项目作者: crypto-utils

项目描述 :
URL and cookie safe UIDs
高级语言: JavaScript
项目地址: git://github.com/crypto-utils/uid-safe.git
创建时间: 2014-06-18T09:01:07Z
项目社区:https://github.com/crypto-utils/uid-safe

开源协议:MIT License

下载


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

  1. $ npm install uid-safe

API

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

  1. uid(18, function (err, string) {
  2. if (err) throw err
  3. // do something with the string
  4. })

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

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

uid.sync(byteLength)

A synchronous version of above.

  1. var string = uid.sync(18)

License

MIT