uuid 8.3.2 → 9.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +30 -73
  2. package/dist/commonjs-browser/index.js +79 -0
  3. package/dist/commonjs-browser/md5.js +223 -0
  4. package/dist/commonjs-browser/native.js +11 -0
  5. package/dist/commonjs-browser/nil.js +8 -0
  6. package/dist/commonjs-browser/parse.js +45 -0
  7. package/dist/commonjs-browser/regex.js +8 -0
  8. package/dist/commonjs-browser/rng.js +25 -0
  9. package/dist/commonjs-browser/sha1.js +104 -0
  10. package/dist/commonjs-browser/stringify.js +44 -0
  11. package/dist/commonjs-browser/v1.js +107 -0
  12. package/dist/commonjs-browser/v3.js +16 -0
  13. package/dist/commonjs-browser/v35.js +80 -0
  14. package/dist/commonjs-browser/v4.js +43 -0
  15. package/dist/commonjs-browser/v5.js +16 -0
  16. package/dist/commonjs-browser/validate.js +17 -0
  17. package/dist/commonjs-browser/version.js +21 -0
  18. package/dist/esm-browser/md5.js +23 -23
  19. package/dist/esm-browser/native.js +4 -0
  20. package/dist/esm-browser/parse.js +2 -2
  21. package/dist/esm-browser/rng.js +4 -5
  22. package/dist/esm-browser/sha1.js +26 -26
  23. package/dist/esm-browser/stringify.js +9 -6
  24. package/dist/esm-browser/v1.js +17 -17
  25. package/dist/esm-browser/v3.js +1 -1
  26. package/dist/esm-browser/v35.js +12 -10
  27. package/dist/esm-browser/v4.js +9 -4
  28. package/dist/esm-browser/v5.js +1 -1
  29. package/dist/esm-browser/version.js +1 -1
  30. package/dist/esm-node/native.js +4 -0
  31. package/dist/esm-node/stringify.js +7 -3
  32. package/dist/esm-node/v1.js +2 -2
  33. package/dist/esm-node/v35.js +6 -4
  34. package/dist/esm-node/v4.js +7 -2
  35. package/dist/esm-node/version.js +1 -1
  36. package/dist/index.js +18 -18
  37. package/dist/native-browser.js +11 -0
  38. package/dist/native.js +15 -0
  39. package/dist/rng-browser.js +2 -3
  40. package/dist/stringify.js +8 -3
  41. package/dist/v1.js +2 -2
  42. package/dist/v35.js +7 -5
  43. package/dist/v4.js +8 -2
  44. package/dist/version.js +1 -1
  45. package/package.json +37 -41
  46. package/dist/umd/uuid.min.js +0 -1
  47. package/dist/umd/uuidNIL.min.js +0 -1
  48. package/dist/umd/uuidParse.min.js +0 -1
  49. package/dist/umd/uuidStringify.min.js +0 -1
  50. package/dist/umd/uuidValidate.min.js +0 -1
  51. package/dist/umd/uuidVersion.min.js +0 -1
  52. package/dist/umd/uuidv1.min.js +0 -1
  53. package/dist/umd/uuidv3.min.js +0 -1
  54. package/dist/umd/uuidv4.min.js +0 -1
  55. package/dist/umd/uuidv5.min.js +0 -1
@@ -4,17 +4,20 @@ import validate from './validate.js';
4
4
  * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
5
5
  */
6
6
 
7
- var byteToHex = [];
7
+ const byteToHex = [];
8
8
 
9
- for (var i = 0; i < 256; ++i) {
10
- byteToHex.push((i + 0x100).toString(16).substr(1));
9
+ for (let i = 0; i < 256; ++i) {
10
+ byteToHex.push((i + 0x100).toString(16).slice(1));
11
11
  }
12
12
 
13
- function stringify(arr) {
14
- var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
13
+ export function unsafeStringify(arr, offset = 0) {
15
14
  // Note: Be careful editing this code! It's been tuned for performance
16
15
  // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
17
- var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
16
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
17
+ }
18
+
19
+ function stringify(arr, offset = 0) {
20
+ const uuid = unsafeStringify(arr, offset); // Consistency check for valid UUID. If this throws, it's likely due to one
18
21
  // of the following:
19
22
  // - One or more input array values don't map to a hex octet (leading to
20
23
  // "undefined" in the uuid)
@@ -1,28 +1,28 @@
1
1
  import rng from './rng.js';
2
- import stringify from './stringify.js'; // **`v1()` - Generate time-based UUID**
2
+ import { unsafeStringify } from './stringify.js'; // **`v1()` - Generate time-based UUID**
3
3
  //
4
4
  // Inspired by https://github.com/LiosK/UUID.js
5
5
  // and http://docs.python.org/library/uuid.html
6
6
 
7
- var _nodeId;
7
+ let _nodeId;
8
8
 
9
- var _clockseq; // Previous uuid creation time
9
+ let _clockseq; // Previous uuid creation time
10
10
 
11
11
 
12
- var _lastMSecs = 0;
13
- var _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
12
+ let _lastMSecs = 0;
13
+ let _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
14
14
 
15
15
  function v1(options, buf, offset) {
16
- var i = buf && offset || 0;
17
- var b = buf || new Array(16);
16
+ let i = buf && offset || 0;
17
+ const b = buf || new Array(16);
18
18
  options = options || {};
19
- var node = options.node || _nodeId;
20
- var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
19
+ let node = options.node || _nodeId;
20
+ let clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
21
21
  // specified. We do this lazily to minimize issues related to insufficient
22
22
  // system entropy. See #189
23
23
 
24
24
  if (node == null || clockseq == null) {
25
- var seedBytes = options.random || (options.rng || rng)();
25
+ const seedBytes = options.random || (options.rng || rng)();
26
26
 
27
27
  if (node == null) {
28
28
  // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
@@ -39,12 +39,12 @@ function v1(options, buf, offset) {
39
39
  // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
40
40
 
41
41
 
42
- var msecs = options.msecs !== undefined ? options.msecs : Date.now(); // Per 4.2.1.2, use count of uuid's generated during the current clock
42
+ let msecs = options.msecs !== undefined ? options.msecs : Date.now(); // Per 4.2.1.2, use count of uuid's generated during the current clock
43
43
  // cycle to simulate higher resolution clock
44
44
 
45
- var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs)
45
+ let nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs)
46
46
 
47
- var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression
47
+ const dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression
48
48
 
49
49
  if (dt < 0 && options.clockseq === undefined) {
50
50
  clockseq = clockseq + 1 & 0x3fff;
@@ -67,13 +67,13 @@ function v1(options, buf, offset) {
67
67
 
68
68
  msecs += 12219292800000; // `time_low`
69
69
 
70
- var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
70
+ const tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
71
71
  b[i++] = tl >>> 24 & 0xff;
72
72
  b[i++] = tl >>> 16 & 0xff;
73
73
  b[i++] = tl >>> 8 & 0xff;
74
74
  b[i++] = tl & 0xff; // `time_mid`
75
75
 
76
- var tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
76
+ const tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
77
77
  b[i++] = tmh >>> 8 & 0xff;
78
78
  b[i++] = tmh & 0xff; // `time_high_and_version`
79
79
 
@@ -85,11 +85,11 @@ function v1(options, buf, offset) {
85
85
 
86
86
  b[i++] = clockseq & 0xff; // `node`
87
87
 
88
- for (var n = 0; n < 6; ++n) {
88
+ for (let n = 0; n < 6; ++n) {
89
89
  b[i + n] = node[n];
90
90
  }
91
91
 
92
- return buf || stringify(b);
92
+ return buf || unsafeStringify(b);
93
93
  }
94
94
 
95
95
  export default v1;
@@ -1,4 +1,4 @@
1
1
  import v35 from './v35.js';
2
2
  import md5 from './md5.js';
3
- var v3 = v35('v3', 0x30, md5);
3
+ const v3 = v35('v3', 0x30, md5);
4
4
  export default v3;
@@ -1,22 +1,24 @@
1
- import stringify from './stringify.js';
1
+ import { unsafeStringify } from './stringify.js';
2
2
  import parse from './parse.js';
3
3
 
4
4
  function stringToBytes(str) {
5
5
  str = unescape(encodeURIComponent(str)); // UTF8 escape
6
6
 
7
- var bytes = [];
7
+ const bytes = [];
8
8
 
9
- for (var i = 0; i < str.length; ++i) {
9
+ for (let i = 0; i < str.length; ++i) {
10
10
  bytes.push(str.charCodeAt(i));
11
11
  }
12
12
 
13
13
  return bytes;
14
14
  }
15
15
 
16
- export var DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
17
- export var URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
18
- export default function (name, version, hashfunc) {
16
+ export const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
17
+ export const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
18
+ export default function v35(name, version, hashfunc) {
19
19
  function generateUUID(value, namespace, buf, offset) {
20
+ var _namespace;
21
+
20
22
  if (typeof value === 'string') {
21
23
  value = stringToBytes(value);
22
24
  }
@@ -25,14 +27,14 @@ export default function (name, version, hashfunc) {
25
27
  namespace = parse(namespace);
26
28
  }
27
29
 
28
- if (namespace.length !== 16) {
30
+ if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {
29
31
  throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
30
32
  } // Compute hash of namespace and value, Per 4.3
31
33
  // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
32
34
  // hashfunc([...namespace, ... value])`
33
35
 
34
36
 
35
- var bytes = new Uint8Array(16 + value.length);
37
+ let bytes = new Uint8Array(16 + value.length);
36
38
  bytes.set(namespace);
37
39
  bytes.set(value, namespace.length);
38
40
  bytes = hashfunc(bytes);
@@ -42,14 +44,14 @@ export default function (name, version, hashfunc) {
42
44
  if (buf) {
43
45
  offset = offset || 0;
44
46
 
45
- for (var i = 0; i < 16; ++i) {
47
+ for (let i = 0; i < 16; ++i) {
46
48
  buf[offset + i] = bytes[i];
47
49
  }
48
50
 
49
51
  return buf;
50
52
  }
51
53
 
52
- return stringify(bytes);
54
+ return unsafeStringify(bytes);
53
55
  } // Function#name is not settable on some platforms (#270)
54
56
 
55
57
 
@@ -1,9 +1,14 @@
1
+ import native from './native.js';
1
2
  import rng from './rng.js';
2
- import stringify from './stringify.js';
3
+ import { unsafeStringify } from './stringify.js';
3
4
 
4
5
  function v4(options, buf, offset) {
6
+ if (native.randomUUID && !buf && !options) {
7
+ return native.randomUUID();
8
+ }
9
+
5
10
  options = options || {};
6
- var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
11
+ const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
7
12
 
8
13
  rnds[6] = rnds[6] & 0x0f | 0x40;
9
14
  rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
@@ -11,14 +16,14 @@ function v4(options, buf, offset) {
11
16
  if (buf) {
12
17
  offset = offset || 0;
13
18
 
14
- for (var i = 0; i < 16; ++i) {
19
+ for (let i = 0; i < 16; ++i) {
15
20
  buf[offset + i] = rnds[i];
16
21
  }
17
22
 
18
23
  return buf;
19
24
  }
20
25
 
21
- return stringify(rnds);
26
+ return unsafeStringify(rnds);
22
27
  }
23
28
 
24
29
  export default v4;
@@ -1,4 +1,4 @@
1
1
  import v35 from './v35.js';
2
2
  import sha1 from './sha1.js';
3
- var v5 = v35('v5', 0x50, sha1);
3
+ const v5 = v35('v5', 0x50, sha1);
4
4
  export default v5;
@@ -5,7 +5,7 @@ function version(uuid) {
5
5
  throw TypeError('Invalid UUID');
6
6
  }
7
7
 
8
- return parseInt(uuid.substr(14, 1), 16);
8
+ return parseInt(uuid.slice(14, 15), 16);
9
9
  }
10
10
 
11
11
  export default version;
@@ -0,0 +1,4 @@
1
+ import crypto from 'crypto';
2
+ export default {
3
+ randomUUID: crypto.randomUUID
4
+ };
@@ -7,13 +7,17 @@ import validate from './validate.js';
7
7
  const byteToHex = [];
8
8
 
9
9
  for (let i = 0; i < 256; ++i) {
10
- byteToHex.push((i + 0x100).toString(16).substr(1));
10
+ byteToHex.push((i + 0x100).toString(16).slice(1));
11
11
  }
12
12
 
13
- function stringify(arr, offset = 0) {
13
+ export function unsafeStringify(arr, offset = 0) {
14
14
  // Note: Be careful editing this code! It's been tuned for performance
15
15
  // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
16
- const uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
16
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
17
+ }
18
+
19
+ function stringify(arr, offset = 0) {
20
+ const uuid = unsafeStringify(arr, offset); // Consistency check for valid UUID. If this throws, it's likely due to one
17
21
  // of the following:
18
22
  // - One or more input array values don't map to a hex octet (leading to
19
23
  // "undefined" in the uuid)
@@ -1,5 +1,5 @@
1
1
  import rng from './rng.js';
2
- import stringify from './stringify.js'; // **`v1()` - Generate time-based UUID**
2
+ import { unsafeStringify } from './stringify.js'; // **`v1()` - Generate time-based UUID**
3
3
  //
4
4
  // Inspired by https://github.com/LiosK/UUID.js
5
5
  // and http://docs.python.org/library/uuid.html
@@ -89,7 +89,7 @@ function v1(options, buf, offset) {
89
89
  b[i + n] = node[n];
90
90
  }
91
91
 
92
- return buf || stringify(b);
92
+ return buf || unsafeStringify(b);
93
93
  }
94
94
 
95
95
  export default v1;
@@ -1,4 +1,4 @@
1
- import stringify from './stringify.js';
1
+ import { unsafeStringify } from './stringify.js';
2
2
  import parse from './parse.js';
3
3
 
4
4
  function stringToBytes(str) {
@@ -15,8 +15,10 @@ function stringToBytes(str) {
15
15
 
16
16
  export const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
17
17
  export const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
18
- export default function (name, version, hashfunc) {
18
+ export default function v35(name, version, hashfunc) {
19
19
  function generateUUID(value, namespace, buf, offset) {
20
+ var _namespace;
21
+
20
22
  if (typeof value === 'string') {
21
23
  value = stringToBytes(value);
22
24
  }
@@ -25,7 +27,7 @@ export default function (name, version, hashfunc) {
25
27
  namespace = parse(namespace);
26
28
  }
27
29
 
28
- if (namespace.length !== 16) {
30
+ if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {
29
31
  throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
30
32
  } // Compute hash of namespace and value, Per 4.3
31
33
  // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
@@ -49,7 +51,7 @@ export default function (name, version, hashfunc) {
49
51
  return buf;
50
52
  }
51
53
 
52
- return stringify(bytes);
54
+ return unsafeStringify(bytes);
53
55
  } // Function#name is not settable on some platforms (#270)
54
56
 
55
57
 
@@ -1,7 +1,12 @@
1
+ import native from './native.js';
1
2
  import rng from './rng.js';
2
- import stringify from './stringify.js';
3
+ import { unsafeStringify } from './stringify.js';
3
4
 
4
5
  function v4(options, buf, offset) {
6
+ if (native.randomUUID && !buf && !options) {
7
+ return native.randomUUID();
8
+ }
9
+
5
10
  options = options || {};
6
11
  const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
7
12
 
@@ -18,7 +23,7 @@ function v4(options, buf, offset) {
18
23
  return buf;
19
24
  }
20
25
 
21
- return stringify(rnds);
26
+ return unsafeStringify(rnds);
22
27
  }
23
28
 
24
29
  export default v4;
@@ -5,7 +5,7 @@ function version(uuid) {
5
5
  throw TypeError('Invalid UUID');
6
6
  }
7
7
 
8
- return parseInt(uuid.substr(14, 1), 16);
8
+ return parseInt(uuid.slice(14, 15), 16);
9
9
  }
10
10
 
11
11
  export default version;
package/dist/index.js CHANGED
@@ -3,58 +3,58 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "v1", {
6
+ Object.defineProperty(exports, "NIL", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _v.default;
9
+ return _nil.default;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "v3", {
12
+ Object.defineProperty(exports, "parse", {
13
13
  enumerable: true,
14
14
  get: function () {
15
- return _v2.default;
15
+ return _parse.default;
16
16
  }
17
17
  });
18
- Object.defineProperty(exports, "v4", {
18
+ Object.defineProperty(exports, "stringify", {
19
19
  enumerable: true,
20
20
  get: function () {
21
- return _v3.default;
21
+ return _stringify.default;
22
22
  }
23
23
  });
24
- Object.defineProperty(exports, "v5", {
24
+ Object.defineProperty(exports, "v1", {
25
25
  enumerable: true,
26
26
  get: function () {
27
- return _v4.default;
27
+ return _v.default;
28
28
  }
29
29
  });
30
- Object.defineProperty(exports, "NIL", {
30
+ Object.defineProperty(exports, "v3", {
31
31
  enumerable: true,
32
32
  get: function () {
33
- return _nil.default;
33
+ return _v2.default;
34
34
  }
35
35
  });
36
- Object.defineProperty(exports, "version", {
36
+ Object.defineProperty(exports, "v4", {
37
37
  enumerable: true,
38
38
  get: function () {
39
- return _version.default;
39
+ return _v3.default;
40
40
  }
41
41
  });
42
- Object.defineProperty(exports, "validate", {
42
+ Object.defineProperty(exports, "v5", {
43
43
  enumerable: true,
44
44
  get: function () {
45
- return _validate.default;
45
+ return _v4.default;
46
46
  }
47
47
  });
48
- Object.defineProperty(exports, "stringify", {
48
+ Object.defineProperty(exports, "validate", {
49
49
  enumerable: true,
50
50
  get: function () {
51
- return _stringify.default;
51
+ return _validate.default;
52
52
  }
53
53
  });
54
- Object.defineProperty(exports, "parse", {
54
+ Object.defineProperty(exports, "version", {
55
55
  enumerable: true,
56
56
  get: function () {
57
- return _parse.default;
57
+ return _version.default;
58
58
  }
59
59
  });
60
60
 
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
8
+ var _default = {
9
+ randomUUID
10
+ };
11
+ exports.default = _default;
package/dist/native.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _crypto = _interopRequireDefault(require("crypto"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ var _default = {
13
+ randomUUID: _crypto.default.randomUUID
14
+ };
15
+ exports.default = _default;
@@ -13,9 +13,8 @@ const rnds8 = new Uint8Array(16);
13
13
  function rng() {
14
14
  // lazy load so that environments that need to polyfill have a chance to do so
15
15
  if (!getRandomValues) {
16
- // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
17
- // find the complete implementation of crypto (msCrypto) on IE11.
18
- getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
16
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
17
+ getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
19
18
 
20
19
  if (!getRandomValues) {
21
20
  throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
package/dist/stringify.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ exports.unsafeStringify = unsafeStringify;
7
8
 
8
9
  var _validate = _interopRequireDefault(require("./validate.js"));
9
10
 
@@ -16,13 +17,17 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
16
17
  const byteToHex = [];
17
18
 
18
19
  for (let i = 0; i < 256; ++i) {
19
- byteToHex.push((i + 0x100).toString(16).substr(1));
20
+ byteToHex.push((i + 0x100).toString(16).slice(1));
20
21
  }
21
22
 
22
- function stringify(arr, offset = 0) {
23
+ function unsafeStringify(arr, offset = 0) {
23
24
  // Note: Be careful editing this code! It's been tuned for performance
24
25
  // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
25
- const uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
26
+ return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
27
+ }
28
+
29
+ function stringify(arr, offset = 0) {
30
+ const uuid = unsafeStringify(arr, offset); // Consistency check for valid UUID. If this throws, it's likely due to one
26
31
  // of the following:
27
32
  // - One or more input array values don't map to a hex octet (leading to
28
33
  // "undefined" in the uuid)
package/dist/v1.js CHANGED
@@ -7,7 +7,7 @@ exports.default = void 0;
7
7
 
8
8
  var _rng = _interopRequireDefault(require("./rng.js"));
9
9
 
10
- var _stringify = _interopRequireDefault(require("./stringify.js"));
10
+ var _stringify = require("./stringify.js");
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
@@ -100,7 +100,7 @@ function v1(options, buf, offset) {
100
100
  b[i + n] = node[n];
101
101
  }
102
102
 
103
- return buf || (0, _stringify.default)(b);
103
+ return buf || (0, _stringify.unsafeStringify)(b);
104
104
  }
105
105
 
106
106
  var _default = v1;
package/dist/v35.js CHANGED
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = _default;
7
6
  exports.URL = exports.DNS = void 0;
7
+ exports.default = v35;
8
8
 
9
- var _stringify = _interopRequireDefault(require("./stringify.js"));
9
+ var _stringify = require("./stringify.js");
10
10
 
11
11
  var _parse = _interopRequireDefault(require("./parse.js"));
12
12
 
@@ -29,8 +29,10 @@ exports.DNS = DNS;
29
29
  const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
30
30
  exports.URL = URL;
31
31
 
32
- function _default(name, version, hashfunc) {
32
+ function v35(name, version, hashfunc) {
33
33
  function generateUUID(value, namespace, buf, offset) {
34
+ var _namespace;
35
+
34
36
  if (typeof value === 'string') {
35
37
  value = stringToBytes(value);
36
38
  }
@@ -39,7 +41,7 @@ function _default(name, version, hashfunc) {
39
41
  namespace = (0, _parse.default)(namespace);
40
42
  }
41
43
 
42
- if (namespace.length !== 16) {
44
+ if (((_namespace = namespace) === null || _namespace === void 0 ? void 0 : _namespace.length) !== 16) {
43
45
  throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
44
46
  } // Compute hash of namespace and value, Per 4.3
45
47
  // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
@@ -63,7 +65,7 @@ function _default(name, version, hashfunc) {
63
65
  return buf;
64
66
  }
65
67
 
66
- return (0, _stringify.default)(bytes);
68
+ return (0, _stringify.unsafeStringify)(bytes);
67
69
  } // Function#name is not settable on some platforms (#270)
68
70
 
69
71
 
package/dist/v4.js CHANGED
@@ -5,13 +5,19 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _native = _interopRequireDefault(require("./native.js"));
9
+
8
10
  var _rng = _interopRequireDefault(require("./rng.js"));
9
11
 
10
- var _stringify = _interopRequireDefault(require("./stringify.js"));
12
+ var _stringify = require("./stringify.js");
11
13
 
12
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
15
 
14
16
  function v4(options, buf, offset) {
17
+ if (_native.default.randomUUID && !buf && !options) {
18
+ return _native.default.randomUUID();
19
+ }
20
+
15
21
  options = options || {};
16
22
 
17
23
  const rnds = options.random || (options.rng || _rng.default)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
@@ -30,7 +36,7 @@ function v4(options, buf, offset) {
30
36
  return buf;
31
37
  }
32
38
 
33
- return (0, _stringify.default)(rnds);
39
+ return (0, _stringify.unsafeStringify)(rnds);
34
40
  }
35
41
 
36
42
  var _default = v4;
package/dist/version.js CHANGED
@@ -14,7 +14,7 @@ function version(uuid) {
14
14
  throw TypeError('Invalid UUID');
15
15
  }
16
16
 
17
- return parseInt(uuid.substr(14, 1), 16);
17
+ return parseInt(uuid.slice(14, 15), 16);
18
18
  }
19
19
 
20
20
  var _default = version;