10 examples of 'uuid generator javascript' in JavaScript

Every line of 'uuid generator javascript' 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
19function generatorUUID() {
20 var d = new Date().getTime();
21 var uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
22 var r = (d + Math.random() * 16) % 16 | 0;
23 d = Math.floor(d / 16);
24 return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
25 });
26
27 return uuid;
28}
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

15function generateUUID() {
16 return $window.crypto ? generatorUUIDSecure() : generatorUUID();
17}
78function generateUUID() {
79 var d = new Date().getTime();
80 var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
81 var r = (d + Math.random()*16)%16 | 0;
82 d = Math.floor(d/16);
83 return (c=='x' ? r : (r&0x3|0x8)).toString(16);
84 });
85 return uuid;
86};
6function generateUUID() { // Public Domain/MIT
7 var d = new Date().getTime();
8 if (typeof performance !== 'undefined' && typeof performance.now === 'function') {
9 d += performance.now(); //use high-precision timer if available
10 }
11 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
12 var r = (d + Math.random() * 16) % 16 | 0;
13 d = Math.floor(d / 16);
14 return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
15 });
16}
61function generateUuid() {
62 return Math.random().toString() +
63 Math.random().toString() +
64 Math.random().toString();
65}
10export function generateUUID() {
11 let d = Date.now();
12 if (window.performance && typeof window.performance.now === 'function') {
13 d += window.performance.now(); // use high-precision timer if available
14 }
15 const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
16 const r = (d + Math.random() * 16) % 16 | 0;
17 d = Math.floor(d / 16);
18 return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
19 });
20 return uuid;
21}
4function uuid() : string {
5 return 'v' + THREE.Math.generateUUID().replace(/-/gi, '');
6}
8function generateUuid() {
9 let uuid = "",
10 i,
11 random;
12 for (let i = 0; i < 32; i++) {
13 random = (Math.random() * 16) | 0;
14
15 if (i == 8 || i == 12 || i == 16 || i == 20) {
16 uuid += "-";
17 }
18 uuid += (i == 12 ? 4 : i == 16 ? (random & 3) | 8 : random).toString(16);
19 }
20 return uuid;
21}
310generateUUID() {
311 return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
312 const r = Math.floor(Math.random() * 16) || 0;
313 return c === 'x' ? r.toString(16) : c;
314 });
315}
193export function generateUUID(): string {
194 if (process.env.NODE_ENV === 'test') {
195 return 'test-uuid';
196 }
197 let d = new Date().getTime();
198 const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
199 // tslint:disable-next-line:no-bitwise
200 const r = (d + Math.random() * 16) % 16 | 0;
201 d = Math.floor(d / 16);
202 // tslint:disable-next-line:no-bitwise
203 return (c === 'x' ? r : (r & 0x7) | 0x8).toString(16);
204 });
205 return uuid;
206}

Related snippets