Skip to content

Instantly share code, notes, and snippets.

@garenyondem
Created February 25, 2020 18:30
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 garenyondem/4fadf0c16be25a4ee1628f454ba66294 to your computer and use it in GitHub Desktop.
Save garenyondem/4fadf0c16be25a4ee1628f454ba66294 to your computer and use it in GitHub Desktop.
Create uuid
export function uuid() {
let rnd: number, val: { toString: (arg0: number) => string };
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, c => {
rnd = (Math.random() * 16) | 0;
val = c === "x" ? rnd : (rnd & 0x3) | 0x8;
return val.toString(16);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment