pax_global_header00006660000000000000000000000064131405132130014503gustar00rootroot0000000000000052 comment=e15ef6049b23826eabe2d88e9f1835436e54e0d9 uid-safe-2.1.5/000077500000000000000000000000001314051321300132055ustar00rootroot00000000000000uid-safe-2.1.5/.eslintignore000066400000000000000000000000261314051321300157060ustar00rootroot00000000000000coverage node_modules uid-safe-2.1.5/.eslintrc000066400000000000000000000000341314051321300150260ustar00rootroot00000000000000{ "extends": "standard" } uid-safe-2.1.5/.gitignore000066400000000000000000000001001314051321300151640ustar00rootroot00000000000000 .DS_Store* *.log *.gz node_modules coverage package-lock.json uid-safe-2.1.5/.travis.yml000066400000000000000000000017651314051321300153270ustar00rootroot00000000000000language: node_js node_js: - "0.8" - "0.10" - "0.12" - "1.8" - "2.5" - "3.3" - "4.8" - "5.12" - "6.11" - "7.10" - "8.2" sudo: false cache: directories: - node_modules before_install: # Skip updating shrinkwrap / lock - "npm config set shrinkwrap false" # Setup Node.js version-specific dependencies - "test $TRAVIS_NODE_VERSION != '0.8' || npm rm --save-dev istanbul" - "test $(echo $TRAVIS_NODE_VERSION | cut -d. -f1) -ge 4 || npm rm --save-dev $(grep -E '\"eslint\\S*\"' package.json | cut -d'\"' -f2)" # Update Node.js modules - "test ! -d node_modules || npm prune" - "test ! -d node_modules || npm rebuild" script: # Run test script, depending on istanbul install - "test ! -z $(npm -ps ls istanbul) || npm test" - "test -z $(npm -ps ls istanbul) || npm run-script test-travis" - "test -z $(npm -ps ls eslint ) || npm run-script lint" after_script: - "test -e ./coverage/lcov.info && npm install coveralls@2 && cat ./coverage/lcov.info | coveralls" uid-safe-2.1.5/HISTORY.md000066400000000000000000000016601314051321300146730ustar00rootroot000000000000002.1.5 / 2017-08-02 ================== * perf: remove only trailing `=` 2.1.4 / 2017-03-02 ================== * Remove `base64-url` dependency 2.1.3 / 2016-10-30 ================== * deps: base64-url@1.3.3 2.1.2 / 2016-08-15 ================== * deps: base64-url@1.3.2 2.1.1 / 2016-05-04 ================== * deps: base64-url@1.2.2 2.1.0 / 2016-01-17 ================== * Use `random-bytes` for byte source 2.0.0 / 2015-05-08 ================== * Use global `Promise` when returning a promise 1.1.0 / 2015-02-01 ================== * Use `crypto.randomBytes`, if available * deps: base64-url@1.2.1 1.0.3 / 2015-01-31 ================== * Fix error branch that would throw * deps: base64-url@1.2.0 1.0.2 / 2015-01-08 ================== * Remove dependency on `mz` 1.0.1 / 2014-06-18 ================== * Remove direct `bluebird` dependency 1.0.0 / 2014-06-18 ================== * Initial release uid-safe-2.1.5/LICENSE000066400000000000000000000022301314051321300142070ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Jonathan Ong Copyright (c) 2015-2017 Douglas Christopher Wilson 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. uid-safe-2.1.5/README.md000066400000000000000000000041551314051321300144710ustar00rootroot00000000000000# uid-safe [![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![Node.js Version][node-version-image]][node-version-url] [![Build Status][travis-image]][travis-url] [![Test Coverage][coveralls-image]][coveralls-url] URL and cookie safe UIDs Create cryptographically secure UIDs safe for both cookie and URL usage. This is in contrast to modules such as [rand-token](https://www.npmjs.com/package/rand-token) and [uid2](https://www.npmjs.com/package/uid2) whose UIDs are actually skewed due to the use of `%` and unnecessarily truncate the UID. Use this if you could still use UIDs with `-` and `_` in them. ## Installation ```sh $ npm install uid-safe ``` ## API ```js var uid = require('uid-safe') ``` ### uid(byteLength, callback) Asynchronously create a UID with a specific byte length. Because `base64` encoding is used underneath, this is not the string length. For example, to create a UID of length 24, you want a byte length of 18. ```js uid(18, function (err, string) { if (err) throw err // do something with the string }) ``` ### uid(byteLength) Asynchronously create a UID with a specific byte length and return a `Promise`. **Note**: To use promises in Node.js _prior to 0.12_, promises must be "polyfilled" using `global.Promise = require('bluebird')`. ```js uid(18).then(function (string) { // do something with the string }) ``` ### uid.sync(byteLength) A synchronous version of above. ```js var string = uid.sync(18) ``` ## License [MIT](LICENSE) [npm-image]: https://img.shields.io/npm/v/uid-safe.svg [npm-url]: https://npmjs.org/package/uid-safe [node-version-image]: https://img.shields.io/node/v/uid-safe.svg [node-version-url]: https://nodejs.org/en/download/ [travis-image]: https://img.shields.io/travis/crypto-utils/uid-safe/master.svg [travis-url]: https://travis-ci.org/crypto-utils/uid-safe [coveralls-image]: https://img.shields.io/coveralls/crypto-utils/uid-safe/master.svg [coveralls-url]: https://coveralls.io/r/crypto-utils/uid-safe?branch=master [downloads-image]: https://img.shields.io/npm/dm/uid-safe.svg [downloads-url]: https://npmjs.org/package/uid-safe uid-safe-2.1.5/index.js000066400000000000000000000036131314051321300146550ustar00rootroot00000000000000/*! * uid-safe * Copyright(c) 2014 Jonathan Ong * Copyright(c) 2015-2017 Douglas Christopher Wilson * MIT Licensed */ 'use strict' /** * Module dependencies. * @private */ var randomBytes = require('random-bytes') /** * Module variables. * @private */ var EQUAL_END_REGEXP = /=+$/ var PLUS_GLOBAL_REGEXP = /\+/g var SLASH_GLOBAL_REGEXP = /\//g /** * Module exports. * @public */ module.exports = uid module.exports.sync = uidSync /** * Create a unique ID. * * @param {number} length * @param {function} [callback] * @return {Promise} * @public */ function uid (length, callback) { // validate callback is a function, if provided if (callback !== undefined && typeof callback !== 'function') { throw new TypeError('argument callback must be a function') } // require the callback without promises if (!callback && !global.Promise) { throw new TypeError('argument callback is required') } if (callback) { // classic callback style return generateUid(length, callback) } return new Promise(function executor (resolve, reject) { generateUid(length, function onUid (err, str) { if (err) return reject(err) resolve(str) }) }) } /** * Create a unique ID sync. * * @param {number} length * @return {string} * @public */ function uidSync (length) { return toString(randomBytes.sync(length)) } /** * Generate a unique ID string. * * @param {number} length * @param {function} callback * @private */ function generateUid (length, callback) { randomBytes(length, function (err, buf) { if (err) return callback(err) callback(null, toString(buf)) }) } /** * Change a Buffer into a string. * * @param {Buffer} buf * @return {string} * @private */ function toString (buf) { return buf.toString('base64') .replace(EQUAL_END_REGEXP, '') .replace(PLUS_GLOBAL_REGEXP, '-') .replace(SLASH_GLOBAL_REGEXP, '_') } uid-safe-2.1.5/package.json000066400000000000000000000023531314051321300154760ustar00rootroot00000000000000{ "name": "uid-safe", "description": "URL and cookie safe UIDs", "version": "2.1.5", "contributors": [ "Douglas Christopher Wilson ", "Jonathan Ong (http://jongleberry.com)" ], "license": "MIT", "repository": "crypto-utils/uid-safe", "dependencies": { "random-bytes": "~1.0.0" }, "devDependencies": { "bluebird": "3.5.0", "eslint": "3.19.0", "eslint-config-standard": "10.2.1", "eslint-plugin-import": "2.7.0", "eslint-plugin-node": "5.1.1", "eslint-plugin-promise": "3.5.0", "eslint-plugin-standard": "3.0.1", "istanbul": "0.4.5", "mocha": "2.5.3" }, "files": [ "LICENSE", "HISTORY.md", "README.md", "index.js" ], "engines": { "node": ">= 0.8" }, "scripts": { "lint": "eslint .", "test": "mocha --trace-deprecation --reporter spec --bail --check-leaks test/", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --trace-deprecation --reporter dot --check-leaks test/", "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --trace-deprecation --reporter spec --check-leaks test/" }, "keywords": [ "random", "generator", "uid", "safe" ] } uid-safe-2.1.5/test/000077500000000000000000000000001314051321300141645ustar00rootroot00000000000000uid-safe-2.1.5/test/.eslintrc000066400000000000000000000000451314051321300160070ustar00rootroot00000000000000{ "env": { "mocha": true } } uid-safe-2.1.5/test/test.js000066400000000000000000000041351314051321300155040ustar00rootroot00000000000000var assert = require('assert') var uid = require('..') var Promise = global.Promise || require('bluebird') // Add Promise to mocha's global list global.Promise = global.Promise describe('uid()', function () { describe('with global Promise', function () { before(function () { global.Promise = Promise }) after(function () { global.Promise = undefined }) it('should return a uid of the correct length', function () { return uid(18).then(function (val) { assert.equal(24, Buffer.byteLength(val)) }) }) it('should not contain +, /, or =', function () { return uid(100000).then(function (val) { assert(!~val.indexOf('+')) assert(!~val.indexOf('/')) assert(!~val.indexOf('=')) }) }) }) describe('without global Promise', function () { before(function () { global.Promise = undefined }) after(function () { global.Promise = Promise }) it('should require callback', function () { assert.throws(function () { uid(18) }, /argument callback.*required/) }) it('should error for bad callback', function () { assert.throws(function () { uid(18, 'silly') }, /argument callback.*function/) }) it('should return a uid of the correct length', function (done) { uid(18, function (err, val) { if (err) return done(err) assert.equal(24, Buffer.byteLength(val)) done() }) }) it('should not contain +, /, or =', function (done) { uid(1000000, function (err, val) { if (err) return done(err) assert(!~val.indexOf('+')) assert(!~val.indexOf('/')) assert(!~val.indexOf('=')) done() }) }) }) }) describe('uid.sync()', function () { it('should return a uid of the correct length', function () { var val = uid.sync(18) assert.equal(24, Buffer.byteLength(val)) }) it('should not contain +, /, or =', function () { var val = uid.sync(100000) assert(!~val.indexOf('+')) assert(!~val.indexOf('/')) assert(!~val.indexOf('=')) }) })