Overview
About 2 min
Api Documentation v1.0.2
tmp
Create temporary directories and files. Can automatically clean up on process exit.
Installation
To install the package, use npm or yarn:
npm install @radicjs/tmpor
yarn add @radicjs/tmpUsage
| Function | Description | 
|---|---|
| tmpDir | Create a temporary directory asynchronously | 
| tmpDirSync | Create a temporary directory synchronously | 
| tmpFile | Create a temporary file asynchronously | 
| tmpFileSync | Create a temporary file synchronously | 
| tmpPath | Retrieve the temporary directory path asynchronously | 
| tmpPathSync | Retrieve the temporary directory path synchronously | 
Declarations
const tmpDir = (options?:TmpDirOptions) => Promise<TmpDirHelper>
const tmpDirSync = (options?:TmpDirOptions) => TmpDirSyncHelper
const tmpFile = (options?:TmpFileOptions) => Promise<TmpFileHelper>
const tmpFileSync = (options?:TmpFileOptions) => TmpFileSyncHelper
const tmpPath = () => Promise<string>
const tmpPathSync = () => string
export interface TmpFileOptions {
    /** use a custom diectory for the temporary file */
    path?: string;
    /** use a custom prefix for the temporary file */
    prefix?: string;
    /**
     * The file mode (permission and sticky bits) to be applied.
     * @default 0o666
     */
    mode?: import('fs').Mode;
}
export interface TmpDirOptions {
    /** use a custom diectory for the temporary directory */
    path?: string;
    /** use a custom prefix for the temporary directory */
    prefix?: string;
}
export interface TmpFileHelper {
    /** the path to the temporary file */
    path: string;
    /** clean up the temporary file */
    clean(): Promise<void>;
    /** check if the temporary file has been cleaned */
    cleaned(): boolean;
    /** track the temporary file for automatic cleanup on process exit */
    track(): void;
    /** check if the temporary file is tracked */
    tracked(): boolean;
    /** untrack the temporary file */
    untrack(): void;
}
export interface TmpDirHelper {
    /** the path to the temporary directory */
    root: string;
    /** create a absolute path relative to the temporary directory */
    path(...args: string[]): string;
    /** check if a path exists in the temporary directory */
    clean(): Promise<void>;
    /** check if a path exists in the temporary directory */
    cleaned(): boolean;
    /** track the temporary directory for automatic cleanup on process exit */
    track(): void;
    /** check if the temporary directory is tracked */
    tracked(): boolean;
    /** untrack the temporary directory */
    untrack(): void;
}Examples
tba
Coverage
| St | File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | 
|---|---|---|---|---|---|---|
| 🟡 | All files | 67.76 | 55.88 | 52.27 | 67.54 | |
| 🔴 | cleanup.ts | 48.64 | 62.5 | 25 | 48.64 | 16-44,78-85 | 
| 🟡 | dir.ts | 67.27 | 50 | 47.05 | 67.27 | 44-48,91,94,102,105-106,112-113,165,168,176,179-180,186-187 | 
| 🟡 | file.ts | 75.51 | 50 | 60 | 75 | 81,89,92-93,99-100,151,159,162-163,169-170 | 
| 🟢 | util.ts | 100 | 100 | 100 | 100 | 
License
This project is licensed under the MIT License.