Skip to content

Instantly share code, notes, and snippets.

@rdbox
Created April 17, 2016 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdbox/cfd09287262de95ea4a0a3b4c2bf5b09 to your computer and use it in GitHub Desktop.
Save rdbox/cfd09287262de95ea4a0a3b4c2bf5b09 to your computer and use it in GitHub Desktop.
/*
Example:
hash(5);
"XjJfV"
hash('xxxx-xx-xxxx-2011')
"YDFb-5e-cShX-2011"
hash = (+new Date());
console.log(hash);
1317814876299
*/
var hash = function(s) {
var n;
if (typeof(s) == 'number' && s === parseInt(s, 10)) {
s = Array(s + 1).join('x');
}
return s.replace(/x/g, function() {
var n = Math.round(Math.random() * 61) + 48;
n = n > 57 ? (n + 7 > 90 ? n + 13 : n + 7) : n;
return String.fromCharCode(n);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment