tempfile 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/index.d.ts +19 -6
  2. package/index.js +14 -3
  3. package/package.json +10 -8
  4. package/readme.md +19 -8
package/index.d.ts CHANGED
@@ -1,17 +1,30 @@
1
+ export type Options = {
2
+ /**
3
+ A file extension to append to the path.
4
+
5
+ @example
6
+ ```
7
+ import tempfile from 'tempfile';
8
+
9
+ tempfile();
10
+ //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'
11
+
12
+ tempfile({extension: 'png'});
13
+ //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
14
+ ```
15
+ */
16
+ readonly extension?: string;
17
+ };
18
+
1
19
  /**
2
20
  Get a random temporary file path.
3
21
 
4
- @param extension - Extension to append to the path.
5
-
6
22
  @example
7
23
  ```
8
24
  import tempfile from 'tempfile';
9
25
 
10
- tempfile('.png');
11
- //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
12
-
13
26
  tempfile();
14
27
  //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'
15
28
  ```
16
29
  */
17
- export default function tempfile(extension?: string): string;
30
+ export default function tempfile(options?: Options): string;
package/index.js CHANGED
@@ -1,7 +1,18 @@
1
1
  import path from 'node:path';
2
- import {v4 as uuidv4} from 'uuid';
2
+ import {randomUUID} from 'node:crypto';
3
3
  import tempDirectory from 'temp-dir';
4
4
 
5
- export default function tempfile(extension = '') {
6
- return path.join(tempDirectory, uuidv4() + extension);
5
+ export default function tempfile(options = {}) {
6
+ // TODO: Remove this for v6.
7
+ if (typeof options === 'string') {
8
+ throw new TypeError('You must now pass in the file extension as an object.');
9
+ }
10
+
11
+ let {extension} = options;
12
+
13
+ if (typeof extension === 'string') {
14
+ extension = extension.startsWith('.') ? extension : `.${extension}`;
15
+ }
16
+
17
+ return path.join(tempDirectory, randomUUID() + (extension ?? ''));
7
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tempfile",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "Get a random temporary file path",
5
5
  "license": "MIT",
6
6
  "repository": "sindresorhus/tempfile",
@@ -11,9 +11,12 @@
11
11
  "url": "https://sindresorhus.com"
12
12
  },
13
13
  "type": "module",
14
- "exports": "./index.js",
14
+ "exports": {
15
+ "types": "./index.d.ts",
16
+ "default": "./index.js"
17
+ },
15
18
  "engines": {
16
- "node": ">=12.20"
19
+ "node": ">=14.18"
17
20
  },
18
21
  "scripts": {
19
22
  "test": "xo && ava && tsd"
@@ -32,12 +35,11 @@
32
35
  "uuid"
33
36
  ],
34
37
  "dependencies": {
35
- "temp-dir": "^2.0.0",
36
- "uuid": "^8.3.2"
38
+ "temp-dir": "^3.0.0"
37
39
  },
38
40
  "devDependencies": {
39
- "ava": "^3.15.0",
40
- "tsd": "^0.17.0",
41
- "xo": "^0.40.2"
41
+ "ava": "^5.2.0",
42
+ "tsd": "^0.25.0",
43
+ "xo": "^0.53.1"
42
44
  }
43
45
  }
package/readme.md CHANGED
@@ -6,8 +6,8 @@
6
6
 
7
7
  ## Install
8
8
 
9
- ```
10
- $ npm install tempfile
9
+ ```sh
10
+ npm install tempfile
11
11
  ```
12
12
 
13
13
  ## Usage
@@ -15,22 +15,33 @@ $ npm install tempfile
15
15
  ```js
16
16
  import tempfile from 'tempfile';
17
17
 
18
- tempfile('.png');
19
- //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
20
-
21
18
  tempfile();
22
19
  //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'
23
20
  ```
24
21
 
25
22
  ## API
26
23
 
27
- ### tempfile(extension?)
24
+ ### tempfile(options?)
25
+
26
+ #### options
28
27
 
29
- #### extension
28
+ Type: `object`
29
+
30
+ ##### extension
30
31
 
31
32
  Type: `string`
32
33
 
33
- Extension to append to the path.
34
+ A file extension to append to the path.
35
+
36
+ ```js
37
+ import tempfile from 'tempfile';
38
+
39
+ tempfile();
40
+ //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'
41
+
42
+ tempfile({extension: 'png'});
43
+ //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
44
+ ```
34
45
 
35
46
  ## Related
36
47