Passy is a CommonJS module for Node.js that has identity and random id generations functions. It's used baseURL encoding and created ids of various predefined lengths (with built in creation dates) and also pure random ids of any length. Time based ids store the creation date within, so don't require additional storage for a 'created' field which is useful for in-memory DBs like REDIS.
baseURL is a simple encoding scheme where each character represents 64 values which work safely in URLs ie (0-9a-zA-Z-_). Each ASCII character encodes 6 binary bits. Input binary numbers must be divisible by 6; unlike base64 there is no scheme to encode variable length binary inputs. Bit lengths which are multiples of 6 & 8 tend to be the most efficient for humans and machines.
npm install --save passy
var passy = ;var id = passy;console; // '-gDzpbAJNzl'identity; // trueidentity // falsevar date = identityconsole; // Wed Jul 24 2013 11:05:33 GMT+0100 (BST)
var random = random;var url = ;console; // 5I13rNbNgttUrandom; // truerandom // falsevar raw = random;console; // [ 5, 44, 1, 3, 27, 49, 11, 49, 16, 29, 29, 56 ]
See code and tests for detailed info.
Create Github issues for all bugs, features & requests. Pull requests are welcome. Make sure tests are included.