|
1 |
| -/* eslint-disable @typescript-eslint/member-ordering */ |
2 | 1 | import {Buffer} from 'node:buffer';
|
3 | 2 | import {MergeExclusive, TypedArray} from 'type-fest';
|
4 | 3 |
|
@@ -41,132 +40,117 @@ The temporary path created by the function. Can be asynchronous.
|
41 | 40 | */
|
42 | 41 | export type TaskCallback<ReturnValueType> = (temporaryPath: string) => Promise<ReturnValueType> | ReturnValueType;
|
43 | 42 |
|
44 |
| -declare const tempy: { |
45 |
| - file: { |
46 |
| - /** |
47 |
| - The `callback` resolves with a temporary file path you can write to. The file is automatically cleaned up after the callback is executed. |
48 |
| -
|
49 |
| - @returns A promise that resolves after the callback is executed and the file is cleaned up. |
50 |
| -
|
51 |
| - @example |
52 |
| - ``` |
53 |
| - import tempy from 'tempy'; |
54 |
| -
|
55 |
| - await tempy.file.task(tempFile => { |
56 |
| - console.log(tempFile); |
57 |
| - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' |
58 |
| - }); |
59 |
| - ``` |
60 |
| - */ |
61 |
| - task: <ReturnValueType>(callback: TaskCallback<ReturnValueType>, options?: FileOptions) => Promise<ReturnValueType>; |
62 |
| - |
63 |
| - /** |
64 |
| - Get a temporary file path you can write to. |
65 |
| -
|
66 |
| - @example |
67 |
| - ``` |
68 |
| - import tempy from 'tempy'; |
69 |
| -
|
70 |
| - tempy.file(); |
71 |
| - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' |
72 |
| -
|
73 |
| - tempy.file({extension: 'png'}); |
74 |
| - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png' |
75 |
| -
|
76 |
| - tempy.file({name: 'unicorn.png'}); |
77 |
| - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png' |
78 |
| -
|
79 |
| - tempy.directory(); |
80 |
| - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' |
81 |
| - ``` |
82 |
| - */ |
83 |
| - (options?: FileOptions): string; |
84 |
| - }; |
85 |
| - |
86 |
| - directory: { |
87 |
| - /** |
88 |
| - The `callback` resolves with a temporary directory path you can write to. The directory is automatically cleaned up after the callback is executed. |
89 |
| -
|
90 |
| - @returns A promise that resolves after the callback is executed and the directory is cleaned up. |
91 |
| -
|
92 |
| - @example |
93 |
| - ``` |
94 |
| - import tempy from 'tempy'; |
95 |
| -
|
96 |
| - await tempy.directory.task(tempDirectory => { |
97 |
| - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' |
98 |
| - }) |
99 |
| - ``` |
100 |
| - */ |
101 |
| - task: <ReturnValueType>(callback: TaskCallback<ReturnValueType>, options?: DirectoryOptions) => Promise<ReturnValueType>; |
102 |
| - |
103 |
| - /** |
104 |
| - Get a temporary directory path. The directory is created for you. |
105 |
| -
|
106 |
| - @example |
107 |
| - ``` |
108 |
| - import tempy from 'tempy'; |
109 |
| -
|
110 |
| - tempy.directory(); |
111 |
| - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' |
112 |
| -
|
113 |
| - tempy.directory({prefix: 'a'}); |
114 |
| - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/name_3c085674ad31223b9653c88f725d6b41' |
115 |
| - ``` |
116 |
| - */ |
117 |
| - (options?: DirectoryOptions): string; |
118 |
| - }; |
119 |
| - |
120 |
| - write: { |
121 |
| - /** |
122 |
| - Write data to a random temp file. The file is automatically cleaned up after the callback is executed. |
123 |
| -
|
124 |
| - @returns A promise that resolves after the callback is executed and the file is cleaned up. |
125 |
| -
|
126 |
| - @example |
127 |
| - ``` |
128 |
| - import tempy from 'tempy'; |
129 |
| -
|
130 |
| - await tempy.write.task('🦄', tempFile => { |
131 |
| - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' |
132 |
| - }); |
133 |
| - ``` |
134 |
| - */ |
135 |
| - task: <ReturnValueType>(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, callback: TaskCallback<ReturnValueType>, options?: FileOptions) => Promise<ReturnValueType>; |
136 |
| - |
137 |
| - /** |
138 |
| - Write data to a random temp file. |
139 |
| -
|
140 |
| - @example |
141 |
| - ``` |
142 |
| - import tempy from 'tempy'; |
143 |
| -
|
144 |
| - await tempy.write('🦄'); |
145 |
| - //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' |
146 |
| - ``` |
147 |
| - */ |
148 |
| - (fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, options?: FileOptions): Promise<string>; |
149 |
| - }; |
| 43 | +/** |
| 44 | +Get a temporary file path you can write to. |
150 | 45 |
|
151 |
| - /** |
152 |
| - Synchronously write data to a random temp file. |
| 46 | +@example |
| 47 | +``` |
| 48 | +import {temporaryFile, temporaryDirectory} from 'tempy'; |
| 49 | +
|
| 50 | +temporaryFile(); |
| 51 | +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' |
| 52 | +
|
| 53 | +temporaryFile({extension: 'png'}); |
| 54 | +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png' |
| 55 | +
|
| 56 | +temporaryFile({name: 'unicorn.png'}); |
| 57 | +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png' |
| 58 | +
|
| 59 | +temporaryDirectory(); |
| 60 | +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' |
| 61 | +``` |
| 62 | +*/ |
| 63 | +export function temporaryFile(options?: FileOptions): string; |
| 64 | + |
| 65 | +/** |
| 66 | +The `callback` resolves with a temporary file path you can write to. The file is automatically cleaned up after the callback is executed. |
| 67 | +
|
| 68 | +@returns A promise that resolves after the callback is executed and the file is cleaned up. |
| 69 | +
|
| 70 | +@example |
| 71 | +``` |
| 72 | +import {temporaryFileTask} from 'tempy'; |
| 73 | +
|
| 74 | +await temporaryFileTask(tempFile => { |
| 75 | + console.log(tempFile); |
| 76 | + //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' |
| 77 | +}); |
| 78 | +``` |
| 79 | +*/ |
| 80 | +export function temporaryFileTask<ReturnValueType>(callback: TaskCallback<ReturnValueType>, options?: FileOptions): Promise <ReturnValueType>; |
| 81 | + |
| 82 | +/** |
| 83 | +Get a temporary directory path. The directory is created for you. |
| 84 | +
|
| 85 | +@example |
| 86 | +``` |
| 87 | +import {temporaryDirectory} from 'tempy'; |
| 88 | +
|
| 89 | +temporaryDirectory(); |
| 90 | +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' |
| 91 | +
|
| 92 | +temporaryDirectory({prefix: 'a'}); |
| 93 | +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/name_3c085674ad31223b9653c88f725d6b41' |
| 94 | +``` |
| 95 | +*/ |
| 96 | +export function temporaryDirectory(options?: DirectoryOptions): string; |
| 97 | + |
| 98 | +/** |
| 99 | +The `callback` resolves with a temporary directory path you can write to. The directory is automatically cleaned up after the callback is executed. |
153 | 100 |
|
154 |
| - @example |
155 |
| - ``` |
156 |
| - import tempy from 'tempy'; |
| 101 | +@returns A promise that resolves after the callback is executed and the directory is cleaned up. |
157 | 102 |
|
158 |
| - tempy.writeSync('🦄'); |
| 103 | +@example |
| 104 | +``` |
| 105 | +import {temporaryDirectoryTask} from 'tempy'; |
| 106 | +
|
| 107 | +await temporaryDirectoryTask(tempDirectory => { |
159 | 108 | //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
|
160 |
| - ``` |
161 |
| - */ |
162 |
| - writeSync: (fileContent: string | Buffer | TypedArray | DataView, options?: FileOptions) => string; |
| 109 | +}) |
| 110 | +``` |
| 111 | +*/ |
| 112 | +export function temporaryDirectoryTask<ReturnValueType>(callback: TaskCallback<ReturnValueType>, options?: DirectoryOptions): Promise<ReturnValueType>; |
163 | 113 |
|
164 |
| - /** |
165 |
| - Get the root temporary directory path. |
| 114 | +/** |
| 115 | +Write data to a random temp file. |
166 | 116 |
|
167 |
| - For example: `/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T`. |
168 |
| - */ |
169 |
| - readonly root: string; |
170 |
| -}; |
| 117 | +@example |
| 118 | +``` |
| 119 | +import {temporaryWrite} from 'tempy'; |
| 120 | +
|
| 121 | +await temporaryWrite('🦄'); |
| 122 | +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' |
| 123 | +``` |
| 124 | +*/ |
| 125 | +export function temporaryWrite(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, options?: FileOptions): Promise<string>; |
| 126 | + |
| 127 | +/** |
| 128 | +Write data to a random temp file. The file is automatically cleaned up after the callback is executed. |
| 129 | +
|
| 130 | +@returns A promise that resolves after the callback is executed and the file is cleaned up. |
| 131 | +
|
| 132 | +@example |
| 133 | +``` |
| 134 | +import {temporaryWriteTask} from 'tempy'; |
| 135 | +
|
| 136 | +await temporaryWriteTask('🦄', tempFile => { |
| 137 | + //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' |
| 138 | +}); |
| 139 | +``` |
| 140 | +*/ |
| 141 | +export function temporaryWriteTask<ReturnValueType>(fileContent: string | Buffer | TypedArray | DataView | NodeJS.ReadableStream, callback: TaskCallback<ReturnValueType>, options?: FileOptions): Promise<ReturnValueType>; |
| 142 | + |
| 143 | +/** |
| 144 | +Synchronously write data to a random temp file. |
| 145 | +
|
| 146 | +@example |
| 147 | +``` |
| 148 | +import {temporaryWriteSync} from 'tempy'; |
| 149 | +
|
| 150 | +temporaryWriteSync('🦄'); |
| 151 | +//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' |
| 152 | +``` |
| 153 | +*/ |
| 154 | +export function temporaryWriteSync(fileContent: string | Buffer | TypedArray | DataView, options?: FileOptions): string; |
171 | 155 |
|
172 |
| -export default tempy; |
| 156 | +export {default as rootTemporaryDirectory} from 'temp-dir'; |
0 commit comments