Last active
October 4, 2023 20:05
-
-
Save sethdavis512/42c7d7959aca57f47bf28c8a1c566c41 to your computer and use it in GitHub Desktop.
Get unique ID function
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
function getUniqueId(prefix: string, length: number = 8): string { | |
let result = `${prefix}-`; | |
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
const charactersLength = characters.length; | |
let counter = 0; | |
while (counter < length) { | |
result = `${result}${characters.charAt(Math.floor(Math.random() * charactersLength))}`; | |
counter += 1; | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment