Collision-resistant IDs optimized for horizontal scaling and performance.
A slim, alternative, and compatible implementation of cuid for node,
also featuring a wide range of options, as well as custom random number generator support.
It can serve as a drop-in replacement, and is also faster than cuid.
// Create a random number generator;// It has to have a method called `random`var generator = { random: function() { return 5 // chosen by fair dice roll }}// Create a custom scuid instancevar scuid = require( 'scuid' ).create({ rng: generator})
Use other custom options
Note that fiddeling with these might make your IDs incompatible with cuid's guarantees.
var scuid = require( 'scuid' ).create({ prefix: 'c', // the ID's prefix base: 36, // radix used in .toString() calls (2-36) blockSize: 4, // block size to pad and trim to fill: '0', // block padding character pid: process.pid, // process ID fingerprint: scuid.createFingerprint( [pid], [hostname] ), // Machine fingerprint rng: Math, // Random number generator})
Tests
Just like cuid, collision resistance for both – slugs and IDs – is tested
over 1 million and 2 million iterations respectively.
To run the tests, run: