Skip to content

Instantly share code, notes, and snippets.

@jogboms
Created April 19, 2019 07:38
Show Gist options
  • Select an option

  • Save jogboms/a2c4bb3dd5f9db29318fdc591bbc82ad to your computer and use it in GitHub Desktop.

Select an option

Save jogboms/a2c4bb3dd5f9db29318fdc591bbc82ad to your computer and use it in GitHub Desktop.
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