Last active
August 8, 2019 13:04
-
-
Save MelodicCrypter/5f8d669d70cca844d50724c69fde9844 to your computer and use it in GitHub Desktop.
A small javascript utility that will generate unique (hashed-type) strings.
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
// Your unique variables here | |
const allCapsAlpha = [..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"]; | |
const allLowerAlpha = [..."abcdefghijklmnopqrstuvwxyz"]; | |
const allUniqueChars = [...'~!@#$%^&*()_+`-=[]\\{}|;:\'",./<>?']; | |
const allNumbers = [..."0123456789"]; | |
// This is the 'pattern', alternate the order if you want. | |
// The final output (order of pattern) will not be the same though, | |
// but you can improve this utility to achieve that. | |
const base = [...allCapsAlpha, ...allNumbers, ...allLowerAlpha, ...allUniqueChars]; | |
// The generator() | |
// base = the pattern you want to generate from | |
// len = the length of the output strings | |
const generator = (base, len) => { | |
return [...Array(len)] | |
.map(i => base[Math.random()*base.length|0]) | |
.join(''); | |
}; | |
// Test | |
console.log('OUTPUT: ', generator(base, 28)); | |
// OUTPUT: )ne]iGl'XBX%(FPCU:4JRnV'#mS= | |
// OUTPUT: kRY.}PZ~]Q|LQ1;qJ1Gnh>,zC{T@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment