Created
April 17, 2016 17:24
-
-
Save rdbox/cfd09287262de95ea4a0a3b4c2bf5b09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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