Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Last active October 4, 2023 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sethdavis512/42c7d7959aca57f47bf28c8a1c566c41 to your computer and use it in GitHub Desktop.
Save sethdavis512/42c7d7959aca57f47bf28c8a1c566c41 to your computer and use it in GitHub Desktop.
Get unique ID function
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