Skip to content

Instantly share code, notes, and snippets.

@IamManchanda
Last active December 14, 2020 08:27
Show Gist options
  • Save IamManchanda/146feb8b14aa550d645098d467b2880a to your computer and use it in GitHub Desktop.
Save IamManchanda/146feb8b14aa550d645098d467b2880a to your computer and use it in GitHub Desktop.
Create your own Universally Unique Identifier (UUID) - v4
function uuidv4() {
const init = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
return init.replace(/[xy]/g, (c) => {
const r = Math.random() * 16 | 0;
const v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment