Created
June 11, 2019 19:20
-
-
Save jsmithdev/1f31f9f3912d40f6b60bdc7e8098ee9f to your computer and use it in GitHub Desktop.
Generate UUID in vanilla JS via https://www.w3resource.com/javascript-exercises/javascript-math-exercise-23.php
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
function createUUID(){ | |
let dt = new Date().getTime() | |
const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
const r = (dt + Math.random()*16)%16 | 0 | |
dt = Math.floor(dt/16) | |
return (c=='x' ? r :(r&0x3|0x8)).toString(16) | |
}) | |
return uuid | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment