A featureful dependency-free UID generator
Clerobee - a featureful UID generator
======== clerobee is a very handy dependency-free utility library allowing to generate UIDs considering actual time, network resources and process in a distributed environment.
Following use cases are supported:
Normal UIDs: Identifiers for general usage with length between 4 and 256. Can be used as cryptographic keys, user IDs, session keys, etc.
Derived UIDs: To express ownership-like relations between identifiers.
If you have to identify devices and be able to link them to a user with verify the ownership against the userID, then simply generate a UID for the user and generate derived UIDs for the devices.
Therethrough the ownership of the device where for example a REST request is coming, can be verified.
Sourced UIDs: Using a JS object data as source for the generation process.
For example to generate product/license keys based on user information and to check if they can be matched while a possible registration process later on.
var Cerobee = require'clerobee';// optional default length for the IDS is passed.// 16 would be used if nothing is given.var cerobee = 128 ;// generate a normal UID with length of 128var nID = cerobeegenerate;// generate a normal UID with length of 16var nID_2 = cerobeegenerate 16 ;// Generates derived UID using the 'nID' as basis.// Its length will be the same: 128var sID = cerobeegenerate nID ;// Tests if 'sID' is really derived from 'nID'.// Test will fail will any other UIDs but 'sID'var test_1 = cerobeeisDerived nID sID ;// Creates user datavar customer = email:'email@example.com' ;// Generates Sourced UID based on customer data with length of 128var pID = cerobeegenerate customer 128 ;// Tests if the given sourced UID relly carries the given user data.// Test will fail with any other pair of user data and UID but thisvar test_2 = cerobeeisSourced reference 128 pID ;
And that's it!