diff options
author | Rebecca Turner <me@re-becca.org> | 2015-05-08 02:13:25 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2015-06-26 03:26:57 +0300 |
commit | f3204a76579b0c441607fef71cbb2a4e3f2e9142 (patch) | |
tree | fa83973dac399938de866e90c48dcd291bc4d112 /node_modules/unique-filename | |
parent | 2ec4fef126ce0c7a6c01aa99a2644966a4dc0c27 (diff) |
unique-filename@1.0.0
Diffstat (limited to 'node_modules/unique-filename')
10 files changed, 193 insertions, 0 deletions
diff --git a/node_modules/unique-filename/.npmignore b/node_modules/unique-filename/.npmignore new file mode 100644 index 000000000..1ab9fa63f --- /dev/null +++ b/node_modules/unique-filename/.npmignore @@ -0,0 +1,5 @@ +*~ +.#* +DEADJOE + +node_modules diff --git a/node_modules/unique-filename/README.md b/node_modules/unique-filename/README.md new file mode 100644 index 000000000..4b5b241eb --- /dev/null +++ b/node_modules/unique-filename/README.md @@ -0,0 +1,33 @@ +unique-filename +=============== + +Generate a unique filename for use in temporary directories or caches. + +``` +var uniqueFilename = require('unique-filename') + +// returns something like: /tmp/912ec803b2ce49e4a541068d495ab570 +var randomTmpfile = uniqueFilename(os.tmpdir()) + +// returns something like: /tmp/my-test-912ec803b2ce49e4a541068d495ab570 +var randomPrefixedTmpfile = uniqueFilename(os.tmpdir(), 'my-test') + +var uniqueTmpfile = uniqueFilename('/tmp', 'testing', '/my/thing/to/uniq/on') +``` + +### uniqueFilename(*dir*, *fileprefix*, *uniqstr*) → String + +Returns the full path of a unique filename that looks like: +`dir/prefix-912ec803b2ce49e4a541068d495ab570` +or `dir/912ec803b2ce49e4a541068d495ab570` + +*dir* – The path you want the filename in. `os.tmpdir()` is a good choice for this. + +*fileprefix* – A string to append prior to the unique part of the filename. +The parameter is required if *uniqstr* is also passed in but is otherwise +optional and can be `undefined`/`null`/`''`. If present and not empty +then this string plus a hyphen are prepended to the unique part. + +*uniqstr* – Optional, if not passed the unique part of the resulting +filename will be random. If passed in it will be generated from this string +in a reproducable way. diff --git a/node_modules/unique-filename/index.js b/node_modules/unique-filename/index.js new file mode 100644 index 000000000..02bf1e273 --- /dev/null +++ b/node_modules/unique-filename/index.js @@ -0,0 +1,8 @@ +'use strict' +var path = require('path') + +var uniqueSlug = require('unique-slug') + +module.exports = function (filepath, prefix, uniq) { + return path.join(filepath, (prefix ? prefix + '-' : '') + uniqueSlug(uniq)) +} diff --git a/node_modules/unique-filename/node_modules/unique-slug/.npmignore b/node_modules/unique-filename/node_modules/unique-slug/.npmignore new file mode 100644 index 000000000..1ab9fa63f --- /dev/null +++ b/node_modules/unique-filename/node_modules/unique-slug/.npmignore @@ -0,0 +1,5 @@ +*~ +.#* +DEADJOE + +node_modules diff --git a/node_modules/unique-filename/node_modules/unique-slug/README.md b/node_modules/unique-filename/node_modules/unique-slug/README.md new file mode 100644 index 000000000..978f69b72 --- /dev/null +++ b/node_modules/unique-filename/node_modules/unique-slug/README.md @@ -0,0 +1,20 @@ +unique-slug +=========== + +Generate a unique character string suitible for use in files and URLs. + +``` +var uniqueSlug = require('unique-slug') + +var randomSlug = uniqueSlug() +var fileSlug = uniqueSlug('/etc/passwd') +``` + +### uniqueSlug(*str*) → String (32 chars) + +If *str* is passed in then the return value will be its md5 digest in +hex. + +If *str* is not passed in, it will be 16 bytes coverted into 32 hex +characters, generated by `crypto.pseudoRandomBytes`. + diff --git a/node_modules/unique-filename/node_modules/unique-slug/index.js b/node_modules/unique-filename/node_modules/unique-slug/index.js new file mode 100644 index 000000000..747cf6d06 --- /dev/null +++ b/node_modules/unique-filename/node_modules/unique-slug/index.js @@ -0,0 +1,15 @@ +'use strict' +var crypto = require('crypto') + +module.exports = function (uniq) { + if (uniq) { + var hash = crypto.createHash('md5') + hash.update(uniq) + return hash.digest('hex') + } else { + // Safe because w/o a callback because this interface can + // neither block nor error (by contrast with randomBytes + // which will throw an exception without enough entropy) + return crypto.pseudoRandomBytes(16).toString('hex') + } +} diff --git a/node_modules/unique-filename/node_modules/unique-slug/package.json b/node_modules/unique-filename/node_modules/unique-slug/package.json new file mode 100644 index 000000000..d4d76fcdb --- /dev/null +++ b/node_modules/unique-filename/node_modules/unique-slug/package.json @@ -0,0 +1,34 @@ +{ + "name": "unique-slug", + "version": "1.0.0", + "description": "Generate a unique character string suitible for use in files and URLs.", + "main": "index.js", + "scripts": { + "test": "standard && tap test" + }, + "keywords": [], + "author": { + "name": "Rebecca Turner", + "email": "me@re-becca.org", + "url": "http://re-becca.org" + }, + "license": "ISC", + "devDependencies": { + "standard": "^3.7.3", + "tap": "^1.0.0" + }, + "repository": { + "type": "git", + "url": "git://github.com/iarna/unique-slug.git" + }, + "readme": "unique-slug\n===========\n\nGenerate a unique character string suitible for use in files and URLs.\n\n```\nvar uniqueSlug = require('unique-slug')\n\nvar randomSlug = uniqueSlug()\nvar fileSlug = uniqueSlug('/etc/passwd')\n```\n\n### uniqueSlug(*str*) → String (32 chars)\n\nIf *str* is passed in then the return value will be its md5 digest in\nhex.\n\nIf *str* is not passed in, it will be 16 bytes coverted into 32 hex\ncharacters, generated by `crypto.pseudoRandomBytes`.\n\n", + "readmeFilename": "README.md", + "gitHead": "024b3bd3c0184550702c93f088822e3f38da5c17", + "bugs": { + "url": "https://github.com/iarna/unique-slug/issues" + }, + "homepage": "https://github.com/iarna/unique-slug", + "_id": "unique-slug@1.0.0", + "_shasum": "4459d12416f576cc091a3deb19939ec99c735626", + "_from": "unique-slug@>=1.0.0 <2.0.0" +} diff --git a/node_modules/unique-filename/node_modules/unique-slug/test/index.js b/node_modules/unique-filename/node_modules/unique-slug/test/index.js new file mode 100644 index 000000000..6866678ed --- /dev/null +++ b/node_modules/unique-filename/node_modules/unique-slug/test/index.js @@ -0,0 +1,13 @@ +'use strict' +var t = require('tap') +var uniqueSlug = require('../index.js') + +t.plan(5) +var slugA = uniqueSlug() +t.is(slugA.length, 32, 'random slugs are 32 chars') +t.notEqual(slugA, uniqueSlug(), "two slugs aren't the same") +var base = '/path/to/thingy' +var slugB = uniqueSlug(base) +t.is(slugB.length, 32, 'string based slugs are 32 chars') +t.is(slugB, uniqueSlug(base), 'two string based slugs, from the same string are the same') +t.notEqual(slugB, uniqueSlug(slugA), 'two string based slongs, from diff strings are different') diff --git a/node_modules/unique-filename/package.json b/node_modules/unique-filename/package.json new file mode 100644 index 000000000..b44501226 --- /dev/null +++ b/node_modules/unique-filename/package.json @@ -0,0 +1,37 @@ +{ + "name": "unique-filename", + "version": "1.0.0", + "description": "Generate a unique filename for use in temporary directories or caches.", + "main": "index.js", + "scripts": { + "test": "standard && tap test" + }, + "repository": { + "type": "git", + "url": "https://github.com/iarna/unique-filename.git" + }, + "keywords": [], + "author": { + "name": "Rebecca Turner", + "email": "me@re-becca.org", + "url": "http://re-becca.org/" + }, + "license": "ISC", + "bugs": { + "url": "https://github.com/iarna/unique-filename/issues" + }, + "homepage": "https://github.com/iarna/unique-filename", + "devDependencies": { + "standard": "^3.7.3", + "tap": "^1.0.0" + }, + "dependencies": { + "unique-slug": "^1.0.0" + }, + "readme": "unique-filename\n===============\n\nGenerate a unique filename for use in temporary directories or caches.\n\n```\nvar uniqueFilename = require('unique-filename')\n\n// returns something like: /tmp/912ec803b2ce49e4a541068d495ab570\nvar randomTmpfile = uniqueFilename(os.tmpdir())\n\n// returns something like: /tmp/my-test-912ec803b2ce49e4a541068d495ab570\nvar randomPrefixedTmpfile = uniqueFilename(os.tmpdir(), 'my-test')\n\nvar uniqueTmpfile = uniqueFilename('/tmp', 'testing', '/my/thing/to/uniq/on')\n```\n\n### uniqueFilename(*dir*, *fileprefix*, *uniqstr*) → String\n\nReturns the full path of a unique filename that looks like:\n`dir/prefix-912ec803b2ce49e4a541068d495ab570`\nor `dir/912ec803b2ce49e4a541068d495ab570`\n\n*dir* – The path you want the filename in. `os.tmpdir()` is a good choice for this.\n\n*fileprefix* – A string to append prior to the unique part of the filename.\nThe parameter is required if *uniqstr* is also passed in but is otherwise\noptional and can be `undefined`/`null`/`''`. If present and not empty\nthen this string plus a hyphen are prepended to the unique part.\n\n*uniqstr* – Optional, if not passed the unique part of the resulting\nfilename will be random. If passed in it will be generated from this string\nin a reproducable way.\n", + "readmeFilename": "README.md", + "gitHead": "935739361f6ecc7b613c5daf66a57b67938796d4", + "_id": "unique-filename@1.0.0", + "_shasum": "0bee4219e192e86da3c4ffc0cc6e054d8634eab9", + "_from": "unique-filename@*" +} diff --git a/node_modules/unique-filename/test/index.js b/node_modules/unique-filename/test/index.js new file mode 100644 index 000000000..b1a8fee5e --- /dev/null +++ b/node_modules/unique-filename/test/index.js @@ -0,0 +1,23 @@ +'sue strict' +var t = require('tap') +var uniqueFilename = require('../index.js') + +t.plan(6) + +var randomTmpfile = uniqueFilename('tmp') +t.like(randomTmpfile, /^tmp.[a-f0-9]{32}$/, 'random tmp file') + +var randomAgain = uniqueFilename('tmp') +t.notEqual(randomAgain, randomTmpfile, 'random tmp files are not the same') + +var randomPrefixedTmpfile = uniqueFilename('tmp', 'my-test') +t.like(randomPrefixedTmpfile, /^tmp.my-test-[a-f0-9]{32}$/, 'random prefixed tmp file') + +var randomPrefixedAgain = uniqueFilename('tmp', 'my-test') +t.notEqual(randomPrefixedAgain, randomPrefixedTmpfile, 'random prefixed tmp files are not the same') + +var uniqueTmpfile = uniqueFilename('tmp', 'testing', '/my/thing/to/uniq/on') +t.like(uniqueTmpfile, /^tmp.testing-dd1ecbb112056bb8a7347e852ce3ddf9$/, 'unique filename') + +var uniqueAgain = uniqueFilename('tmp', 'testing', '/my/thing/to/uniq/on') +t.is(uniqueTmpfile, uniqueAgain, 'same unique string component produces same filename') |