Last active
October 6, 2018 17:52
-
-
Save lap00zza/28a72ec5496914a756fac3479a7a8a03 to your computer and use it in GitHub Desktop.
Quick 'n' dirty id generator
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
const generateId = (len=16) => { | |
const allowedRanges = [[48, 57], [65,90], [97, 122]]; | |
let str = ""; | |
let expand = allowedRanges.reduce((acc, each) => { | |
let [start, end] = each; | |
let nums = []; | |
for(let i = start; i <= end; i++) { | |
nums.push(i); | |
}; | |
return acc.concat(nums); | |
}, []); | |
for (let i = 0; i < len; i++) { | |
str += String.fromCharCode( | |
expand[Math.floor(Math.random() * expand.length)] | |
); | |
} | |
return str; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment