Detalhes do pacote

uid2

coreh6.4mMIT1.0.0

strong uid

readme (leia-me)

uid2

NPM version

Generate unique ids. Pass in a length and it returns a string.

Installation

npm install uid2

Examples

Without a callback it is synchronous:

const uid = require('uid2');

const id = uid(10);
// id => "hbswt489ts"

With a callback it is asynchronous:

const uid = require('uid2');

uid(10, function (err, id) {
  if (err) throw err;
  // id => "hbswt489ts"
});

Imported via uid2/promises it returns a Promise:

const uid = require('uid2/promises');

async function foo() {
  const id = await uid(10);
  // id => "hbswt489ts"
}

License

MIT

changelog (log de mudanças)

1.0.0 - August 24, 2021

  • Switch from crypto.pseudoRandomBytes() back to crypto.randomBytes() (Both are equivalent in Node 4.x and above, and pseudoRandomBytes() is deprecated in Node 11.x and above)
  • Add engines field to package.json
  • Fix character distribution non-uniformity issue by adding back - and _ to generated ids
  • Add character distribution test
  • Enable strict mode
  • Fix JSDoc optional parameter syntax
  • Add Promise-based API

0.0.4 - August 24, 2021

  • Add README.md
  • Add repository field to package.json
  • Add license field to package.json
  • Remove unused var, added param documentation

0.0.3 - July 6, 2013

  • Add MIT License
  • Change string generation to not rely internally on base64 byte buffer encoding
  • Change string generation to only use the 62 latin alphanumeric chars
  • Switch from crypto.randomBytes() to crypto.pseudoRandomBytes()

0.0.2 - February 25, 2013

  • Make unique ids safe for use in URLs (Using 62 latin alphanumeric chars, - and _)

0.0.1 - February 4, 2013

  • Initial Release