Created
September 23, 2018 03:47
-
-
Save zheeeng/d90aba063c3026ee203aa577d5510de0 to your computer and use it in GitHub Desktop.
Get UUID v4
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
// reference: https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript/2117523#2117523 | |
function uuidv4(): string { | |
const uuidTpl = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' | |
return uuidTpl.replace(/[xy]/g, c => | |
String( | |
c == 'x' ? (Math.random() * 16) | 0 : ((Math.random() * 16) & 0x3) | 0x8 | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment