pax_global_header00006660000000000000000000000064151353457070014524gustar00rootroot0000000000000052 comment=ac7a2bb839ceb765d8030aa2356d6830590a38ef sindresorhus-tempfile-37c8137/000077500000000000000000000000001513534570700163405ustar00rootroot00000000000000sindresorhus-tempfile-37c8137/.editorconfig000066400000000000000000000002571513534570700210210ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 sindresorhus-tempfile-37c8137/.gitattributes000066400000000000000000000000231513534570700212260ustar00rootroot00000000000000* text=auto eol=lf sindresorhus-tempfile-37c8137/.github/000077500000000000000000000000001513534570700177005ustar00rootroot00000000000000sindresorhus-tempfile-37c8137/.github/security.md000066400000000000000000000002631513534570700220720ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. sindresorhus-tempfile-37c8137/.github/workflows/000077500000000000000000000000001513534570700217355ustar00rootroot00000000000000sindresorhus-tempfile-37c8137/.github/workflows/main.yml000066400000000000000000000006451513534570700234110ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 24 - 20 steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test sindresorhus-tempfile-37c8137/.gitignore000066400000000000000000000000271513534570700203270ustar00rootroot00000000000000node_modules yarn.lock sindresorhus-tempfile-37c8137/.npmrc000066400000000000000000000000231513534570700174530ustar00rootroot00000000000000package-lock=false sindresorhus-tempfile-37c8137/index.d.ts000066400000000000000000000012241513534570700202400ustar00rootroot00000000000000export 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. @example ``` import tempfile from 'tempfile'; tempfile(); //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3' ``` */ export default function tempfile(options?: Options): string; sindresorhus-tempfile-37c8137/index.js000066400000000000000000000007421513534570700200100ustar00rootroot00000000000000import path from 'node:path'; import {randomUUID} from 'node:crypto'; import temporaryDirectory from 'temp-dir'; import {assertSafeFilename} from 'is-safe-filename'; export default function tempfile(options = {}) { let {extension} = options; if (extension !== undefined && extension !== null) { assertSafeFilename(extension); extension = extension.startsWith('.') ? extension : `.${extension}`; } return path.join(temporaryDirectory, randomUUID() + (extension ?? '')); } sindresorhus-tempfile-37c8137/index.test-d.ts000066400000000000000000000002261513534570700212160ustar00rootroot00000000000000import {expectType} from 'tsd'; import tempfile from './index.js'; expectType(tempfile()); expectType(tempfile({extension: 'png'})); sindresorhus-tempfile-37c8137/license000066400000000000000000000021351513534570700177060ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. sindresorhus-tempfile-37c8137/package.json000066400000000000000000000014741513534570700206340ustar00rootroot00000000000000{ "name": "tempfile", "version": "6.0.1", "description": "Get a random temporary file path", "license": "MIT", "repository": "sindresorhus/tempfile", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": { "types": "./index.d.ts", "default": "./index.js" }, "sideEffects": false, "engines": { "node": ">=20" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "temp", "temporary", "tempfile", "file", "path", "random", "uuid" ], "dependencies": { "is-safe-filename": "^0.1.1", "temp-dir": "^3.0.0" }, "devDependencies": { "ava": "^6.4.1", "tsd": "^0.33.0", "xo": "^1.2.3" } } sindresorhus-tempfile-37c8137/readme.md000066400000000000000000000017371513534570700201270ustar00rootroot00000000000000# tempfile > Get a random temporary file path **Checkout out [`tempy`](https://github.com/sindresorhus/tempy) which is a better take on this module.** ## Install ```sh npm install tempfile ``` ## Usage ```js import tempfile from 'tempfile'; tempfile(); //=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3' ``` ## API ### tempfile(options?) #### options Type: `object` ##### extension Type: `string` 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 - [tempy](https://github.com/sindresorhus/tempy) - Get a random temporary file or directory path - [temp-write](https://github.com/sindresorhus/temp-write) - Write string/buffer/stream to a random temp file sindresorhus-tempfile-37c8137/test.js000066400000000000000000000007701513534570700176610ustar00rootroot00000000000000import {tmpdir} from 'node:os'; import test from 'ava'; import {unsafeFilenameFixtures} from 'is-safe-filename'; import tempfile from './index.js'; test('main', t => { t.true(tempfile().includes(tmpdir())); t.true(tempfile({extension: 'png'}).endsWith('.png')); t.true(tempfile({extension: '.png'}).endsWith('.png')); }); test('rejects unsafe extensions', t => { for (const fixture of unsafeFilenameFixtures) { t.throws(() => tempfile({extension: fixture}), {message: /Unsafe filename/}); } });