Created
April 24, 2020 15:29
-
-
Save jestho/00f08326722085c7e7e1a2b59c1d71ef to your computer and use it in GitHub Desktop.
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
type UUID = string & { UUID: never }; | |
export const uuid = () => | |
"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => { | |
const r = (Math.random() * 16) | 0; | |
const v = c == "x" ? r : (r & 0x3) | 0x8; | |
return v.toString(16); | |
}) as UUID; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment