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,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,50 +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 v4_js_1 = require("../v4.js");
8
- function splitmix32(a) {
9
- return function () {
10
- a |= 0;
11
- a = (a + 0x9e3779b9) | 0;
12
- let t = a ^ (a >>> 16);
13
- t = Math.imul(t, 0x21f0aaad);
14
- t = t ^ (t >>> 15);
15
- t = Math.imul(t, 0x735a2d97);
16
- return ((t = t ^ (t >>> 15)) >>> 0) / 4294967296;
17
- };
18
- }
19
- const rand = splitmix32(0x12345678);
20
- function rng(bytes = new Uint8Array(16)) {
21
- for (let i = 0; i < 16; i++) {
22
- bytes[i] = rand() * 256;
23
- }
24
- return bytes;
25
- }
26
- (0, node_test_1.describe)('parse', () => {
27
- (0, node_test_1.default)('String -> bytes parsing', () => {
28
- assert.deepStrictEqual((0, parse_js_1.default)('0f5abcd1-c194-47f3-905b-2df7263a084b'), Uint8Array.from([
29
- 0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08,
30
- 0x4b,
31
- ]));
32
- });
33
- (0, node_test_1.default)('String -> bytes -> string symmetry for assorted uuids', () => {
34
- for (let i = 0; i < 1000; i++) {
35
- const uuid = (0, v4_js_1.default)({ rng });
36
- assert.equal((0, stringify_js_1.default)((0, parse_js_1.default)(uuid)), uuid);
37
- }
38
- });
39
- (0, node_test_1.default)('Case neutrality', () => {
40
- assert.deepStrictEqual((0, parse_js_1.default)('0f5abcd1-c194-47f3-905b-2df7263a084b'), (0, parse_js_1.default)('0f5abcd1-c194-47f3-905b-2df7263a084b'.toUpperCase()));
41
- });
42
- (0, node_test_1.default)('Null UUID case', () => {
43
- assert.deepStrictEqual((0, parse_js_1.default)('00000000-0000-0000-0000-000000000000'), Uint8Array.from(new Array(16).fill(0)));
44
- });
45
- (0, node_test_1.default)('UUID validation', () => {
46
- assert.throws(() => (0, parse_js_1.default)());
47
- assert.throws(() => (0, parse_js_1.default)('invalid uuid'));
48
- assert.throws(() => (0, parse_js_1.default)('zyxwvuts-rqpo-nmlk-jihg-fedcba000000'));
49
- });
50
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,14 +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 rng_js_1 = require("../rng.js");
6
- (0, node_test_1.describe)('rng', () => {
7
- (0, node_test_1.default)('Node.js RNG', () => {
8
- const bytes = (0, rng_js_1.default)();
9
- assert.equal(bytes.length, 16);
10
- for (let i = 0; i < bytes.length; ++i) {
11
- assert.equal(typeof bytes[i], 'number');
12
- }
13
- });
14
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,23 +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 stringify_js_1 = require("../stringify.js");
6
- const BYTES = Uint8Array.of(0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08, 0x4b);
7
- (0, node_test_1.describe)('stringify', () => {
8
- (0, node_test_1.default)('Stringify Array (unsafe)', () => {
9
- assert.equal((0, stringify_js_1.unsafeStringify)(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b');
10
- });
11
- (0, node_test_1.default)('Stringify w/ offset (unsafe)', () => {
12
- const bytes = new Uint8Array(19).fill(0);
13
- bytes.set(BYTES, 3);
14
- assert.equal((0, stringify_js_1.unsafeStringify)(bytes, 3), '0f5abcd1-c194-47f3-905b-2df7263a084b');
15
- });
16
- (0, node_test_1.default)('Stringify Array (safe)', () => {
17
- assert.equal((0, stringify_js_1.default)(BYTES), '0f5abcd1-c194-47f3-905b-2df7263a084b');
18
- });
19
- (0, node_test_1.default)('Throws on not enough values (safe)', () => {
20
- const bytes = BYTES.slice(0, 15);
21
- assert.throws(() => (0, stringify_js_1.default)(bytes));
22
- });
23
- });
@@ -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
- })[];
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TESTS = void 0;
4
- const max_js_1 = require("../max.js");
5
- const nil_js_1 = require("../nil.js");
6
- exports.TESTS = [
7
- { value: nil_js_1.default, expectedValidate: true, expectedVersion: 0 },
8
- { value: max_js_1.default, expectedValidate: true, expectedVersion: 15 },
9
- { value: '00000000-0000-1000-8000-000000000000', expectedValidate: true, expectedVersion: 1 },
10
- { value: 'ffffffff-ffff-1fff-8fff-ffffffffffff', expectedValidate: true, expectedVersion: 1 },
11
- { value: '00000000-0000-2000-8000-000000000000', expectedValidate: true, expectedVersion: 2 },
12
- { value: 'ffffffff-ffff-2fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 2 },
13
- { value: '00000000-0000-3000-8000-000000000000', expectedValidate: true, expectedVersion: 3 },
14
- { value: 'ffffffff-ffff-3fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 3 },
15
- { value: '00000000-0000-4000-8000-000000000000', expectedValidate: true, expectedVersion: 4 },
16
- { value: 'ffffffff-ffff-4fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 4 },
17
- { value: '00000000-0000-5000-8000-000000000000', expectedValidate: true, expectedVersion: 5 },
18
- { value: 'ffffffff-ffff-5fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 5 },
19
- { value: '00000000-0000-6000-8000-000000000000', expectedValidate: true, expectedVersion: 6 },
20
- { value: 'ffffffff-ffff-6fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 6 },
21
- { value: '00000000-0000-7000-8000-000000000000', expectedValidate: true, expectedVersion: 7 },
22
- { value: 'ffffffff-ffff-7fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 7 },
23
- { value: '00000000-0000-8000-8000-000000000000', expectedValidate: true, expectedVersion: 8 },
24
- { value: 'ffffffff-ffff-8fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 8 },
25
- { value: '00000000-0000-9000-8000-000000000000', expectedValidate: false },
26
- { value: 'ffffffff-ffff-9fff-bfff-ffffffffffff', expectedValidate: false },
27
- { value: '00000000-0000-a000-8000-000000000000', expectedValidate: false },
28
- { value: 'ffffffff-ffff-afff-bfff-ffffffffffff', expectedValidate: false },
29
- { value: '00000000-0000-b000-8000-000000000000', expectedValidate: false },
30
- { value: 'ffffffff-ffff-bfff-bfff-ffffffffffff', expectedValidate: false },
31
- { value: '00000000-0000-c000-8000-000000000000', expectedValidate: false },
32
- { value: 'ffffffff-ffff-cfff-bfff-ffffffffffff', expectedValidate: false },
33
- { value: '00000000-0000-d000-8000-000000000000', expectedValidate: false },
34
- { value: 'ffffffff-ffff-dfff-bfff-ffffffffffff', expectedValidate: false },
35
- { value: '00000000-0000-e000-8000-000000000000', expectedValidate: false },
36
- { value: 'ffffffff-ffff-efff-bfff-ffffffffffff', expectedValidate: false },
37
- { value: 'd9428888-122b-11e1-b85c-61cd3cbb3210', expectedValidate: true, expectedVersion: 1 },
38
- { value: '000003e8-2363-21ef-b200-325096b39f47', expectedValidate: true, expectedVersion: 2 },
39
- { value: 'a981a0c2-68b1-35dc-bcfc-296e52ab01ec', expectedValidate: true, expectedVersion: 3 },
40
- { value: '109156be-c4fb-41ea-b1b4-efe1671c5836', expectedValidate: true, expectedVersion: 4 },
41
- { value: '90123e1c-7512-523e-bb28-76fab9f2f73d', expectedValidate: true, expectedVersion: 5 },
42
- { value: '1ef21d2f-1207-6660-8c4f-419efbd44d48', expectedValidate: true, expectedVersion: 6 },
43
- { value: '017f22e2-79b0-7cc3-98c4-dc0c0c07398f', expectedValidate: true, expectedVersion: 7 },
44
- { value: '0d8f23a0-697f-83ae-802e-48f3756dd581', expectedValidate: true, expectedVersion: 8 },
45
- { value: '00000000-0000-1000-0000-000000000000', expectedValidate: false },
46
- { value: '00000000-0000-1000-1000-000000000000', expectedValidate: false },
47
- { value: '00000000-0000-1000-2000-000000000000', expectedValidate: false },
48
- { value: '00000000-0000-1000-3000-000000000000', expectedValidate: false },
49
- { value: '00000000-0000-1000-4000-000000000000', expectedValidate: false },
50
- { value: '00000000-0000-1000-5000-000000000000', expectedValidate: false },
51
- { value: '00000000-0000-1000-6000-000000000000', expectedValidate: false },
52
- { value: '00000000-0000-1000-7000-000000000000', expectedValidate: false },
53
- { value: '00000000-0000-1000-8000-000000000000', expectedValidate: true, expectedVersion: 1 },
54
- { value: '00000000-0000-1000-9000-000000000000', expectedValidate: true, expectedVersion: 1 },
55
- { value: '00000000-0000-1000-a000-000000000000', expectedValidate: true, expectedVersion: 1 },
56
- { value: '00000000-0000-1000-b000-000000000000', expectedValidate: true, expectedVersion: 1 },
57
- { value: '00000000-0000-1000-c000-000000000000', expectedValidate: false },
58
- { value: '00000000-0000-1000-d000-000000000000', expectedValidate: false },
59
- { value: '00000000-0000-1000-e000-000000000000', expectedValidate: false },
60
- { value: '00000000-0000-1000-f000-000000000000', expectedValidate: false },
61
- { value: '00000000000000000000000000000000', expectedValidate: false },
62
- { value: '', expectedValidate: false },
63
- { value: 'invalid uuid string', expectedValidate: false },
64
- {
65
- value: '=Y00a-f*vb*-c-d#-p00f\b-g0h-#i^-j*3&-L00k-\nl---00n-fg000-00p-00r+',
66
- expectedValidate: false,
67
- },
68
- { value: undefined, expectedValidate: false },
69
- { value: null, expectedValidate: false },
70
- { value: 123, expectedValidate: false },
71
- { value: /regex/, expectedValidate: false },
72
- { value: new Date(0), expectedValidate: false },
73
- { value: false, expectedValidate: false },
74
- ];
75
- for (let charIndex = 0; charIndex < 36; charIndex++) {
76
- if (charIndex === 8 ||
77
- charIndex === 13 ||
78
- charIndex === 14 ||
79
- charIndex === 18 ||
80
- charIndex === 23) {
81
- continue;
82
- }
83
- const nilChars = nil_js_1.default.split('');
84
- const maxChars = max_js_1.default.split('');
85
- for (let i = 0; i < 4; i++) {
86
- nilChars[charIndex] = (0x0 ^ (1 << i)).toString(16);
87
- exports.TESTS.push({ value: nilChars.join(''), expectedValidate: false });
88
- maxChars[charIndex] = (0xf ^ (1 << i)).toString(16);
89
- exports.TESTS.push({ value: maxChars.join(''), expectedValidate: false });
90
- }
91
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,127 +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 v1_js_1 = require("../v1.js");
7
- const TIME = 1321644961388;
8
- const RFC_V1 = 'c232ab00-9414-11ec-b3c8-9f68deced846';
9
- const RFC_V1_BYTES = (0, parse_js_1.default)(RFC_V1);
10
- const RFC_OPTIONS = {
11
- msecs: 0x17f22e279b0,
12
- nsecs: 0,
13
- clockseq: 0x33c8,
14
- node: Uint8Array.of(0x9f, 0x68, 0xde, 0xce, 0xd8, 0x46),
15
- };
16
- const RFC_RANDOM = Uint8Array.of(0, 0, 0, 0, 0, 0, 0, 0, RFC_OPTIONS.clockseq >> 8, RFC_OPTIONS.clockseq & 0xff, ...RFC_OPTIONS.node);
17
- function compareV1TimeField(a, b) {
18
- a = a.split('-').slice(0, 3).reverse().join('');
19
- b = b.split('-').slice(0, 3).reverse().join('');
20
- return a < b ? -1 : a > b ? 1 : 0;
21
- }
22
- (0, node_test_1.describe)('v1', () => {
23
- (0, node_test_1.default)('v1 sort order (default)', () => {
24
- const ids = [(0, v1_js_1.default)(), (0, v1_js_1.default)(), (0, v1_js_1.default)(), (0, v1_js_1.default)(), (0, v1_js_1.default)()];
25
- const sorted = [...ids].sort(compareV1TimeField);
26
- assert.deepEqual(ids, sorted);
27
- });
28
- (0, node_test_1.default)('v1 sort order (time option)', () => {
29
- const ids = [
30
- (0, v1_js_1.default)({ msecs: TIME - 10 * 3600 * 1000 }),
31
- (0, v1_js_1.default)({ msecs: TIME - 1 }),
32
- (0, v1_js_1.default)({ msecs: TIME }),
33
- (0, v1_js_1.default)({ msecs: TIME + 1 }),
34
- (0, v1_js_1.default)({ msecs: TIME + 28 * 24 * 3600 * 1000 }),
35
- ];
36
- const sorted = [...ids].sort(compareV1TimeField);
37
- assert.deepEqual(ids, sorted);
38
- });
39
- (0, node_test_1.default)('v1(options)', () => {
40
- assert.equal((0, v1_js_1.default)({ msecs: RFC_OPTIONS.msecs, random: RFC_RANDOM }), RFC_V1, 'minimal options');
41
- assert.equal((0, v1_js_1.default)(RFC_OPTIONS), RFC_V1, 'full options');
42
- });
43
- (0, node_test_1.default)('v1(options) equality', () => {
44
- assert.notEqual((0, v1_js_1.default)({ msecs: TIME }), (0, v1_js_1.default)({ msecs: TIME }), 'UUIDs with minimal options differ');
45
- assert.equal((0, v1_js_1.default)(RFC_OPTIONS), (0, v1_js_1.default)(RFC_OPTIONS), 'UUIDs with full options are identical');
46
- });
47
- (0, node_test_1.default)('fills one UUID into a buffer as expected', () => {
48
- const buffer = new Uint8Array(16);
49
- const result = (0, v1_js_1.default)(RFC_OPTIONS, buffer);
50
- assert.deepEqual(buffer, RFC_V1_BYTES);
51
- assert.strictEqual(buffer, result);
52
- });
53
- (0, node_test_1.default)('fills two UUIDs into a buffer as expected', () => {
54
- const buffer = new Uint8Array(32);
55
- (0, v1_js_1.default)(RFC_OPTIONS, buffer, 0);
56
- (0, v1_js_1.default)(RFC_OPTIONS, buffer, 16);
57
- const expectedBuf = new Uint8Array(32);
58
- expectedBuf.set(RFC_V1_BYTES);
59
- expectedBuf.set(RFC_V1_BYTES, 16);
60
- assert.deepEqual(buffer, expectedBuf);
61
- });
62
- (0, node_test_1.default)('v1() state transitions', () => {
63
- const PRE_STATE = {
64
- msecs: 10,
65
- nsecs: 20,
66
- clockseq: 0x1234,
67
- node: Uint8Array.of(0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc),
68
- };
69
- const tests = [
70
- {
71
- title: 'initial state',
72
- state: {},
73
- now: 10,
74
- expected: {
75
- msecs: 10,
76
- nsecs: 0,
77
- clockseq: RFC_OPTIONS.clockseq,
78
- node: RFC_OPTIONS.node,
79
- },
80
- },
81
- {
82
- title: 'same time interval',
83
- state: { ...PRE_STATE },
84
- now: PRE_STATE.msecs,
85
- expected: {
86
- ...PRE_STATE,
87
- nsecs: 21,
88
- },
89
- },
90
- {
91
- title: 'new time interval',
92
- state: { ...PRE_STATE },
93
- now: PRE_STATE.msecs + 1,
94
- expected: {
95
- ...PRE_STATE,
96
- msecs: PRE_STATE.msecs + 1,
97
- nsecs: 0,
98
- },
99
- },
100
- {
101
- title: 'same time interval (nsecs overflow)',
102
- state: { ...PRE_STATE, nsecs: 9999 },
103
- now: PRE_STATE.msecs,
104
- expected: {
105
- ...PRE_STATE,
106
- nsecs: 0,
107
- clockseq: RFC_OPTIONS.clockseq,
108
- node: RFC_OPTIONS.node,
109
- },
110
- },
111
- {
112
- title: 'time regression',
113
- state: { ...PRE_STATE },
114
- now: PRE_STATE.msecs - 1,
115
- expected: {
116
- ...PRE_STATE,
117
- msecs: PRE_STATE.msecs - 1,
118
- clockseq: RFC_OPTIONS.clockseq,
119
- node: RFC_OPTIONS.node,
120
- },
121
- },
122
- ];
123
- for (const { title, state, now, expected } of tests) {
124
- assert.deepStrictEqual((0, v1_js_1.updateV1State)(state, now, RFC_RANDOM), expected, `Failed: ${title}`);
125
- }
126
- });
127
- });
@@ -1 +0,0 @@
1
- export {};