uuid 11.0.3 → 11.0.5

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 (120) hide show
  1. package/README.md +29 -16
  2. package/dist/cjs/md5.d.ts +2 -0
  3. package/dist/cjs/native.d.ts +1 -0
  4. package/dist/cjs/rng.js +1 -1
  5. package/dist/cjs/sha1.d.ts +2 -0
  6. package/dist/cjs/stringify.js +2 -1
  7. package/dist/cjs/v1.js +10 -1
  8. package/dist/cjs/v1ToV6.js +1 -1
  9. package/dist/cjs/v35.js +3 -3
  10. package/dist/cjs/v4.js +7 -1
  11. package/dist/cjs/v6ToV1.js +1 -1
  12. package/dist/cjs/v7.js +10 -1
  13. package/dist/cjs-browser/rng.js +1 -1
  14. package/dist/cjs-browser/stringify.js +2 -1
  15. package/dist/cjs-browser/v1.js +10 -1
  16. package/dist/cjs-browser/v1ToV6.js +1 -1
  17. package/dist/cjs-browser/v35.js +3 -3
  18. package/dist/cjs-browser/v4.js +7 -1
  19. package/dist/cjs-browser/v6ToV1.js +1 -1
  20. package/dist/cjs-browser/v7.js +10 -1
  21. package/dist/esm/md5.d.ts +2 -0
  22. package/dist/esm/native.d.ts +1 -0
  23. package/dist/esm/sha1.d.ts +2 -0
  24. package/dist/esm/v1.js +8 -0
  25. package/dist/esm/v4.js +7 -1
  26. package/dist/esm/v7.js +8 -0
  27. package/dist/esm-browser/v1.js +8 -0
  28. package/dist/esm-browser/v4.js +7 -1
  29. package/dist/esm-browser/v7.js +8 -0
  30. package/package.json +26 -28
  31. package/CHANGELOG.md +0 -335
  32. package/CONTRIBUTING.md +0 -18
  33. package/dist/cjs/test/parse.test.d.ts +0 -1
  34. package/dist/cjs/test/parse.test.js +0 -50
  35. package/dist/cjs/test/rng.test.d.ts +0 -1
  36. package/dist/cjs/test/rng.test.js +0 -14
  37. package/dist/cjs/test/stringify.test.d.ts +0 -1
  38. package/dist/cjs/test/stringify.test.js +0 -23
  39. package/dist/cjs/test/test_constants.d.ts +0 -33
  40. package/dist/cjs/test/test_constants.js +0 -91
  41. package/dist/cjs/test/v1.test.d.ts +0 -1
  42. package/dist/cjs/test/v1.test.js +0 -127
  43. package/dist/cjs/test/v35.test.d.ts +0 -1
  44. package/dist/cjs/test/v35.test.js +0 -143
  45. package/dist/cjs/test/v4.test.d.ts +0 -1
  46. package/dist/cjs/test/v4.test.js +0 -60
  47. package/dist/cjs/test/v6.test.d.ts +0 -1
  48. package/dist/cjs/test/v6.test.js +0 -56
  49. package/dist/cjs/test/v7.test.d.ts +0 -1
  50. package/dist/cjs/test/v7.test.js +0 -194
  51. package/dist/cjs/test/validate.test.d.ts +0 -1
  52. package/dist/cjs/test/validate.test.js +0 -13
  53. package/dist/cjs/test/version.test.d.ts +0 -1
  54. package/dist/cjs/test/version.test.js +0 -20
  55. package/dist/cjs-browser/test/parse.test.d.ts +0 -1
  56. package/dist/cjs-browser/test/parse.test.js +0 -50
  57. package/dist/cjs-browser/test/rng.test.d.ts +0 -1
  58. package/dist/cjs-browser/test/rng.test.js +0 -14
  59. package/dist/cjs-browser/test/stringify.test.d.ts +0 -1
  60. package/dist/cjs-browser/test/stringify.test.js +0 -23
  61. package/dist/cjs-browser/test/test_constants.d.ts +0 -33
  62. package/dist/cjs-browser/test/test_constants.js +0 -91
  63. package/dist/cjs-browser/test/v1.test.d.ts +0 -1
  64. package/dist/cjs-browser/test/v1.test.js +0 -127
  65. package/dist/cjs-browser/test/v35.test.d.ts +0 -1
  66. package/dist/cjs-browser/test/v35.test.js +0 -143
  67. package/dist/cjs-browser/test/v4.test.d.ts +0 -1
  68. package/dist/cjs-browser/test/v4.test.js +0 -60
  69. package/dist/cjs-browser/test/v6.test.d.ts +0 -1
  70. package/dist/cjs-browser/test/v6.test.js +0 -56
  71. package/dist/cjs-browser/test/v7.test.d.ts +0 -1
  72. package/dist/cjs-browser/test/v7.test.js +0 -194
  73. package/dist/cjs-browser/test/validate.test.d.ts +0 -1
  74. package/dist/cjs-browser/test/validate.test.js +0 -13
  75. package/dist/cjs-browser/test/version.test.d.ts +0 -1
  76. package/dist/cjs-browser/test/version.test.js +0 -20
  77. package/dist/esm/test/parse.test.d.ts +0 -1
  78. package/dist/esm/test/parse.test.js +0 -48
  79. package/dist/esm/test/rng.test.d.ts +0 -1
  80. package/dist/esm/test/rng.test.js +0 -12
  81. package/dist/esm/test/stringify.test.d.ts +0 -1
  82. package/dist/esm/test/stringify.test.js +0 -21
  83. package/dist/esm/test/test_constants.d.ts +0 -33
  84. package/dist/esm/test/test_constants.js +0 -88
  85. package/dist/esm/test/v1.test.d.ts +0 -1
  86. package/dist/esm/test/v1.test.js +0 -125
  87. package/dist/esm/test/v35.test.d.ts +0 -1
  88. package/dist/esm/test/v35.test.js +0 -141
  89. package/dist/esm/test/v4.test.d.ts +0 -1
  90. package/dist/esm/test/v4.test.js +0 -58
  91. package/dist/esm/test/v6.test.d.ts +0 -1
  92. package/dist/esm/test/v6.test.js +0 -54
  93. package/dist/esm/test/v7.test.d.ts +0 -1
  94. package/dist/esm/test/v7.test.js +0 -192
  95. package/dist/esm/test/validate.test.d.ts +0 -1
  96. package/dist/esm/test/validate.test.js +0 -11
  97. package/dist/esm/test/version.test.d.ts +0 -1
  98. package/dist/esm/test/version.test.js +0 -18
  99. package/dist/esm-browser/test/parse.test.d.ts +0 -1
  100. package/dist/esm-browser/test/parse.test.js +0 -48
  101. package/dist/esm-browser/test/rng.test.d.ts +0 -1
  102. package/dist/esm-browser/test/rng.test.js +0 -12
  103. package/dist/esm-browser/test/stringify.test.d.ts +0 -1
  104. package/dist/esm-browser/test/stringify.test.js +0 -21
  105. package/dist/esm-browser/test/test_constants.d.ts +0 -33
  106. package/dist/esm-browser/test/test_constants.js +0 -88
  107. package/dist/esm-browser/test/v1.test.d.ts +0 -1
  108. package/dist/esm-browser/test/v1.test.js +0 -125
  109. package/dist/esm-browser/test/v35.test.d.ts +0 -1
  110. package/dist/esm-browser/test/v35.test.js +0 -141
  111. package/dist/esm-browser/test/v4.test.d.ts +0 -1
  112. package/dist/esm-browser/test/v4.test.js +0 -58
  113. package/dist/esm-browser/test/v6.test.d.ts +0 -1
  114. package/dist/esm-browser/test/v6.test.js +0 -54
  115. package/dist/esm-browser/test/v7.test.d.ts +0 -1
  116. package/dist/esm-browser/test/v7.test.js +0 -192
  117. package/dist/esm-browser/test/validate.test.d.ts +0 -1
  118. package/dist/esm-browser/test/validate.test.js +0 -11
  119. package/dist/esm-browser/test/version.test.d.ts +0 -1
  120. package/dist/esm-browser/test/version.test.js +0 -18
