tempfile 3.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.
package/index.d.ts CHANGED
@@ -1,19 +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
- import tempfile = require('tempfile');
9
-
10
- tempfile('.png');
11
- //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
24
+ import tempfile from 'tempfile';
12
25
 
13
26
  tempfile();
14
27
  //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'
15
28
  ```
16
29
  */
17
- declare function tempfile(extension?: string): string;
18
-
19
- export = tempfile;
30
+ export default function tempfile(options?: Options): string;
package/index.js CHANGED
@@ -1,6 +1,18 @@
1
- 'use strict';
2
- const path = require('path');
3
- const uuid = require('uuid');
4
- const tempDirectory = require('temp-dir');
1
+ import path from 'node:path';
2
+ import {randomUUID} from 'node:crypto';
3
+ import tempDirectory from 'temp-dir';
5
4
 
6
- module.exports = (extension = '') => path.join(tempDirectory, uuid.v4() + 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 ?? ''));
18
+ }
package/license CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
package/package.json CHANGED
@@ -1,16 +1,22 @@
1
1
  {
2
2
  "name": "tempfile",
3
- "version": "3.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",
7
+ "funding": "https://github.com/sponsors/sindresorhus",
7
8
  "author": {
8
9
  "name": "Sindre Sorhus",
9
10
  "email": "sindresorhus@gmail.com",
10
- "url": "sindresorhus.com"
11
+ "url": "https://sindresorhus.com"
12
+ },
13
+ "type": "module",
14
+ "exports": {
15
+ "types": "./index.d.ts",
16
+ "default": "./index.js"
11
17
  },
12
18
  "engines": {
13
- "node": ">=8"
19
+ "node": ">=14.18"
14
20
  },
15
21
  "scripts": {
16
22
  "test": "xo && ava && tsd"
@@ -29,12 +35,11 @@
29
35
  "uuid"
30
36
  ],
31
37
  "dependencies": {
32
- "temp-dir": "^2.0.0",
33
- "uuid": "^3.3.2"
38
+ "temp-dir": "^3.0.0"
34
39
  },
35
40
  "devDependencies": {
36
- "ava": "^1.4.1",
37
- "tsd": "^0.7.2",
38
- "xo": "^0.24.0"
41
+ "ava": "^5.2.0",
42
+ "tsd": "^0.25.0",
43
+ "xo": "^0.53.1"
39
44
  }
40
45
  }
package/readme.md CHANGED
@@ -1,47 +1,49 @@
1
- # tempfile [![Build Status](https://travis-ci.org/sindresorhus/tempfile.svg?branch=master)](https://travis-ci.org/sindresorhus/tempfile)
1
+ # tempfile
2
2
 
3
3
  > Get a random temporary file path
4
4
 
5
5
  **Checkout out [`tempy`](https://github.com/sindresorhus/tempy) which is a better take on this module.**
6
6
 
7
-
8
7
  ## Install
9
8
 
9
+ ```sh
10
+ npm install tempfile
10
11
  ```
11
- $ npm install tempfile
12
- ```
13
-
14
12
 
15
13
  ## Usage
16
14
 
17
15
  ```js
18
- const tempfile = require('tempfile');
19
-
20
- tempfile('.png');
21
- //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
16
+ import tempfile from 'tempfile';
22
17
 
23
18
  tempfile();
24
19
  //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'
25
20
  ```
26
21
 
27
-
28
22
  ## API
29
23
 
30
- ### tempfile([extension])
24
+ ### tempfile(options?)
25
+
26
+ #### options
31
27
 
32
- #### extension
28
+ Type: `object`
29
+
30
+ ##### extension
33
31
 
34
32
  Type: `string`
35
33
 
36
- Extension to append to the path.
34
+ A file extension to append to the path.
35
+
36
+ ```js
37
+ import tempfile from 'tempfile';
37
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
+ ```
38
45
 
39
46
  ## Related
40
47
 
41
48
  - [tempy](https://github.com/sindresorhus/tempy) - Get a random temporary file or directory path
42
49
  - [temp-write](https://github.com/sindresorhus/temp-write) - Write string/buffer/stream to a random temp file
43
-
44
-
45
- ## License
46
-
47
- MIT © [Sindre Sorhus](https://sindresorhus.com)