Generate unique ids and hashes
UID()creates a short, time-ordered, unique id (12 characters). It sorts by creation time and is what theUIDinput type validates. Use it as the primary key of your documents.GUID(length)creates a random string of the requested length. Use it for tokens and file names.HASH(value)returns a fast numeric hash (not cryptographic). Use it for cache keys, ETags and sharding, never for passwords.
exports.install = function() {
ROUTE('GET /ids/', ids);
};
function ids($) {
var a = UID();
var b = UID();
$.json({
uid: a,
uidlength: a.length,
valid: a.isUID(),
different: a !== b,
guid: GUID(20),
sameHash: HASH('total') === HASH('total'),
otherHash: HASH('total') !== HASH('Total'),
type: typeof(HASH('total'))
});
}