| 1 | /// <reference types="node"/>
|
|---|
| 2 | import {MergeExclusive, TypedArray} from 'type-fest';
|
|---|
| 3 |
|
|---|
| 4 | declare namespace tempy {
|
|---|
| 5 | type FileOptions = MergeExclusive<
|
|---|
| 6 | {
|
|---|
| 7 | /**
|
|---|
| 8 | File extension.
|
|---|
| 9 |
|
|---|
| 10 | Mutually exclusive with the `name` option.
|
|---|
| 11 |
|
|---|
| 12 | _You usually won't need this option. Specify it only when actually needed._
|
|---|
| 13 | */
|
|---|
| 14 | readonly extension?: string;
|
|---|
| 15 | },
|
|---|
| 16 | {
|
|---|
| 17 | /**
|
|---|
| 18 | Filename.
|
|---|
| 19 |
|
|---|
| 20 | Mutually exclusive with the `extension` option.
|
|---|
| 21 |
|
|---|
| 22 | _You usually won't need this option. Specify it only when actually needed._
|
|---|
| 23 | */
|
|---|
| 24 | readonly name?: string;
|
|---|
| 25 | }
|
|---|
| 26 | >;
|
|---|
| 27 |
|
|---|
| 28 | type DirectoryOptions = {
|
|---|
| 29 | /**
|
|---|
| 30 | _You usually won't need this option. Specify it only when actually needed._
|
|---|
| 31 |
|
|---|
| 32 | Directory prefix.
|
|---|
| 33 |
|
|---|
| 34 | Useful for testing by making it easier to identify cache directories that are created.
|
|---|
| 35 | */
|
|---|
| 36 | readonly prefix?: string;
|
|---|
| 37 | };
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | declare const tempy: {
|
|---|
| 41 | /**
|
|---|
| 42 | Get a temporary file path you can write to.
|
|---|
| 43 |
|
|---|
| 44 | @example
|
|---|
| 45 | ```
|
|---|
| 46 | import tempy = require('tempy');
|
|---|
| 47 |
|
|---|
| 48 | tempy.file();
|
|---|
| 49 | //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
|
|---|
| 50 |
|
|---|
| 51 | tempy.file({extension: 'png'});
|
|---|
| 52 | //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png'
|
|---|
| 53 |
|
|---|
| 54 | tempy.file({name: 'unicorn.png'});
|
|---|
| 55 | //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png'
|
|---|
| 56 |
|
|---|
| 57 | tempy.directory();
|
|---|
| 58 | //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
|
|---|
| 59 | ```
|
|---|
| 60 | */
|
|---|
| 61 | file: (options?: tempy.FileOptions) => string;
|
|---|
| 62 |
|
|---|
| 63 | /**
|
|---|
| 64 | Get a temporary directory path. The directory is created for you.
|
|---|
| 65 |
|
|---|
| 66 | @example
|
|---|
| 67 | ```
|
|---|
| 68 | import tempy = require('tempy');
|
|---|
| 69 |
|
|---|
| 70 | tempy.directory();
|
|---|
| 71 | //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
|
|---|
| 72 |
|
|---|
| 73 | tempy.directory({prefix: 'a'});
|
|---|
| 74 | //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/name_3c085674ad31223b9653c88f725d6b41'
|
|---|
| 75 | ```
|
|---|
| 76 | */
|
|---|
| 77 | directory: (options?: tempy.DirectoryOptions) => string;
|
|---|
| 78 |
|
|---|
| 79 | /**
|
|---|
| 80 | Write data to a random temp file.
|
|---|
| 81 |
|
|---|
| 82 | @example
|
|---|
| 83 | ```
|
|---|
| 84 | import tempy = require('tempy');
|
|---|
| 85 |
|
|---|
| 86 | await tempy.write('🦄');
|
|---|
| 87 | //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
|
|---|
| 88 | ```
|
|---|
| 89 | */
|
|---|
| 90 | write: (fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, options?: tempy.FileOptions) => Promise<string>;
|
|---|
| 91 |
|
|---|
| 92 | /**
|
|---|
| 93 | Synchronously write data to a random temp file.
|
|---|
| 94 |
|
|---|
| 95 | @example
|
|---|
| 96 | ```
|
|---|
| 97 | import tempy = require('tempy');
|
|---|
| 98 |
|
|---|
| 99 | tempy.writeSync('🦄');
|
|---|
| 100 | //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
|
|---|
| 101 | ```
|
|---|
| 102 | */
|
|---|
| 103 | writeSync: (fileContent: string | Buffer | TypedArray | DataView, options?: tempy.FileOptions) => string;
|
|---|
| 104 |
|
|---|
| 105 | /**
|
|---|
| 106 | Get the root temporary directory path.
|
|---|
| 107 |
|
|---|
| 108 | For example: `/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T`.
|
|---|
| 109 | */
|
|---|
| 110 | readonly root: string;
|
|---|
| 111 | };
|
|---|
| 112 |
|
|---|
| 113 | export = tempy;
|
|---|