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 = require'passy';var id = passyidentity66;console.logid; // '-gDzpbAJNzl'identityisValidid; // trueidentityisValid121 // falsevar date = identitytoDateidconsole.logdate; // Wed Jul 24 2013 11:05:33 GMT+0100 (BST)
var random = require'passy'random;var url = random;console.logurl; // 5I13rNbNgttUrandomisValidurl; // truerandomisValid'3%' // falsevar raw = randomtoArrayurl;console.lograw; // [ 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.