diff --git a/.editorconfig b/.editorconfig index 98a761d..1c6314a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,6 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[{package.json,*.yml}] +[*.yml] indent_style = space indent_size = 2 diff --git a/.gitattributes b/.gitattributes index 391f0a4..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -* text=auto -*.js text eol=lf +* text=auto eol=lf diff --git a/.gitignore b/.gitignore index 3c3629e..239ecff 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +yarn.lock diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml index b18bae5..f98fed0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ -sudo: false language: node_js node_js: - - '6' - - '4' + - '12' + - '10' + - '8' diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..c516009 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,19 @@ +/** +Get a random temporary file path. + +@param extension - Extension to append to the path. + +@example +``` +import tempfile = require('tempfile'); + +tempfile('.png'); +//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4049f192-43e7-43b2-98d9-094e6760861b.png' + +tempfile(); +//=> '/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/6271e235-13b9-4138-8b9b-ee2f26c09ce3' +``` +*/ +declare function tempfile(extension?: string): string; + +export = tempfile; diff --git a/index.js b/index.js index 5a44ea6..1b5f3bd 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ 'use strict'; const path = require('path'); const uuid = require('uuid'); -const tempDir = require('temp-dir'); +const tempDirectory = require('temp-dir'); -module.exports = ext => path.join(tempDir, uuid.v4() + (ext || '')); +module.exports = (extension = '') => path.join(tempDirectory, uuid.v4() + extension); diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..2810287 --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,5 @@ +import {expectType} from 'tsd'; +import tempfile = require('.'); + +expectType(tempfile()); +expectType(tempfile('.png')); diff --git a/license b/license index 654d0bf..e7af2f7 100644 --- a/license +++ b/license @@ -1,21 +1,9 @@ -The MIT License (MIT) +MIT License Copyright (c) Sindre Sorhus (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: +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 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. +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. diff --git a/package.json b/package.json index e4a4c7c..593733d 100644 --- a/package.json +++ b/package.json @@ -1,40 +1,42 @@ { - "name": "tempfile", - "version": "2.0.0", - "description": "Get a random temporary file path", - "license": "MIT", - "repository": "sindresorhus/tempfile", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=4" - }, - "scripts": { - "test": "xo && ava" - }, - "files": [ - "index.js" - ], - "keywords": [ - "tmp", - "temp", - "temporary", - "tempfile", - "file", - "path", - "random", - "rand", - "uuid" - ], - "dependencies": { - "temp-dir": "^1.0.0", - "uuid": "^3.0.1" - }, - "devDependencies": { - "ava": "*", - "xo": "*" - } + "name": "tempfile", + "version": "2.0.0", + "description": "Get a random temporary file path", + "license": "MIT", + "repository": "sindresorhus/tempfile", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=8" + }, + "scripts": { + "test": "xo && ava && tsd" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "tmp", + "temp", + "temporary", + "tempfile", + "file", + "path", + "random", + "rand", + "uuid" + ], + "dependencies": { + "temp-dir": "^2.0.0", + "uuid": "^3.3.2" + }, + "devDependencies": { + "ava": "^1.4.1", + "tsd": "^0.7.2", + "xo": "^0.24.0" + } } diff --git a/readme.md b/readme.md index 211ba91..7b2dff4 100644 --- a/readme.md +++ b/readme.md @@ -8,7 +8,7 @@ ## Install ``` -$ npm install --save tempfile +$ npm install tempfile ``` diff --git a/test.js b/test.js index 7e1ec6c..e05995c 100644 --- a/test.js +++ b/test.js @@ -1,8 +1,8 @@ import {tmpdir} from 'os'; import test from 'ava'; -import m from '.'; +import tempfile from '.'; -test(t => { - t.true(m().includes(tmpdir())); - t.true(m('.png').endsWith('.png')); +test('main', t => { + t.true(tempfile().includes(tmpdir())); + t.true(tempfile('.png').endsWith('.png')); });