Socket
Socket
Sign inDemoInstall

tempfile

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tempfile - npm Package Compare versions

Comparing version 4.0.0 to 5.0.0

25

index.d.ts

@@ -0,6 +1,22 @@

export type Options = {
/**
A file extension to append to the path.
@example
```
import tempfile from 'tempfile';
tempfile();
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'
tempfile({extension: 'png'});
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
```
*/
readonly extension?: string;
};
/**
Get a random temporary file path.
@param extension - Extension to append to the path.
@example

@@ -10,5 +26,2 @@ ```

tempfile('.png');
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
tempfile();

@@ -18,2 +31,2 @@ //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'

*/
export default function tempfile(extension?: string): string;
export default function tempfile(options?: Options): string;
import path from 'node:path';
import {v4 as uuidv4} from 'uuid';
import {randomUUID} from 'node:crypto';
import tempDirectory from 'temp-dir';
export default function tempfile(extension = '') {
return path.join(tempDirectory, uuidv4() + extension);
export default function tempfile(options = {}) {
// TODO: Remove this for v6.
if (typeof options === 'string') {
throw new TypeError('You must now pass in the file extension as an object.');
}
let {extension} = options;
if (typeof extension === 'string') {
extension = extension.startsWith('.') ? extension : `.${extension}`;
}
return path.join(tempDirectory, randomUUID() + (extension ?? ''));
}
{
"name": "tempfile",
"version": "4.0.0",
"version": "5.0.0",
"description": "Get a random temporary file path",

@@ -14,5 +14,8 @@ "license": "MIT",

"type": "module",
"exports": "./index.js",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"engines": {
"node": ">=12.20"
"node": ">=14.18"
},

@@ -36,10 +39,9 @@ "scripts": {

"dependencies": {
"temp-dir": "^2.0.0",
"uuid": "^8.3.2"
"temp-dir": "^3.0.0"
},
"devDependencies": {
"ava": "^3.15.0",
"tsd": "^0.17.0",
"xo": "^0.40.2"
"ava": "^5.2.0",
"tsd": "^0.25.0",
"xo": "^0.53.1"
}
}

@@ -9,5 +9,5 @@ # tempfile

```sh
npm install tempfile
```
$ npm install tempfile
```

@@ -19,5 +19,2 @@ ## Usage

tempfile('.png');
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
tempfile();

@@ -29,10 +26,24 @@ //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'

### tempfile(extension?)
### tempfile(options?)
#### extension
#### options
Type: `object`
##### extension
Type: `string`
Extension to append to the path.
A file extension to append to the path.
```js
import tempfile from 'tempfile';
tempfile();
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3'
tempfile({extension: 'png'});
//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png'
```
## Related

@@ -39,0 +50,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc