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,192 +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 v7, { updateV7State } from '../v7.js';
6
- const RFC_V7 = '017f22e2-79b0-7cc3-98c4-dc0c0c07398f';
7
- const RFC_V7_BYTES = parse('017f22e2-79b0-7cc3-98c4-dc0c0c07398f');
8
- const RFC_MSECS = 0x17f22e279b0;
9
- const RFC_SEQ = (0x0cc3 << 20) | (0x98c4dc >> 2);
10
- const RFC_RANDOM = Uint8Array.of(0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0x0c, 0xc3, 0x18, 0xc4, 0x6c, 0x0c, 0x0c, 0x07, 0x39, 0x8f);
11
- describe('v7', () => {
12
- test('subsequent UUIDs are different', () => {
13
- const id1 = v7();
14
- const id2 = v7();
15
- assert.ok(id1 !== id2);
16
- });
17
- test('explicit options.random and options.msecs produces expected result', () => {
18
- const id = v7({
19
- random: RFC_RANDOM,
20
- msecs: RFC_MSECS,
21
- seq: RFC_SEQ,
22
- });
23
- assert.strictEqual(id, RFC_V7);
24
- });
25
- test('explicit options.rng produces expected result', () => {
26
- const id = v7({
27
- rng: () => RFC_RANDOM,
28
- msecs: RFC_MSECS,
29
- seq: RFC_SEQ,
30
- });
31
- assert.strictEqual(id, RFC_V7);
32
- });
33
- test('explicit options.msecs produces expected result', () => {
34
- const id = v7({
35
- msecs: RFC_MSECS,
36
- });
37
- assert.strictEqual(id.indexOf('017f22e2'), 0);
38
- });
39
- test('fills one UUID into a buffer as expected', () => {
40
- const buffer = new Uint8Array(16);
41
- const result = v7({
42
- random: RFC_RANDOM,
43
- msecs: RFC_MSECS,
44
- seq: RFC_SEQ,
45
- }, buffer);
46
- stringify(buffer);
47
- assert.deepEqual(buffer, RFC_V7_BYTES);
48
- assert.strictEqual(buffer, result);
49
- });
50
- test('fills two UUIDs into a buffer as expected', () => {
51
- const buffer = new Uint8Array(32);
52
- v7({
53
- random: RFC_RANDOM,
54
- msecs: RFC_MSECS,
55
- seq: RFC_SEQ,
56
- }, buffer, 0);
57
- v7({
58
- random: RFC_RANDOM,
59
- msecs: RFC_MSECS,
60
- seq: RFC_SEQ,
61
- }, buffer, 16);
62
- const expected = new Uint8Array(32);
63
- expected.set(RFC_V7_BYTES);
64
- expected.set(RFC_V7_BYTES, 16);
65
- assert.deepEqual(buffer, expected);
66
- });
67
- test('lexicographical sorting is preserved', () => {
68
- let id;
69
- let prior;
70
- let msecs = RFC_MSECS;
71
- for (let i = 0; i < 20000; ++i) {
72
- if (i % 1500 === 0) {
73
- msecs += 1;
74
- }
75
- id = v7({ msecs, seq: i });
76
- if (prior !== undefined) {
77
- assert.ok(prior < id, `${prior} < ${id}`);
78
- }
79
- prior = id;
80
- }
81
- });
82
- test('can supply seq', () => {
83
- let seq = 0x12345;
84
- let uuid = v7({
85
- msecs: RFC_MSECS,
86
- seq,
87
- });
88
- assert.strictEqual(uuid.substr(0, 25), '017f22e2-79b0-7000-848d-1');
89
- seq = 0x6fffffff;
90
- uuid = v7({
91
- msecs: RFC_MSECS,
92
- seq,
93
- });
94
- assert.strictEqual(uuid.substring(0, 25), '017f22e2-79b0-76ff-bfff-f');
95
- });
96
- test('internal seq is reset upon timestamp change', () => {
97
- v7({
98
- msecs: RFC_MSECS,
99
- seq: 0x6fffffff,
100
- });
101
- const uuid = v7({
102
- msecs: RFC_MSECS + 1,
103
- });
104
- assert.ok(uuid.indexOf('fff') !== 15);
105
- });
106
- test('v7() state transitions', () => {
107
- const tests = [
108
- {
109
- title: 'new time interval',
110
- state: { msecs: 1, seq: 123 },
111
- now: 2,
112
- expected: {
113
- msecs: 2,
114
- seq: 0x6c318c4,
115
- },
116
- },
117
- {
118
- title: 'same time interval',
119
- state: { msecs: 1, seq: 123 },
120
- now: 1,
121
- expected: {
122
- msecs: 1,
123
- seq: 124,
124
- },
125
- },
126
- {
127
- title: 'same time interval (sequence rollover)',
128
- state: { msecs: 1, seq: 0xffffffff },
129
- now: 1,
130
- expected: {
131
- msecs: 2,
132
- seq: 0,
133
- },
134
- },
135
- {
136
- title: 'time regression',
137
- state: { msecs: 2, seq: 123 },
138
- now: 1,
139
- expected: {
140
- msecs: 2,
141
- seq: 124,
142
- },
143
- },
144
- {
145
- title: 'time regression (sequence rollover)',
146
- state: { msecs: 2, seq: 0xffffffff },
147
- now: 1,
148
- expected: {
149
- msecs: 3,
150
- seq: 0,
151
- },
152
- },
153
- ];
154
- for (const { title, state, now, expected } of tests) {
155
- assert.deepStrictEqual(updateV7State(state, now, RFC_RANDOM), expected, `Failed: ${title}`);
156
- }
157
- });
158
- test('flipping bits changes the result', () => {
159
- const asBigInt = (buf) => buf.reduce((acc, v) => (acc << 8n) | BigInt(v), 0n);
160
- const asNumber = (bits, data) => Number(BigInt.asUintN(bits, data));
161
- const flip = (data, n) => data ^ (1n << BigInt(127 - n));
162
- const optionsFrom = (data) => {
163
- const ms = asNumber(48, data >> 80n);
164
- const hi = asNumber(12, data >> 64n);
165
- const lo = asNumber(20, data >> 42n);
166
- const r = BigInt.asUintN(42, data);
167
- return {
168
- msecs: ms,
169
- seq: (hi << 20) | lo,
170
- random: Uint8Array.from([
171
- ...Array(10).fill(0),
172
- ...Array(6)
173
- .fill(0)
174
- .map((_, i) => asNumber(8, r >> (BigInt(i) * 8n)))
175
- .reverse(),
176
- ]),
177
- };
178
- };
179
- const buf = new Uint8Array(16);
180
- const data = asBigInt(v7({}, buf));
181
- const id = stringify(buf);
182
- const reserved = [48, 49, 50, 51, 64, 65];
183
- for (let i = 0; i < 128; ++i) {
184
- if (reserved.includes(i)) {
185
- continue;
186
- }
187
- const flipped = flip(data, i);
188
- assert.strictEqual(asBigInt(v7(optionsFrom(flipped), buf)).toString(16), flipped.toString(16), `Unequal uuids at bit ${i}`);
189
- assert.notStrictEqual(stringify(buf), id);
190
- }
191
- });
192
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- import * as assert from 'assert';
2
- import test, { describe } from 'node:test';
3
- import validate from '../validate.js';
4
- import { TESTS } from './test_constants.js';
5
- describe('validate()', () => {
6
- test('TESTS cases', () => {
7
- for (const { value, expectedValidate } of TESTS) {
8
- assert.strictEqual(validate(value), expectedValidate, `validate(${value}) should be ${expectedValidate}`);
9
- }
10
- });
11
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,18 +0,0 @@
1
- import * as assert from 'assert';
2
- import test, { describe } from 'node:test';
3
- import version from '../version.js';
4
- import { TESTS } from './test_constants.js';
5
- describe('version()', () => {
6
- test('TESTS cases', () => {
7
- for (const { value, expectedValidate, expectedVersion } of TESTS) {
8
- try {
9
- const actualVersion = version(value);
10
- assert.ok(expectedValidate, `version(${value}) should throw`);
11
- assert.strictEqual(actualVersion, expectedVersion);
12
- }
13
- catch {
14
- assert.ok(!expectedValidate, `version(${value}) threw unexpectedly`);
15
- }
16
- }
17
- });
18
- });