Comparing version 0.1.0 to 0.2.0
16
index.js
@@ -5,7 +5,4 @@ 'use strict'; | ||
const uniqueString = require('unique-string'); | ||
const pify = require('pify'); | ||
const tempDir = require('temp-dir'); | ||
const mkdir = pify(fs.mkdir); | ||
const getPath = () => path.join(tempDir, uniqueString()); | ||
@@ -18,2 +15,10 @@ | ||
if (opts.name) { | ||
if (opts.extension) { | ||
throw new Error('The `name` and `extension` options are mutually exclusive'); | ||
} | ||
return path.join(module.exports.directory(), opts.name); | ||
} | ||
return getPath() + (opts.extension ? `.${opts.extension.replace(/^\./, '')}` : ''); | ||
@@ -28,7 +33,2 @@ }; | ||
module.exports.directoryAsync = () => { | ||
const dir = getPath(); | ||
return mkdir(dir).then(() => dir); | ||
}; | ||
module.exports.root = tempDir; |
{ | ||
"name": "tempy", | ||
"version": "0.1.0", | ||
"description": "Get a random temporary file or directory path", | ||
"license": "MIT", | ||
"repository": "sindresorhus/tempy", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"temp", | ||
"tmp", | ||
"temporary", | ||
"path", | ||
"file", | ||
"directory", | ||
"dir", | ||
"folder", | ||
"tempfile", | ||
"tempdir", | ||
"tmpdir", | ||
"tmpfile", | ||
"random", | ||
"rand", | ||
"unique", | ||
"uniq" | ||
], | ||
"dependencies": { | ||
"pify": "^2.3.0", | ||
"temp-dir": "^1.0.0", | ||
"unique-string": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
"name": "tempy", | ||
"version": "0.2.0", | ||
"description": "Get a random temporary file or directory path", | ||
"license": "MIT", | ||
"repository": "sindresorhus/tempy", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"temp", | ||
"tmp", | ||
"temporary", | ||
"path", | ||
"file", | ||
"directory", | ||
"dir", | ||
"folder", | ||
"tempfile", | ||
"tempdir", | ||
"tmpdir", | ||
"tmpfile", | ||
"random", | ||
"rand", | ||
"unique", | ||
"uniq" | ||
], | ||
"dependencies": { | ||
"temp-dir": "^1.0.0", | ||
"unique-string": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
} |
@@ -9,3 +9,3 @@ # tempy [](https://travis-ci.org/sindresorhus/tempy) | ||
``` | ||
$ npm install --save tempy | ||
$ npm install tempy | ||
``` | ||
@@ -19,5 +19,11 @@ | ||
tempy.file(); | ||
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd' | ||
tempy.file({extension: 'png'}); | ||
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd.png' | ||
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png' | ||
tempy.file({name: 'unicorn.png'}); | ||
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png' | ||
tempy.directory(); | ||
@@ -38,2 +44,4 @@ //=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6' | ||
*You usually won't need either the `extension` or `name` option. Specify them only when actually needed.* | ||
##### extension | ||
@@ -45,11 +53,11 @@ | ||
### tempy.directory() | ||
##### name | ||
Get a temporary directory path. The directory is created for you. | ||
Type: `string` | ||
### tempy.directoryAsync() | ||
Filename. Mutually exclusive with the `extension` option. | ||
Get a `Promise` for a temporary directory path. | ||
### tempy.directory() | ||
**You most likely don't need this.** This is only useful if you use it in a highly concurrent server where even the tiniest blocking operation is a problem. For everything else, use `tempy.directory()`, which will be faster in most cases. | ||
Get a temporary directory path. The directory is created for you. | ||
@@ -56,0 +64,0 @@ ### tempy.root |
Sorry, the diff of this file is not supported yet
4214
2
80
- Removedpify@^2.3.0
- Removedpify@2.3.0(transitive)