@@ -1,143 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const node_test_1 = require("node:test");
5
- const md5_js_1 = require("../md5.js");
6
- const sha1_js_1 = require("../sha1.js");
7
- const v3_js_1 = require("../v3.js");
8
- const v35_js_1 = require("../v35.js");
9
- const v5_js_1 = require("../v5.js");
10
- (0, node_test_1.describe)('v35', () => {
11
- const HASH_SAMPLES = [
12
- {
13
- input: (0, v35_js_1.stringToBytes)(''),
14
- sha1: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
15
- md5: 'd41d8cd98f00b204e9800998ecf8427e',
16
- },
17
- {
18
- input: (0, v35_js_1.stringToBytes)('\t\b\f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u00A1\u00A2\u00A3\u00A4\u00A5\u00A6\u00A7\u00A8\u00A9\u00AA\u00AB\u00AC\u00AE\u00AF\u00B0\u00B1\u00B2\u00B3\u00B4\u00B5\u00B6\u00B7\u00B8\u00B9\u00BA\u00BB\u00BC\u00BD\u00BE\u00BF\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5\u00C6\u00C7\u00C8\u00C9\u00CA\u00CB\u00CC\u00CD\u00CE\u00CF\u00D0\u00D1\u00D2\u00D3\u00D4\u00D5\u00D6\u00D7\u00D8\u00D9\u00DA\u00DB\u00DC\u00DD\u00DE\u00DF\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u00E6\u00E7\u00E8\u00E9\u00EA\u00EB\u00EC\u00ED\u00EE\u00EF\u00F0\u00F1\u00F2\u00F3\u00F4\u00F5\u00F6\u00F7\u00F8\u00F9\u00FA\u00FB\u00FC\u00FD\u00FE\u00FF'),
19
- sha1: 'ca4a426a3d536f14cfd79011e79e10d64de950a0',
20
- md5: 'e8098ec21950f841731d28749129d3ee',
21
- },
22
- {
23
- input: (0, v35_js_1.stringToBytes)('\u00A5\u0104\u018F\u0256\u02B1o\u0315\u038E\u0409\u0500\u0531\u05E1\u05B6\u0920\u0903\u09A4\u0983\u0A20\u0A02\u0AA0\u0A83\u0B06\u0C05\u0C03\u1401\u16A0'),
24
- sha1: 'f2753ebc390e5f637e333c2a4179644a93ae9f65',
25
- md5: '231b309e277b6be8bb3d6c688b7f098b',
26
- },
27
- ];
28
- function hashToHex(hash) {
29
- const chars = new Array(hash.length);
30
- for (let i = 0; i < hash.length; i++) {
31
- chars[i] = hash[i].toString(16).padStart(2, '0');
32
- }
33
- return chars.join('');
34
- }
35
- HASH_SAMPLES.forEach(function (sample, i) {
36
- (0, node_test_1.default)(`sha1(node) HASH_SAMPLES[${i}]`, () => {
37
- assert.equal(hashToHex((0, sha1_js_1.default)(sample.input)), sample.sha1);
38
- });
39
- });
40
- HASH_SAMPLES.forEach(function (sample, i) {
41
- (0, node_test_1.default)(`md5(node) HASH_SAMPLES[${i}]`, () => {
42
- assert.equal(hashToHex((0, md5_js_1.default)(sample.input)), sample.md5);
43
- });
44
- });
45
- (0, node_test_1.default)('v3', () => {
46
- assert.strictEqual((0, v3_js_1.default)('hello.example.com', v3_js_1.default.DNS), '9125a8dc-52ee-365b-a5aa-81b0b3681cf6');
47
- assert.strictEqual((0, v3_js_1.default)('http://example.com/hello', v3_js_1.default.URL), 'c6235813-3ba4-3801-ae84-e0a6ebb7d138');
48
- assert.strictEqual((0, v3_js_1.default)('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'), 'a981a0c2-68b1-35dc-bcfc-296e52ab01ec');
49
- });
50
- (0, node_test_1.default)('v3 namespace.toUpperCase', () => {
51
- assert.strictEqual((0, v3_js_1.default)('hello.example.com', v3_js_1.default.DNS.toUpperCase()), '9125a8dc-52ee-365b-a5aa-81b0b3681cf6');
52
- assert.strictEqual((0, v3_js_1.default)('http://example.com/hello', v3_js_1.default.URL.toUpperCase()), 'c6235813-3ba4-3801-ae84-e0a6ebb7d138');
53
- assert.strictEqual((0, v3_js_1.default)('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'.toUpperCase()), 'a981a0c2-68b1-35dc-bcfc-296e52ab01ec');
54
- });
55
- (0, node_test_1.default)('v3 namespace string validation', () => {
56
- assert.throws(() => {
57
- (0, v3_js_1.default)('hello.example.com', 'zyxwvuts-rqpo-nmlk-jihg-fedcba000000');
58
- });
59
- assert.throws(() => {
60
- (0, v3_js_1.default)('hello.example.com', 'invalid uuid value');
61
- });
62
- assert.ok((0, v3_js_1.default)('hello.example.com', '00000000-0000-0000-0000-000000000000'));
63
- });
64
- (0, node_test_1.default)('v3 namespace buffer validation', () => {
65
- assert.throws(() => {
66
- (0, v3_js_1.default)('hello.example.com', new Uint8Array(15));
67
- });
68
- assert.throws(() => {
69
- (0, v3_js_1.default)('hello.example.com', new Uint8Array(17));
70
- });
71
- assert.ok((0, v3_js_1.default)('hello.example.com', new Uint8Array(16).fill(0)));
72
- });
73
- (0, node_test_1.default)('v3 fill buffer', () => {
74
- let buf = new Uint8Array(16);
75
- const expectedUuid = Uint8Array.of(0x91, 0x25, 0xa8, 0xdc, 0x52, 0xee, 0x36, 0x5b, 0xa5, 0xaa, 0x81, 0xb0, 0xb3, 0x68, 0x1c, 0xf6);
76
- const result = (0, v3_js_1.default)('hello.example.com', v3_js_1.default.DNS, buf);
77
- assert.deepEqual(buf, expectedUuid);
78
- assert.strictEqual(result, buf);
79
- buf = new Uint8Array(19).fill(0xaa);
80
- const expectedBuf = new Uint8Array(19).fill(0xaa);
81
- expectedBuf.set(expectedUuid, 3);
82
- (0, v3_js_1.default)('hello.example.com', v3_js_1.default.DNS, buf, 3);
83
- assert.deepEqual(buf, expectedBuf);
84
- });
85
- (0, node_test_1.default)('v3 undefined/null', () => {
86
- assert.throws(() => (0, v3_js_1.default)());
87
- assert.throws(() => (0, v3_js_1.default)('hello'));
88
- assert.throws(() => (0, v3_js_1.default)('hello.example.com', undefined));
89
- assert.throws(() => (0, v3_js_1.default)('hello.example.com', null, new Uint8Array(16)));
90
- });
91
- (0, node_test_1.default)('v5', () => {
92
- assert.strictEqual((0, v5_js_1.default)('hello.example.com', v5_js_1.default.DNS), 'fdda765f-fc57-5604-a269-52a7df8164ec');
93
- assert.strictEqual((0, v5_js_1.default)('http://example.com/hello', v5_js_1.default.URL), '3bbcee75-cecc-5b56-8031-b6641c1ed1f1');
94
- assert.strictEqual((0, v5_js_1.default)('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'), '90123e1c-7512-523e-bb28-76fab9f2f73d');
95
- });
96
- (0, node_test_1.default)('v5 namespace.toUpperCase', () => {
97
- assert.strictEqual((0, v5_js_1.default)('hello.example.com', v5_js_1.default.DNS.toUpperCase()), 'fdda765f-fc57-5604-a269-52a7df8164ec');
98
- assert.strictEqual((0, v5_js_1.default)('http://example.com/hello', v5_js_1.default.URL.toUpperCase()), '3bbcee75-cecc-5b56-8031-b6641c1ed1f1');
99
- assert.strictEqual((0, v5_js_1.default)('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'.toUpperCase()), '90123e1c-7512-523e-bb28-76fab9f2f73d');
100
- });
101
- (0, node_test_1.default)('v5 namespace string validation', () => {
102
- assert.throws(() => {
103
- (0, v5_js_1.default)('hello.example.com', 'zyxwvuts-rqpo-nmlk-jihg-fedcba000000');
104
- });
105
- assert.throws(() => {
106
- (0, v5_js_1.default)('hello.example.com', 'invalid uuid value');
107
- });
108
- assert.ok((0, v5_js_1.default)('hello.example.com', '00000000-0000-0000-0000-000000000000'));
109
- });
110
- (0, node_test_1.default)('v5 namespace buffer validation', () => {
111
- assert.throws(() => {
112
- (0, v5_js_1.default)('hello.example.com', new Uint8Array(15));
113
- });
114
- assert.throws(() => {
115
- (0, v5_js_1.default)('hello.example.com', new Uint8Array(17));
116
- });
117
- assert.ok((0, v5_js_1.default)('hello.example.com', new Uint8Array(16).fill(0)));
118
- });
119
- (0, node_test_1.default)('v5 fill buffer', () => {
120
- let buf = new Uint8Array(16);
121
- const expectedUuid = Uint8Array.of(0xfd, 0xda, 0x76, 0x5f, 0xfc, 0x57, 0x56, 0x04, 0xa2, 0x69, 0x52, 0xa7, 0xdf, 0x81, 0x64, 0xec);
122
- const result = (0, v5_js_1.default)('hello.example.com', v5_js_1.default.DNS, buf);
123
- assert.deepEqual(buf, expectedUuid);
124
- assert.strictEqual(result, buf);
125
- buf = new Uint8Array(19).fill(0xaa);
126
- const expectedBuf = new Uint8Array(19).fill(0xaa);
127
- expectedBuf.set(expectedUuid, 3);
128
- (0, v5_js_1.default)('hello.example.com', v5_js_1.default.DNS, buf, 3);
129
- assert.deepEqual(buf, expectedBuf);
130
- });
131
- (0, node_test_1.default)('v5 undefined/null', () => {
132
- assert.throws(() => (0, v5_js_1.default)());
133
- assert.throws(() => (0, v5_js_1.default)('hello'));
134
- assert.throws(() => (0, v5_js_1.default)('hello.example.com', undefined));
135
- assert.throws(() => (0, v5_js_1.default)('hello.example.com', null, new Uint8Array(16)));
136
- });
137
- (0, node_test_1.default)('v3/v5 constants', () => {
138
- assert.strictEqual(v3_js_1.default.DNS, '6ba7b810-9dad-11d1-80b4-00c04fd430c8');
139
- assert.strictEqual(v3_js_1.default.URL, '6ba7b811-9dad-11d1-80b4-00c04fd430c8');
140
- assert.strictEqual(v5_js_1.default.DNS, '6ba7b810-9dad-11d1-80b4-00c04fd430c8');
141
- assert.strictEqual(v5_js_1.default.URL, '6ba7b811-9dad-11d1-80b4-00c04fd430c8');
142
- });
143
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const node_test_1 = require("node:test");
5
- const native_js_1 = require("../native.js");
6
- const v4_js_1 = require("../v4.js");
7
- const randomBytesFixture = Uint8Array.of(0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea, 0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36);
8
- const expectedBytes = Uint8Array.of(16, 145, 86, 190, 196, 251, 65, 234, 177, 180, 239, 225, 103, 28, 88, 54);
9
- (0, node_test_1.describe)('v4', () => {
10
- (0, node_test_1.default)('subsequent UUIDs are different', () => {
11
- const id1 = (0, v4_js_1.default)();
12
- const id2 = (0, v4_js_1.default)();
13
- assert.ok(id1 !== id2);
14
- });
15
- (0, node_test_1.default)('should uses native randomUUID() if no option is passed', async () => {
16
- const mock = (await Promise.resolve().then(() => require('node:test'))).default.mock;
17
- if (!mock) {
18
- return;
19
- }
20
- const mockRandomUUID = mock.method(native_js_1.default, 'randomUUID');
21
- assert.equal(mockRandomUUID.mock.callCount(), 0);
22
- (0, v4_js_1.default)();
23
- assert.equal(mockRandomUUID.mock.callCount(), 1);
24
- mock.restoreAll();
25
- });
26
- (0, node_test_1.default)('should not use native randomUUID() if an option is passed', async () => {
27
- const mock = (await Promise.resolve().then(() => require('node:test'))).default.mock;
28
- if (!mock) {
29
- return;
30
- }
31
- const mockRandomUUID = mock.method(native_js_1.default, 'randomUUID');
32
- assert.equal(mockRandomUUID.mock.callCount(), 0);
33
- (0, v4_js_1.default)({});
34
- assert.equal(mockRandomUUID.mock.callCount(), 0);
35
- mock.restoreAll();
36
- });
37
- (0, node_test_1.default)('explicit options.random produces expected result', () => {
38
- const id = (0, v4_js_1.default)({ random: randomBytesFixture });
39
- assert.strictEqual(id, '109156be-c4fb-41ea-b1b4-efe1671c5836');
40
- });
41
- (0, node_test_1.default)('explicit options.rng produces expected result', () => {
42
- const id = (0, v4_js_1.default)({ rng: () => randomBytesFixture });
43
- assert.strictEqual(id, '109156be-c4fb-41ea-b1b4-efe1671c5836');
44
- });
45
- (0, node_test_1.default)('fills one UUID into a buffer as expected', () => {
46
- const buffer = new Uint8Array(16);
47
- const result = (0, v4_js_1.default)({ random: randomBytesFixture }, buffer);
48
- assert.deepEqual(buffer, expectedBytes);
49
- assert.strictEqual(buffer, result);
50
- });
51
- (0, node_test_1.default)('fills two UUIDs into a buffer as expected', () => {
52
- const buffer = new Uint8Array(32);
53
- (0, v4_js_1.default)({ random: randomBytesFixture }, buffer, 0);
54
- (0, v4_js_1.default)({ random: randomBytesFixture }, buffer, 16);
55
- const expectedBuf = new Uint8Array(32);
56
- expectedBuf.set(expectedBytes);
57
- expectedBuf.set(expectedBytes, 16);
58
- assert.deepEqual(buffer, expectedBuf);
59
- });
60
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const node_test_1 = require("node:test");
5
- const v1ToV6_js_1 = require("../v1ToV6.js");
6
- const v6_js_1 = require("../v6.js");
7
- const v6ToV1_js_1 = require("../v6ToV1.js");
8
- (0, node_test_1.describe)('v6', () => {
9
- const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
10
- const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
11
- const fullOptions = {
12
- msecs: 0x133b891f705,
13
- nsecs: 0x1538,
14
- clockseq: 0x385c,
15
- node: Uint8Array.of(0x61, 0xcd, 0x3c, 0xbb, 0x32, 0x10),
16
- };
17
- const EXPECTED_BYTES = Uint8Array.of(0x1e, 0x11, 0x22, 0xbd, 0x94, 0x28, 0x68, 0x88, 0xb8, 0x5c, 0x61, 0xcd, 0x3c, 0xbb, 0x32, 0x10);
18
- (0, node_test_1.default)('default behavior', () => {
19
- const id = (0, v6_js_1.default)();
20
- assert.ok(/[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/.test(id), 'id is valid v6 UUID');
21
- });
22
- (0, node_test_1.default)('default behavior (binary type)', () => {
23
- const buffer = new Uint8Array(16);
24
- const result = (0, v6_js_1.default)(fullOptions, buffer);
25
- assert.deepEqual(buffer, EXPECTED_BYTES);
26
- assert.strictEqual(buffer, result);
27
- });
28
- (0, node_test_1.default)('all options', () => {
29
- const id = (0, v6_js_1.default)(fullOptions);
30
- assert.equal(id, '1e1122bd-9428-6888-b85c-61cd3cbb3210');
31
- });
32
- (0, node_test_1.default)('sort by creation time', () => {
33
- const ids = [];
34
- for (let i = 0; i < 5; i++) {
35
- ids.push((0, v6_js_1.default)({ msecs: i * 1000 }));
36
- }
37
- assert.deepEqual(ids, ids.slice().sort());
38
- });
39
- (0, node_test_1.default)('creating at array offset', () => {
40
- const buffer = new Uint8Array(32);
41
- (0, v6_js_1.default)(fullOptions, buffer, 0);
42
- (0, v6_js_1.default)(fullOptions, buffer, 16);
43
- const expectedBuf = new Uint8Array(32);
44
- expectedBuf.set(EXPECTED_BYTES, 0);
45
- expectedBuf.set(EXPECTED_BYTES, 16);
46
- assert.deepEqual(buffer, expectedBuf);
47
- });
48
- (0, node_test_1.default)('v1 -> v6 conversion', () => {
49
- const id = (0, v1ToV6_js_1.default)(V1_ID);
50
- assert.equal(id, V6_ID);
51
- });
52
- (0, node_test_1.default)('v6 -> v1 conversion', () => {
53
- const id = (0, v6ToV1_js_1.default)(V6_ID);
54
- assert.equal(id, V1_ID);
55
- });
56
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,194 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const node_test_1 = require("node:test");
5
- const parse_js_1 = require("../parse.js");
6
- const stringify_js_1 = require("../stringify.js");
7
- const v7_js_1 = require("../v7.js");
8
- const RFC_V7 = '017f22e2-79b0-7cc3-98c4-dc0c0c07398f';
9
- const RFC_V7_BYTES = (0, parse_js_1.default)('017f22e2-79b0-7cc3-98c4-dc0c0c07398f');
10
- const RFC_MSECS = 0x17f22e279b0;
11
- const RFC_SEQ = (0x0cc3 << 20) | (0x98c4dc >> 2);
12
- const RFC_RANDOM = Uint8Array.of(0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0x0c, 0xc3, 0x18, 0xc4, 0x6c, 0x0c, 0x0c, 0x07, 0x39, 0x8f);
13
- (0, node_test_1.describe)('v7', () => {
14
- (0, node_test_1.default)('subsequent UUIDs are different', () => {
15
- const id1 = (0, v7_js_1.default)();
16
- const id2 = (0, v7_js_1.default)();
17
- assert.ok(id1 !== id2);
18
- });
19
- (0, node_test_1.default)('explicit options.random and options.msecs produces expected result', () => {
20
- const id = (0, v7_js_1.default)({
21
- random: RFC_RANDOM,
22
- msecs: RFC_MSECS,
23
- seq: RFC_SEQ,
24
- });
25
- assert.strictEqual(id, RFC_V7);
26
- });
27
- (0, node_test_1.default)('explicit options.rng produces expected result', () => {
28
- const id = (0, v7_js_1.default)({
29
- rng: () => RFC_RANDOM,
30
- msecs: RFC_MSECS,
31
- seq: RFC_SEQ,
32
- });
33
- assert.strictEqual(id, RFC_V7);
34
- });
35
- (0, node_test_1.default)('explicit options.msecs produces expected result', () => {
36
- const id = (0, v7_js_1.default)({
37
- msecs: RFC_MSECS,
38
- });
39
- assert.strictEqual(id.indexOf('017f22e2'), 0);
40
- });
41
- (0, node_test_1.default)('fills one UUID into a buffer as expected', () => {
42
- const buffer = new Uint8Array(16);
43
- const result = (0, v7_js_1.default)({
44
- random: RFC_RANDOM,
45
- msecs: RFC_MSECS,
46
- seq: RFC_SEQ,
47
- }, buffer);
48
- (0, stringify_js_1.default)(buffer);
49
- assert.deepEqual(buffer, RFC_V7_BYTES);
50
- assert.strictEqual(buffer, result);
51
- });
52
- (0, node_test_1.default)('fills two UUIDs into a buffer as expected', () => {
53
- const buffer = new Uint8Array(32);
54
- (0, v7_js_1.default)({
55
- random: RFC_RANDOM,
56
- msecs: RFC_MSECS,
57
- seq: RFC_SEQ,
58
- }, buffer, 0);
59
- (0, v7_js_1.default)({
60
- random: RFC_RANDOM,
61
- msecs: RFC_MSECS,
62
- seq: RFC_SEQ,
63
- }, buffer, 16);
64
- const expected = new Uint8Array(32);
65
- expected.set(RFC_V7_BYTES);
66
- expected.set(RFC_V7_BYTES, 16);
67
- assert.deepEqual(buffer, expected);
68
- });
69
- (0, node_test_1.default)('lexicographical sorting is preserved', () => {
70
- let id;
71
- let prior;
72
- let msecs = RFC_MSECS;
73
- for (let i = 0; i < 20000; ++i) {
74
- if (i % 1500 === 0) {
75
- msecs += 1;
76
- }
77
- id = (0, v7_js_1.default)({ msecs, seq: i });
78
- if (prior !== undefined) {
79
- assert.ok(prior < id, `${prior} < ${id}`);
80
- }
81
- prior = id;
82
- }
83
- });
84
- (0, node_test_1.default)('can supply seq', () => {
85
- let seq = 0x12345;
86
- let uuid = (0, v7_js_1.default)({
87
- msecs: RFC_MSECS,
88
- seq,
89
- });
90
- assert.strictEqual(uuid.substr(0, 25), '017f22e2-79b0-7000-848d-1');
91
- seq = 0x6fffffff;
92
- uuid = (0, v7_js_1.default)({
93
- msecs: RFC_MSECS,
94
- seq,
95
- });
96
- assert.strictEqual(uuid.substring(0, 25), '017f22e2-79b0-76ff-bfff-f');
97
- });
98
- (0, node_test_1.default)('internal seq is reset upon timestamp change', () => {
99
- (0, v7_js_1.default)({
100
- msecs: RFC_MSECS,
101
- seq: 0x6fffffff,
102
- });
103
- const uuid = (0, v7_js_1.default)({
104
- msecs: RFC_MSECS + 1,
105
- });
106
- assert.ok(uuid.indexOf('fff') !== 15);
107
- });
108
- (0, node_test_1.default)('v7() state transitions', () => {
109
- const tests = [
110
- {
111
- title: 'new time interval',
112
- state: { msecs: 1, seq: 123 },
113
- now: 2,
114
- expected: {
115
- msecs: 2,
116
- seq: 0x6c318c4,
117
- },
118
- },
119
- {
120
- title: 'same time interval',
121
- state: { msecs: 1, seq: 123 },
122
- now: 1,
123
- expected: {
124
- msecs: 1,
125
- seq: 124,
126
- },
127
- },
128
- {
129
- title: 'same time interval (sequence rollover)',
130
- state: { msecs: 1, seq: 0xffffffff },
131
- now: 1,
132
- expected: {
133
- msecs: 2,
134
- seq: 0,
135
- },
136
- },
137
- {
138
- title: 'time regression',
139
- state: { msecs: 2, seq: 123 },
140
- now: 1,
141
- expected: {
142
- msecs: 2,
143
- seq: 124,
144
- },
145
- },
146
- {
147
- title: 'time regression (sequence rollover)',
148
- state: { msecs: 2, seq: 0xffffffff },
149
- now: 1,
150
- expected: {
151
- msecs: 3,
152
- seq: 0,
153
- },
154
- },
155
- ];
156
- for (const { title, state, now, expected } of tests) {
157
- assert.deepStrictEqual((0, v7_js_1.updateV7State)(state, now, RFC_RANDOM), expected, `Failed: ${title}`);
158
- }
159
- });
160
- (0, node_test_1.default)('flipping bits changes the result', () => {
161
- const asBigInt = (buf) => buf.reduce((acc, v) => (acc << 8n) | BigInt(v), 0n);
162
- const asNumber = (bits, data) => Number(BigInt.asUintN(bits, data));
163
- const flip = (data, n) => data ^ (1n << BigInt(127 - n));
164
- const optionsFrom = (data) => {
165
- const ms = asNumber(48, data >> 80n);
166
- const hi = asNumber(12, data >> 64n);
167
- const lo = asNumber(20, data >> 42n);
168
- const r = BigInt.asUintN(42, data);
169
- return {
170
- msecs: ms,
171
- seq: (hi << 20) | lo,
172
- random: Uint8Array.from([
173
- ...Array(10).fill(0),
174
- ...Array(6)
175
- .fill(0)
176
- .map((_, i) => asNumber(8, r >> (BigInt(i) * 8n)))
177
- .reverse(),
178
- ]),
179
- };
180
- };
181
- const buf = new Uint8Array(16);
182
- const data = asBigInt((0, v7_js_1.default)({}, buf));
183
- const id = (0, stringify_js_1.default)(buf);
184
- const reserved = [48, 49, 50, 51, 64, 65];
185
- for (let i = 0; i < 128; ++i) {
186
- if (reserved.includes(i)) {
187
- continue;
188
- }
189
- const flipped = flip(data, i);
190
- assert.strictEqual(asBigInt((0, v7_js_1.default)(optionsFrom(flipped), buf)).toString(16), flipped.toString(16), `Unequal uuids at bit ${i}`);
191
- assert.notStrictEqual((0, stringify_js_1.default)(buf), id);
192
- }
193
- });
194
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const node_test_1 = require("node:test");
5
- const validate_js_1 = require("../validate.js");
6
- const test_constants_js_1 = require("./test_constants.js");
7
- (0, node_test_1.describe)('validate()', () => {
8
- (0, node_test_1.default)('TESTS cases', () => {
9
- for (const { value, expectedValidate } of test_constants_js_1.TESTS) {
10
- assert.strictEqual((0, validate_js_1.default)(value), expectedValidate, `validate(${value}) should be ${expectedValidate}`);
11
- }
12
- });
13
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const node_test_1 = require("node:test");
5
- const version_js_1 = require("../version.js");
6
- const test_constants_js_1 = require("./test_constants.js");
7
- (0, node_test_1.describe)('version()', () => {
8
- (0, node_test_1.default)('TESTS cases', () => {
9
- for (const { value, expectedValidate, expectedVersion } of test_constants_js_1.TESTS) {
10
- try {
11
- const actualVersion = (0, version_js_1.default)(value);
12
- assert.ok(expectedValidate, `version(${value}) should throw`);
13
- assert.strictEqual(actualVersion, expectedVersion);
14
- }
15
- catch {
16
- assert.ok(!expectedValidate, `version(${value}) threw unexpectedly`);
17
- }
18
- }
19
- });
20
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,48 +0,0 @@
1
- import * as assert from 'assert';
2
- import test, { describe } from 'node:test';
3
- import parse from '../parse.js';
4
- import stringify from '../stringify.js';
5
- import uuidv4 from '../v4.js';
6
- function splitmix32(a) {
7
- return function () {
8
- a |= 0;
9
- a = (a + 0x9e3779b9) | 0;
10
- let t = a ^ (a >>> 16);
11
- t = Math.imul(t, 0x21f0aaad);
12
- t = t ^ (t >>> 15);
13
- t = Math.imul(t, 0x735a2d97);
14
- return ((t = t ^ (t >>> 15)) >>> 0) / 4294967296;
15
- };
16
- }
17
- const rand = splitmix32(0x12345678);
18
- function rng(bytes = new Uint8Array(16)) {
19
- for (let i = 0; i < 16; i++) {
20
- bytes[i] = rand() * 256;
21
- }
22
- return bytes;
23
- }
24
- describe('parse', () => {
25
- test('String -> bytes parsing', () => {
26
- assert.deepStrictEqual(parse('0f5abcd1-c194-47f3-905b-2df7263a084b'), Uint8Array.from([
27
- 0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08,
28
- 0x4b,
29
- ]));
30
- });
31
- test('String -> bytes -> string symmetry for assorted uuids', () => {
32
- for (let i = 0; i < 1000; i++) {
33
- const uuid = uuidv4({ rng });
34
- assert.equal(stringify(parse(uuid)), uuid);
35
- }
36
- });
37
- test('Case neutrality', () => {
38
- assert.deepStrictEqual(parse('0f5abcd1-c194-47f3-905b-2df7263a084b'), parse('0f5abcd1-c194-47f3-905b-2df7263a084b'.toUpperCase()));
39
- });
40
- test('Null UUID case', () => {
41
- assert.deepStrictEqual(parse('00000000-0000-0000-0000-000000000000'), Uint8Array.from(new Array(16).fill(0)));
42
- });
43
- test('UUID validation', () => {
44
- assert.throws(() => parse());
45
- assert.throws(() => parse('invalid uuid'));
46
- assert.throws(() => parse('zyxwvuts-rqpo-nmlk-jihg-fedcba000000'));
47
- });
48
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,12 +0,0 @@
1
- import * as assert from 'assert';
2
- import test, { describe } from 'node:test';
3
- import rng from '../rng.js';
4
- describe('rng', () => {
5
- test('Node.js RNG', () => {
6
- const bytes = rng();
7
- assert.equal(bytes.length, 16);
8
- for (let i = 0; i < bytes.length; ++i) {
9
- assert.equal(typeof bytes[i], 'number');
10
- }
11
- });
12
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,21 +0,0 @@
1
- import * as assert from 'assert';
2
- import test, { describe } from 'node:test';
3
- import stringify, { unsafeStringify } from '../stringify.js';
4
- const BYTES = Uint8Array.of(0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08, 0x4b);
5
- describe('stringify', () => {
6
- test('Stringify Array (unsafe)', () => {
7
- assert.equal(unsafeStringify(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b');
8
- });
9
- test('Stringify w/ offset (unsafe)', () => {
10
- const bytes = new Uint8Array(19).fill(0);
11
- bytes.set(BYTES, 3);
12
- assert.equal(unsafeStringify(bytes, 3), '0f5abcd1-c194-47f3-905b-2df7263a084b');
13
- });
14
- test('Stringify Array (safe)', () => {
15
- assert.equal(stringify(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b');
16
- });
17
- test('Throws on not enough values (safe)', () => {
18
- const bytes = BYTES.slice(0, 15);
19
- assert.throws(() => stringify(bytes));
20
- });
21
- });
@@ -1,33 +0,0 @@
1
- export declare const TESTS: ({
2
- value: string;
3
- expectedValidate: boolean;
4
- expectedVersion: number;
5
- } | {
6
- value: string;
7
- expectedValidate: boolean;
8
- expectedVersion?: undefined;
9
- } | {
10
- value: undefined;
11
- expectedValidate: boolean;
12
- expectedVersion?: undefined;
13
- } | {
14
- value: null;
15
- expectedValidate: boolean;
16
- expectedVersion?: undefined;
17
- } | {
18
- value: number;
19
- expectedValidate: boolean;
20
- expectedVersion?: undefined;
21
- } | {
22
- value: RegExp;
23
- expectedValidate: boolean;
24
- expectedVersion?: undefined;
25
- } | {
26
- value: Date;
27
- expectedValidate: boolean;
28
- expectedVersion?: undefined;
29
- } | {
30
- value: boolean;
31
- expectedValidate: boolean;
32
- expectedVersion?: undefined;
33
- })[];