Sha256: dc55c574a6aa44845f763ee843150e0c403e139b6fbc93774064ceefaf48e295

Contents?: true

Size: 642 Bytes

Versions: 17

Compression:

Stored size: 642 Bytes

Contents

var pseudoRandomBytes = require('crypto').pseudoRandomBytes
var escape = require('base64-url').escape

var pseudoRandomBytesProm

module.exports = uid

function uid(length, cb) {
  if (cb) {
    return pseudoRandomBytes(length, function (err, buf) {
      if (err) return cb(err)
      cb(null, escapeBuffer(buf))
    })
  }

  pseudoRandomBytesProm || (pseudoRandomBytesProm = require('mz/crypto').pseudoRandomBytes)
  return pseudoRandomBytesProm(length).then(escapeBuffer)
}

uid.sync = function uid_sync(length) {
  return escapeBuffer(pseudoRandomBytes(length))
}

function escapeBuffer(buf) {
  return escape(buf.toString('base64'))
}

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
hooch-0.4.2 jasmine/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
hooch-0.2.0 jasmine/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
hooch-0.1.0 jasmine/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
hooch-0.0.8 jasmine/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
hooch-0.0.7 jasmine/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
hooch-0.0.6 jasmine/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
entangled-0.0.16 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
entangled-0.0.15 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
entangled-0.0.14 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
entangled-0.0.13 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
entangled-0.0.12 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
entangled-0.0.11 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js
entangled-0.0.10 spec/dummy/public/node_modules/karma/node_modules/connect/node_modules/express-session/node_modules/uid-safe/index.js