Created
March 14, 2024 21:19
-
-
Save Angelfire/3fbc9debefcb4f1154fb9db7b04c95e5 to your computer and use it in GitHub Desktop.
Generates a random ID with the given prefix.
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
/** | |
* Generates a random ID with the given prefix. | |
* @param prefix - The prefix to be added to the generated ID. | |
* @returns The generated random ID. | |
*/ | |
export const generateRandomId = (prefix: string) => | |
`${prefix}${btoa(Date.now().toString())}${btoa( | |
(Math.random() * 1_000_000_000_000).toString() | |
)}`.replace(/=+/g, ""); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment