ForgeTotal.js 5
en

Total.js 5

Generate unique ids and hashes

Total.js 5 · total5@0.0.19 utilitiesidssecurity Executed against Total.js 5
  • UID() creates a short, time-ordered, unique id (12 characters). It sorts by creation time and is what the UID input 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.
controllers/ids.js
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'))
	});
}