uuid 8.1.0 → 8.3.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 (52) hide show
  1. package/CHANGELOG.md +23 -15
  2. package/CONTRIBUTING.md +2 -4
  3. package/LICENSE.md +3 -15
  4. package/README.md +222 -200
  5. package/dist/esm-browser/index.js +6 -1
  6. package/dist/esm-browser/nil.js +1 -0
  7. package/dist/esm-browser/parse.js +35 -0
  8. package/dist/esm-browser/regex.js +1 -0
  9. package/dist/esm-browser/sha1.js +3 -0
  10. package/dist/esm-browser/stringify.js +30 -0
  11. package/dist/esm-browser/v1.js +3 -3
  12. package/dist/esm-browser/v35.js +23 -22
  13. package/dist/esm-browser/v4.js +4 -9
  14. package/dist/esm-browser/validate.js +7 -0
  15. package/dist/esm-browser/version.js +11 -0
  16. package/dist/esm-node/index.js +6 -1
  17. package/dist/esm-node/nil.js +1 -0
  18. package/dist/esm-node/parse.js +35 -0
  19. package/dist/esm-node/regex.js +1 -0
  20. package/dist/esm-node/stringify.js +29 -0
  21. package/dist/esm-node/v1.js +3 -3
  22. package/dist/esm-node/v35.js +23 -22
  23. package/dist/esm-node/v4.js +4 -9
  24. package/dist/esm-node/validate.js +7 -0
  25. package/dist/esm-node/version.js +11 -0
  26. package/dist/index.js +40 -0
  27. package/dist/nil.js +8 -0
  28. package/dist/parse.js +45 -0
  29. package/dist/regex.js +8 -0
  30. package/dist/sha1-browser.js +3 -0
  31. package/dist/stringify.js +39 -0
  32. package/dist/umd/uuid.min.js +1 -1
  33. package/dist/umd/uuidNIL.min.js +1 -0
  34. package/dist/umd/uuidParse.min.js +1 -0
  35. package/dist/umd/uuidStringify.min.js +1 -0
  36. package/dist/umd/uuidValidate.min.js +1 -0
  37. package/dist/umd/uuidVersion.min.js +1 -0
  38. package/dist/umd/uuidv1.min.js +1 -1
  39. package/dist/umd/uuidv3.min.js +1 -1
  40. package/dist/umd/uuidv4.min.js +1 -1
  41. package/dist/umd/uuidv5.min.js +1 -1
  42. package/dist/uuid-bin.js +18 -4
  43. package/dist/v1.js +3 -3
  44. package/dist/v35.js +24 -22
  45. package/dist/v4.js +4 -9
  46. package/dist/validate.js +17 -0
  47. package/dist/version.js +21 -0
  48. package/package.json +34 -29
  49. package/wrapper.mjs +5 -0
  50. package/dist/bytesToUuid.js +0 -27
  51. package/dist/esm-browser/bytesToUuid.js +0 -19
  52. package/dist/esm-node/bytesToUuid.js +0 -19
@@ -0,0 +1,30 @@
1
+ import validate from './validate.js';
2
+ /**
3
+ * Convert array of 16 byte values to UUID string format of the form:
4
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
5
+ */
6
+
7
+ var byteToHex = [];
8
+
9
+ for (var i = 0; i < 256; ++i) {
10
+ byteToHex.push((i + 0x100).toString(16).substr(1));
11
+ }
12
+
13
+ function stringify(arr) {
14
+ var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
15
+ // Note: Be careful editing this code! It's been tuned for performance
16
+ // 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
18
+ // of the following:
19
+ // - One or more input array values don't map to a hex octet (leading to
20
+ // "undefined" in the uuid)
21
+ // - Invalid input values for the RFC `version` or `variant` fields
22
+
23
+ if (!validate(uuid)) {
24
+ throw TypeError('Stringified UUID is invalid');
25
+ }
26
+
27
+ return uuid;
28
+ }
29
+
30
+ export default stringify;
@@ -1,5 +1,5 @@
1
1
  import rng from './rng.js';
2
- import bytesToUuid from './bytesToUuid.js'; // **`v1()` - Generate time-based UUID**
2
+ import stringify 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
@@ -14,7 +14,7 @@ var _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
14
14
 
15
15
  function v1(options, buf, offset) {
16
16
  var i = buf && offset || 0;
17
- var b = buf || [];
17
+ var b = buf || new Array(16);
18
18
  options = options || {};
19
19
  var node = options.node || _nodeId;
20
20
  var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
@@ -89,7 +89,7 @@ function v1(options, buf, offset) {
89
89
  b[i + n] = node[n];
90
90
  }
91
91
 
92
- return buf || bytesToUuid(b);
92
+ return buf || stringify(b);
93
93
  }
94
94
 
95
95
  export default v1;
@@ -1,13 +1,5 @@
1
- import bytesToUuid from './bytesToUuid.js';
2
-
3
- function uuidToBytes(uuid) {
4
- // Note: We assume we're being passed a valid uuid string
5
- var bytes = [];
6
- uuid.replace(/[a-fA-F0-9]{2}/g, function (hex) {
7
- bytes.push(parseInt(hex, 16));
8
- });
9
- return bytes;
10
- }
1
+ import stringify from './stringify.js';
2
+ import parse from './parse.js';
11
3
 
12
4
  function stringToBytes(str) {
13
5
  str = unescape(encodeURIComponent(str)); // UTF8 escape
@@ -25,30 +17,39 @@ export var DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
25
17
  export var URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
26
18
  export default function (name, version, hashfunc) {
27
19
  function generateUUID(value, namespace, buf, offset) {
28
- var off = buf && offset || 0;
29
- if (typeof value === 'string') value = stringToBytes(value);
30
- if (typeof namespace === 'string') namespace = uuidToBytes(namespace);
20
+ if (typeof value === 'string') {
21
+ value = stringToBytes(value);
22
+ }
31
23
 
32
- if (!Array.isArray(value)) {
33
- throw TypeError('value must be an array of bytes');
24
+ if (typeof namespace === 'string') {
25
+ namespace = parse(namespace);
34
26
  }
35
27
 
36
- if (!Array.isArray(namespace) || namespace.length !== 16) {
37
- throw TypeError('namespace must be uuid string or an Array of 16 byte values');
38
- } // Per 4.3
28
+ if (namespace.length !== 16) {
29
+ throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
30
+ } // Compute hash of namespace and value, Per 4.3
31
+ // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
32
+ // hashfunc([...namespace, ... value])`
39
33
 
40
34
 
41
- var bytes = hashfunc(namespace.concat(value));
35
+ var bytes = new Uint8Array(16 + value.length);
36
+ bytes.set(namespace);
37
+ bytes.set(value, namespace.length);
38
+ bytes = hashfunc(bytes);
42
39
  bytes[6] = bytes[6] & 0x0f | version;
43
40
  bytes[8] = bytes[8] & 0x3f | 0x80;
44
41
 
45
42
  if (buf) {
46
- for (var idx = 0; idx < 16; ++idx) {
47
- buf[off + idx] = bytes[idx];
43
+ offset = offset || 0;
44
+
45
+ for (var i = 0; i < 16; ++i) {
46
+ buf[offset + i] = bytes[i];
48
47
  }
48
+
49
+ return buf;
49
50
  }
50
51
 
51
- return buf || bytesToUuid(bytes);
52
+ return stringify(bytes);
52
53
  } // Function#name is not settable on some platforms (#270)
53
54
 
54
55
 
@@ -1,12 +1,7 @@
1
1
  import rng from './rng.js';
2
- import bytesToUuid from './bytesToUuid.js';
2
+ import stringify from './stringify.js';
3
3
 
4
4
  function v4(options, buf, offset) {
5
- if (typeof options === 'string') {
6
- buf = options === 'binary' ? new Uint8Array(16) : null;
7
- options = null;
8
- }
9
-
10
5
  options = options || {};
11
6
  var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
12
7
 
@@ -14,16 +9,16 @@ function v4(options, buf, offset) {
14
9
  rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
15
10
 
16
11
  if (buf) {
17
- var start = offset || 0;
12
+ offset = offset || 0;
18
13
 
19
14
  for (var i = 0; i < 16; ++i) {
20
- buf[start + i] = rnds[i];
15
+ buf[offset + i] = rnds[i];
21
16
  }
22
17
 
23
18
  return buf;
24
19
  }
25
20
 
26
- return bytesToUuid(rnds);
21
+ return stringify(rnds);
27
22
  }
28
23
 
29
24
  export default v4;
@@ -0,0 +1,7 @@
1
+ import REGEX from './regex.js';
2
+
3
+ function validate(uuid) {
4
+ return typeof uuid === 'string' && REGEX.test(uuid);
5
+ }
6
+
7
+ export default validate;
@@ -0,0 +1,11 @@
1
+ import validate from './validate.js';
2
+
3
+ function version(uuid) {
4
+ if (!validate(uuid)) {
5
+ throw TypeError('Invalid UUID');
6
+ }
7
+
8
+ return parseInt(uuid.substr(14, 1), 16);
9
+ }
10
+
11
+ export default version;
@@ -1,4 +1,9 @@
1
1
  export { default as v1 } from './v1.js';
2
2
  export { default as v3 } from './v3.js';
3
3
  export { default as v4 } from './v4.js';
4
- export { default as v5 } from './v5.js';
4
+ export { default as v5 } from './v5.js';
5
+ export { default as NIL } from './nil.js';
6
+ export { default as version } from './version.js';
7
+ export { default as validate } from './validate.js';
8
+ export { default as stringify } from './stringify.js';
9
+ export { default as parse } from './parse.js';
@@ -0,0 +1 @@
1
+ export default '00000000-0000-0000-0000-000000000000';
@@ -0,0 +1,35 @@
1
+ import validate from './validate.js';
2
+
3
+ function parse(uuid) {
4
+ if (!validate(uuid)) {
5
+ throw TypeError('Invalid UUID');
6
+ }
7
+
8
+ let v;
9
+ const arr = new Uint8Array(16); // Parse ########-....-....-....-............
10
+
11
+ arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
12
+ arr[1] = v >>> 16 & 0xff;
13
+ arr[2] = v >>> 8 & 0xff;
14
+ arr[3] = v & 0xff; // Parse ........-####-....-....-............
15
+
16
+ arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
17
+ arr[5] = v & 0xff; // Parse ........-....-####-....-............
18
+
19
+ arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
20
+ arr[7] = v & 0xff; // Parse ........-....-....-####-............
21
+
22
+ arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
23
+ arr[9] = v & 0xff; // Parse ........-....-....-....-############
24
+ // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
25
+
26
+ arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
27
+ arr[11] = v / 0x100000000 & 0xff;
28
+ arr[12] = v >>> 24 & 0xff;
29
+ arr[13] = v >>> 16 & 0xff;
30
+ arr[14] = v >>> 8 & 0xff;
31
+ arr[15] = v & 0xff;
32
+ return arr;
33
+ }
34
+
35
+ export default parse;
@@ -0,0 +1 @@
1
+ export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
@@ -0,0 +1,29 @@
1
+ import validate from './validate.js';
2
+ /**
3
+ * Convert array of 16 byte values to UUID string format of the form:
4
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
5
+ */
6
+
7
+ const byteToHex = [];
8
+
9
+ for (let i = 0; i < 256; ++i) {
10
+ byteToHex.push((i + 0x100).toString(16).substr(1));
11
+ }
12
+
13
+ function stringify(arr, offset = 0) {
14
+ // Note: Be careful editing this code! It's been tuned for performance
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
17
+ // of the following:
18
+ // - One or more input array values don't map to a hex octet (leading to
19
+ // "undefined" in the uuid)
20
+ // - Invalid input values for the RFC `version` or `variant` fields
21
+
22
+ if (!validate(uuid)) {
23
+ throw TypeError('Stringified UUID is invalid');
24
+ }
25
+
26
+ return uuid;
27
+ }
28
+
29
+ export default stringify;
@@ -1,5 +1,5 @@
1
1
  import rng from './rng.js';
2
- import bytesToUuid from './bytesToUuid.js'; // **`v1()` - Generate time-based UUID**
2
+ import stringify 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
@@ -14,7 +14,7 @@ let _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
14
14
 
15
15
  function v1(options, buf, offset) {
16
16
  let i = buf && offset || 0;
17
- const b = buf || [];
17
+ const b = buf || new Array(16);
18
18
  options = options || {};
19
19
  let node = options.node || _nodeId;
20
20
  let clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
@@ -89,7 +89,7 @@ function v1(options, buf, offset) {
89
89
  b[i + n] = node[n];
90
90
  }
91
91
 
92
- return buf || bytesToUuid(b);
92
+ return buf || stringify(b);
93
93
  }
94
94
 
95
95
  export default v1;
@@ -1,13 +1,5 @@
1
- import bytesToUuid from './bytesToUuid.js';
2
-
3
- function uuidToBytes(uuid) {
4
- // Note: We assume we're being passed a valid uuid string
5
- const bytes = [];
6
- uuid.replace(/[a-fA-F0-9]{2}/g, function (hex) {
7
- bytes.push(parseInt(hex, 16));
8
- });
9
- return bytes;
10
- }
1
+ import stringify from './stringify.js';
2
+ import parse from './parse.js';
11
3
 
12
4
  function stringToBytes(str) {
13
5
  str = unescape(encodeURIComponent(str)); // UTF8 escape
@@ -25,30 +17,39 @@ export const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
25
17
  export const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
26
18
  export default function (name, version, hashfunc) {
27
19
  function generateUUID(value, namespace, buf, offset) {
28
- const off = buf && offset || 0;
29
- if (typeof value === 'string') value = stringToBytes(value);
30
- if (typeof namespace === 'string') namespace = uuidToBytes(namespace);
20
+ if (typeof value === 'string') {
21
+ value = stringToBytes(value);
22
+ }
31
23
 
32
- if (!Array.isArray(value)) {
33
- throw TypeError('value must be an array of bytes');
24
+ if (typeof namespace === 'string') {
25
+ namespace = parse(namespace);
34
26
  }
35
27
 
36
- if (!Array.isArray(namespace) || namespace.length !== 16) {
37
- throw TypeError('namespace must be uuid string or an Array of 16 byte values');
38
- } // Per 4.3
28
+ if (namespace.length !== 16) {
29
+ throw TypeError('Namespace must be array-like (16 iterable integer values, 0-255)');
30
+ } // Compute hash of namespace and value, Per 4.3
31
+ // Future: Use spread syntax when supported on all platforms, e.g. `bytes =
32
+ // hashfunc([...namespace, ... value])`
39
33
 
40
34
 
41
- const bytes = hashfunc(namespace.concat(value));
35
+ let bytes = new Uint8Array(16 + value.length);
36
+ bytes.set(namespace);
37
+ bytes.set(value, namespace.length);
38
+ bytes = hashfunc(bytes);
42
39
  bytes[6] = bytes[6] & 0x0f | version;
43
40
  bytes[8] = bytes[8] & 0x3f | 0x80;
44
41
 
45
42
  if (buf) {
46
- for (let idx = 0; idx < 16; ++idx) {
47
- buf[off + idx] = bytes[idx];
43
+ offset = offset || 0;
44
+
45
+ for (let i = 0; i < 16; ++i) {
46
+ buf[offset + i] = bytes[i];
48
47
  }
48
+
49
+ return buf;
49
50
  }
50
51
 
51
- return buf || bytesToUuid(bytes);
52
+ return stringify(bytes);
52
53
  } // Function#name is not settable on some platforms (#270)
53
54
 
54
55
 
@@ -1,12 +1,7 @@
1
1
  import rng from './rng.js';
2
- import bytesToUuid from './bytesToUuid.js';
2
+ import stringify from './stringify.js';
3
3
 
4
4
  function v4(options, buf, offset) {
5
- if (typeof options === 'string') {
6
- buf = options === 'binary' ? new Uint8Array(16) : null;
7
- options = null;
8
- }
9
-
10
5
  options = options || {};
11
6
  const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
12
7
 
@@ -14,16 +9,16 @@ function v4(options, buf, offset) {
14
9
  rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
15
10
 
16
11
  if (buf) {
17
- const start = offset || 0;
12
+ offset = offset || 0;
18
13
 
19
14
  for (let i = 0; i < 16; ++i) {
20
- buf[start + i] = rnds[i];
15
+ buf[offset + i] = rnds[i];
21
16
  }
22
17
 
23
18
  return buf;
24
19
  }
25
20
 
26
- return bytesToUuid(rnds);
21
+ return stringify(rnds);
27
22
  }
28
23
 
29
24
  export default v4;
@@ -0,0 +1,7 @@
1
+ import REGEX from './regex.js';
2
+
3
+ function validate(uuid) {
4
+ return typeof uuid === 'string' && REGEX.test(uuid);
5
+ }
6
+
7
+ export default validate;
@@ -0,0 +1,11 @@
1
+ import validate from './validate.js';
2
+
3
+ function version(uuid) {
4
+ if (!validate(uuid)) {
5
+ throw TypeError('Invalid UUID');
6
+ }
7
+
8
+ return parseInt(uuid.substr(14, 1), 16);
9
+ }
10
+
11
+ export default version;
package/dist/index.js CHANGED
@@ -27,6 +27,36 @@ Object.defineProperty(exports, "v5", {
27
27
  return _v4.default;
28
28
  }
29
29
  });
30
+ Object.defineProperty(exports, "NIL", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _nil.default;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "version", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _version.default;
40
+ }
41
+ });
42
+ Object.defineProperty(exports, "validate", {
43
+ enumerable: true,
44
+ get: function () {
45
+ return _validate.default;
46
+ }
47
+ });
48
+ Object.defineProperty(exports, "stringify", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _stringify.default;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, "parse", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _parse.default;
58
+ }
59
+ });
30
60
 
31
61
  var _v = _interopRequireDefault(require("./v1.js"));
32
62
 
@@ -36,4 +66,14 @@ var _v3 = _interopRequireDefault(require("./v4.js"));
36
66
 
37
67
  var _v4 = _interopRequireDefault(require("./v5.js"));
38
68
 
69
+ var _nil = _interopRequireDefault(require("./nil.js"));
70
+
71
+ var _version = _interopRequireDefault(require("./version.js"));
72
+
73
+ var _validate = _interopRequireDefault(require("./validate.js"));
74
+
75
+ var _stringify = _interopRequireDefault(require("./stringify.js"));
76
+
77
+ var _parse = _interopRequireDefault(require("./parse.js"));
78
+
39
79
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
package/dist/nil.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = '00000000-0000-0000-0000-000000000000';
8
+ exports.default = _default;
package/dist/parse.js ADDED
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _validate = _interopRequireDefault(require("./validate.js"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ function parse(uuid) {
13
+ if (!(0, _validate.default)(uuid)) {
14
+ throw TypeError('Invalid UUID');
15
+ }
16
+
17
+ let v;
18
+ const arr = new Uint8Array(16); // Parse ########-....-....-....-............
19
+
20
+ arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
21
+ arr[1] = v >>> 16 & 0xff;
22
+ arr[2] = v >>> 8 & 0xff;
23
+ arr[3] = v & 0xff; // Parse ........-####-....-....-............
24
+
25
+ arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
26
+ arr[5] = v & 0xff; // Parse ........-....-####-....-............
27
+
28
+ arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
29
+ arr[7] = v & 0xff; // Parse ........-....-....-####-............
30
+
31
+ arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
32
+ arr[9] = v & 0xff; // Parse ........-....-....-....-############
33
+ // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
34
+
35
+ arr[10] = (v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000 & 0xff;
36
+ arr[11] = v / 0x100000000 & 0xff;
37
+ arr[12] = v >>> 24 & 0xff;
38
+ arr[13] = v >>> 16 & 0xff;
39
+ arr[14] = v >>> 8 & 0xff;
40
+ arr[15] = v & 0xff;
41
+ return arr;
42
+ }
43
+
44
+ var _default = parse;
45
+ exports.default = _default;
package/dist/regex.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
8
+ exports.default = _default;
@@ -39,6 +39,9 @@ function sha1(bytes) {
39
39
  for (let i = 0; i < msg.length; ++i) {
40
40
  bytes.push(msg.charCodeAt(i));
41
41
  }
42
+ } else if (!Array.isArray(bytes)) {
43
+ // Convert Array-like to Array
44
+ bytes = Array.prototype.slice.call(bytes);
42
45
  }
43
46
 
44
47
  bytes.push(0x80);
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _validate = _interopRequireDefault(require("./validate.js"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ /**
13
+ * Convert array of 16 byte values to UUID string format of the form:
14
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
15
+ */
16
+ const byteToHex = [];
17
+
18
+ for (let i = 0; i < 256; ++i) {
19
+ byteToHex.push((i + 0x100).toString(16).substr(1));
20
+ }
21
+
22
+ function stringify(arr, offset = 0) {
23
+ // Note: Be careful editing this code! It's been tuned for performance
24
+ // 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
+ // of the following:
27
+ // - One or more input array values don't map to a hex octet (leading to
28
+ // "undefined" in the uuid)
29
+ // - Invalid input values for the RFC `version` or `variant` fields
30
+
31
+ if (!(0, _validate.default)(uuid)) {
32
+ throw TypeError('Stringified UUID is invalid');
33
+ }
34
+
35
+ return uuid;
36
+ }
37
+
38
+ var _default = stringify;
39
+ exports.default = _default;