filer/src/shared.js

28 lines
562 B
JavaScript
Raw Normal View History

function generateRandom(template) {
return template.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
function guid() {
return generateRandom('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx').toUpperCase();
}
/**
* Generate a string of n random characters. Defaults to n=6.
*/
function randomChars(n) {
n = n || 6;
var template = 'x'.repeat(n);
return generateRandom(template);
}
2013-05-31 01:38:44 +00:00
function nop() {}
2013-05-31 01:38:44 +00:00
module.exports = {
guid: guid,
nop: nop,
randomChars: randomChars
};