npm package: @radicjs/tmp
Description: Get temporary file path, Create temporary files or directories. Can automatically clean up on process exit.
Author: Robin Radic
Latest version: 1.0.2

# tmp

[![npm version](https://badge.fury.io/js/%40radicjs%2Ftmp.svg)](https://badge.fury.io/js/%40radicjs%2Ftmp)

Create temporary directories and files. Can automatically clean up on process exit.

### Installation

To install the package, use npm or yarn:

```sh
npm install @radicjs/tmp
```

or

```sh
yarn add @radicjs/tmp
```

### Usage

| 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**
```ts
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
<!-- coverage:start -->
St|File        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                                           
--|------------|---------|----------|---------|---------|-------------------------------------------------------------
🟡|All files   |   67.76 |    55.88 |   52.27 |   67.54 |                                                             
🔴|&nbsp;[cleanup.ts](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/cleanup.ts)|   48.64 |     62.5 |      25 |   48.64 |[16-44](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/cleanup.ts#L16-L44),[78-85](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/cleanup.ts#L78-L85)
🟡|&nbsp;[dir.ts](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/dir.ts)|   67.27 |       50 |   47.05 |   67.27 |[44-48](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/dir.ts#L44-L48),[91](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/dir.ts#L91),[94](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/dir.ts#L94),[102](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/dir.ts#L102),[105-106](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/dir.ts#L105-L106),[112-113](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/dir.ts#L112-L113),[165](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/dir.ts#L165),[168](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/dir.ts#L168),[176](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/dir.ts#L176),[179-180](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/dir.ts#L179-L180),[186-187](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/dir.ts#L186-L187)
🟡|&nbsp;[file.ts](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/file.ts)|   75.51 |       50 |      60 |      75 |[81](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/file.ts#L81),[89](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/file.ts#L89),[92-93](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/file.ts#L92-L93),[99-100](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/file.ts#L99-L100),[151](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/file.ts#L151),[159](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/file.ts#L159),[162-163](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/file.ts#L162-L163),[169-170](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/file.ts#L169-L170)
🟢|&nbsp;[util.ts](https://github.com/RobinRadic/radicjs/tree/master/packages/utils/src/util.ts)|     100 |      100 |     100 |     100 |
<!-- coverage:end -->


## License

This project is licensed under the MIT License.