@kvsrohit/shortid
ShortId (https://www.npmjs.com/package/shortid) has been an amazing module to generate short non-sequential url-friendly unique ids.
However it is no longer maintained and suggests using NanoId (https://www.npmjs.com/package/nanoid) as replacement.
NanoId is simple and straight forward. However, it is not a drop-in replacement. Specially places where ShortId is a transient dependency.
This project uses NanoId and provides same interface as ShortId so that it can be used as drop-in resolution for transient dependencies.
Usage
const shortid = require('@kvsrohit/shortid');
console.log(shortid.generate());
Mongoose Unique Id
_id: {
'type': String,
'default': shortid.generate
},
API
const shortid = require('@kvsrohit/shortid');
shortid.generate()
Returns string
non-sequential unique id.
Example
users.insert({
_id: shortid.generate(),
name: '...',
email: '...'
});