Created
March 3, 2020 10:00
-
-
Save amadeuszblanik/f6b7f06a46e81d84e60285cb2df14c89 to your computer and use it in GitHub Desktop.
[TypeScript] Generate random ID
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
export const idGenerator = (length: number) => { | |
const allowedCharacters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
let response: string = "" | |
for (let i = 0; i < length; i++) { | |
const {length: charLength} = allowedCharacters | |
response += allowedCharacters.charAt(Math.floor(Math.random() * charLength)) | |
} | |
return response | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment