Created
April 19, 2019 07:38
-
-
Save jogboms/a2c4bb3dd5f9db29318fdc591bbc82ad to your computer and use it in GitHub Desktop.
This file contains hidden or 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 alphabet = "abcdefghijklmnopqrst"; | |
| const randomStr = Array(3) | |
| .fill(null) | |
| .map(() => Math.floor(Math.random() * alphabet.length)) | |
| .map(num => alphabet[num]) | |
| .join(""); | |
| let counter = 0; | |
| export function newId<T extends string>(prefix: string = "id") { | |
| return `${prefix}_${randomStr}_${counter++}` as T; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment