8 examples of 'uuidv4' in JavaScript

Every line of 'uuidv4' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
256function getUuidV4String() {
257 return uuidToString(getUuidV4());
258}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

10export default function uuidV4 () {
11 return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
12 s4() + '-' + s4() + s4() + s4()
13}
30function uuid(): string {
31 return v4();
32}
46uuidv4 ()
47{
48 const uuid = ([1e7]+-1e3+-4e3+-8e3+-1e11).replace (/[018]/g, c => (c ^ crypto.getRandomValues (new Uint8Array (1))[0] & 15 >> c / 4).toString (16));
49 return ("_" + uuid);
50}
49function uuidv4() {
50 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
51 let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
52 return v.toString(16);
53 });
54}
74function uuidv4() {
75 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
76 var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
77 return v.toString(16);
78 });
79}
2export default function uuidv4() {
3 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
4 // eslint-disable-next-line
5 let r = Math.random() * 16 | 0,
6 // eslint-disable-next-line
7 v = c == 'x' ? r : (r & 0x3 | 0x8);
8 return v.toString(16);
9 });
10}
23generate(): string {
24 return uuidv4();
25}

Related snippets