idgen
Minimal ID generator
Features (vs. traditional UUIDs):
- Uses base64url encoding for compactness and readability. I think hex-based UUIDs are too long and hard to identify at a glance. base64url works nicely in URLs and can be generated from a Buffer.
- Supports deterministic IDs by passing in a Buffer, created using SHA or HMAC for example.
- Supports generating any length ID (adjust length to increase uniqueness or compactness).
- Can produce cryptographically secure random strings.
Install
$ npm install idgen
Usage
var idgen = ; // simple 8-character opaque id;// returns: 1WWQ1OEc // more collision-proof 16-character id:;// returns: C1574ad7cX6ztPsD // from a Buffer:;// returns: jaMHiVNo_MpTmVUDQH-VDDKR6x00r1Ejf1AKx-W98Ak // to get the Buffer back,// returns: 8da307895368fcca53995503407f950c3291eb1d34af51237f500ac7e5bdf009 // from a Buffer, truncated to 16 characters:;// returns: jaMHiVNo_MpTmVUD
CLI version
$ npm install -g idgen$ idgen1WWQ1OEc$ idgen 16C1574ad7cX6ztPsD$ echo -n "carlos" | idgenY2FybG9z
License
MIT