Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

uid-safe

crypto-utils13mMIT2.1.5TypeScript support: definitely-typed

URL and cookie safe UIDs

random, generator, uid, safe

readme

uid-safe

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

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 and 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

$ npm install uid-safe

API

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.

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').

uid(18).then(function (string) {
  // do something with the string
})

uid.sync(byteLength)

A synchronous version of above.

var string = uid.sync(18)

License

MIT

changelog

2.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

2.1.2 / 2016-08-15

2.1.1 / 2016-05-04

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

1.0.3 / 2015-01-31

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