asljs-tmpdir
v0.1.12
Published
Disposable temporary directory helper for Node.js.
Downloads
1,588
Maintainers
Readme
tmpdir
Part of Alexandrite Software Library – a set of high‑quality, performant JavaScript libraries for everyday use.
Disposable temporary directory helper for Node.js.
Features
- Create a temporary directory with a unique name
- Provides helpers for creating files and subdirectories
- Automatically cleans up the temporary directory when done
- Prevents escaping the temporary directory path
Installation
npm install asljs-tmpdirNPM Package: asljs-tmpdir
Usage
Basic
import { TmpDir }
from 'asljs-tmpdir';
using tmpDir =
new TmpDir();
await tmpDir.writeText(
'example/file.txt',
'Hello, world!');
console.log(
await tmpDir.readText(
'example/file.txt'));
// the temporary directory and its contents
// will be automatically deleted at the end of
// the using blockCustom tracing handler
import { TmpDir,
formatMessage }
from 'asljs-tmpdir';
using tmpDir =
new TmpDir(
{ trace:
(message, ...params) =>
console.log(
formatMessage(
message,
...params)) });
await tmpDir.writeText(
'example/file.txt',
'Hello, world!');Strict error handling
Failing to clean up is not a critical error so the default behavior is to log a warning to the console. Replacing the error handler makes it more strict.
import { TmpDir,
tmpDirThrowErrorFunction }
from 'asljs-tmpdir';
using tmpDir =
new TmpDir(
{ error: tmpDirThrowErrorFunction });License
MIT License. See LICENSE for details.
