@m59/use-tmp-dir

3.0.0 • Public • Published

@m59/use-tmp-dir

Takes a function and calls it with a path to a temporary directory. The temporary directory is removed after the function completes, or if the process exits meanwhile.

import { use_tmp_dir } from '@m59/use-tmp-dir'
import { access, writeFile } from 'node:fs/promises'
import { join as join_path } from 'node:path'

const removed_tmp_dir = await use_tmp_dir(
	async tmp_dir => {
		await writeFile(join_path(tmp_dir, 'some-file.txt'), 'some contents')
		return tmp_dir
	}
)

const error = await access(removed_tmp_dir)
	.catch(error => error)
error.code // => 'ENOENT'

Dependencies (1)

Dev Dependencies (2)

Package Sidebar

Install

npm i @m59/use-tmp-dir

Weekly Downloads

1

Version

3.0.0

License

ISC

Unpacked Size

5.11 kB

Total Files

6

Last publish

Collaborators

  • m59