uuid 11.0.3 → 11.0.4
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.
- package/README.md +29 -16
- package/dist/cjs/md5.d.ts +1 -1
- package/dist/cjs/parse.d.ts +1 -1
- package/dist/cjs/rng.d.ts +1 -1
- package/dist/cjs/sha1.d.ts +1 -1
- package/dist/cjs/v1.js +8 -0
- package/dist/cjs/v35.d.ts +2 -2
- package/dist/cjs/v4.js +7 -1
- package/dist/cjs/v7.js +8 -0
- package/dist/cjs-browser/md5.d.ts +1 -1
- package/dist/cjs-browser/parse.d.ts +1 -1
- package/dist/cjs-browser/rng.d.ts +1 -1
- package/dist/cjs-browser/v1.js +8 -0
- package/dist/cjs-browser/v35.d.ts +2 -2
- package/dist/cjs-browser/v4.js +7 -1
- package/dist/cjs-browser/v7.js +8 -0
- package/dist/esm/md5.d.ts +1 -1
- package/dist/esm/parse.d.ts +1 -1
- package/dist/esm/rng.d.ts +1 -1
- package/dist/esm/sha1.d.ts +1 -1
- package/dist/esm/v1.js +8 -0
- package/dist/esm/v35.d.ts +2 -2
- package/dist/esm/v4.js +7 -1
- package/dist/esm/v7.js +8 -0
- package/dist/esm-browser/md5.d.ts +1 -1
- package/dist/esm-browser/parse.d.ts +1 -1
- package/dist/esm-browser/rng.d.ts +1 -1
- package/dist/esm-browser/v1.js +8 -0
- package/dist/esm-browser/v35.d.ts +2 -2
- package/dist/esm-browser/v4.js +7 -1
- package/dist/esm-browser/v7.js +8 -0
- package/package.json +17 -20
- package/CHANGELOG.md +0 -335
- package/CONTRIBUTING.md +0 -18
- package/dist/cjs/test/parse.test.d.ts +0 -1
- package/dist/cjs/test/parse.test.js +0 -50
- package/dist/cjs/test/rng.test.d.ts +0 -1
- package/dist/cjs/test/rng.test.js +0 -14
- package/dist/cjs/test/stringify.test.d.ts +0 -1
- package/dist/cjs/test/stringify.test.js +0 -23
- package/dist/cjs/test/test_constants.d.ts +0 -33
- package/dist/cjs/test/test_constants.js +0 -91
- package/dist/cjs/test/v1.test.d.ts +0 -1
- package/dist/cjs/test/v1.test.js +0 -127
- package/dist/cjs/test/v35.test.d.ts +0 -1
- package/dist/cjs/test/v35.test.js +0 -143
- package/dist/cjs/test/v4.test.d.ts +0 -1
- package/dist/cjs/test/v4.test.js +0 -60
- package/dist/cjs/test/v6.test.d.ts +0 -1
- package/dist/cjs/test/v6.test.js +0 -56
- package/dist/cjs/test/v7.test.d.ts +0 -1
- package/dist/cjs/test/v7.test.js +0 -194
- package/dist/cjs/test/validate.test.d.ts +0 -1
- package/dist/cjs/test/validate.test.js +0 -13
- package/dist/cjs/test/version.test.d.ts +0 -1
- package/dist/cjs/test/version.test.js +0 -20
- package/dist/cjs-browser/test/parse.test.d.ts +0 -1
- package/dist/cjs-browser/test/parse.test.js +0 -50
- package/dist/cjs-browser/test/rng.test.d.ts +0 -1
- package/dist/cjs-browser/test/rng.test.js +0 -14
- package/dist/cjs-browser/test/stringify.test.d.ts +0 -1
- package/dist/cjs-browser/test/stringify.test.js +0 -23
- package/dist/cjs-browser/test/test_constants.d.ts +0 -33
- package/dist/cjs-browser/test/test_constants.js +0 -91
- package/dist/cjs-browser/test/v1.test.d.ts +0 -1
- package/dist/cjs-browser/test/v1.test.js +0 -127
- package/dist/cjs-browser/test/v35.test.d.ts +0 -1
- package/dist/cjs-browser/test/v35.test.js +0 -143
- package/dist/cjs-browser/test/v4.test.d.ts +0 -1
- package/dist/cjs-browser/test/v4.test.js +0 -60
- package/dist/cjs-browser/test/v6.test.d.ts +0 -1
- package/dist/cjs-browser/test/v6.test.js +0 -56
- package/dist/cjs-browser/test/v7.test.d.ts +0 -1
- package/dist/cjs-browser/test/v7.test.js +0 -194
- package/dist/cjs-browser/test/validate.test.d.ts +0 -1
- package/dist/cjs-browser/test/validate.test.js +0 -13
- package/dist/cjs-browser/test/version.test.d.ts +0 -1
- package/dist/cjs-browser/test/version.test.js +0 -20
- package/dist/esm/test/parse.test.d.ts +0 -1
- package/dist/esm/test/parse.test.js +0 -48
- package/dist/esm/test/rng.test.d.ts +0 -1
- package/dist/esm/test/rng.test.js +0 -12
- package/dist/esm/test/stringify.test.d.ts +0 -1
- package/dist/esm/test/stringify.test.js +0 -21
- package/dist/esm/test/test_constants.d.ts +0 -33
- package/dist/esm/test/test_constants.js +0 -88
- package/dist/esm/test/v1.test.d.ts +0 -1
- package/dist/esm/test/v1.test.js +0 -125
- package/dist/esm/test/v35.test.d.ts +0 -1
- package/dist/esm/test/v35.test.js +0 -141
- package/dist/esm/test/v4.test.d.ts +0 -1
- package/dist/esm/test/v4.test.js +0 -58
- package/dist/esm/test/v6.test.d.ts +0 -1
- package/dist/esm/test/v6.test.js +0 -54
- package/dist/esm/test/v7.test.d.ts +0 -1
- package/dist/esm/test/v7.test.js +0 -192
- package/dist/esm/test/validate.test.d.ts +0 -1
- package/dist/esm/test/validate.test.js +0 -11
- package/dist/esm/test/version.test.d.ts +0 -1
- package/dist/esm/test/version.test.js +0 -18
- package/dist/esm-browser/test/parse.test.d.ts +0 -1
- package/dist/esm-browser/test/parse.test.js +0 -48
- package/dist/esm-browser/test/rng.test.d.ts +0 -1
- package/dist/esm-browser/test/rng.test.js +0 -12
- package/dist/esm-browser/test/stringify.test.d.ts +0 -1
- package/dist/esm-browser/test/stringify.test.js +0 -21
- package/dist/esm-browser/test/test_constants.d.ts +0 -33
- package/dist/esm-browser/test/test_constants.js +0 -88
- package/dist/esm-browser/test/v1.test.d.ts +0 -1
- package/dist/esm-browser/test/v1.test.js +0 -125
- package/dist/esm-browser/test/v35.test.d.ts +0 -1
- package/dist/esm-browser/test/v35.test.js +0 -141
- package/dist/esm-browser/test/v4.test.d.ts +0 -1
- package/dist/esm-browser/test/v4.test.js +0 -58
- package/dist/esm-browser/test/v6.test.d.ts +0 -1
- package/dist/esm-browser/test/v6.test.js +0 -54
- package/dist/esm-browser/test/v7.test.d.ts +0 -1
- package/dist/esm-browser/test/v7.test.js +0 -192
- package/dist/esm-browser/test/validate.test.d.ts +0 -1
- package/dist/esm-browser/test/validate.test.js +0 -11
- package/dist/esm-browser/test/version.test.d.ts +0 -1
- package/dist/esm-browser/test/version.test.js +0 -18
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import * as assert from 'assert';
|
|
2
|
-
import test, { describe } from 'node:test';
|
|
3
|
-
import md5 from '../md5.js';
|
|
4
|
-
import sha1 from '../sha1.js';
|
|
5
|
-
import v3 from '../v3.js';
|
|
6
|
-
import { stringToBytes } from '../v35.js';
|
|
7
|
-
import v5 from '../v5.js';
|
|
8
|
-
describe('v35', () => {
|
|
9
|
-
const HASH_SAMPLES = [
|
|
10
|
-
{
|
|
11
|
-
input: stringToBytes(''),
|
|
12
|
-
sha1: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
|
|
13
|
-
md5: 'd41d8cd98f00b204e9800998ecf8427e',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
input: 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'),
|
|
17
|
-
sha1: 'ca4a426a3d536f14cfd79011e79e10d64de950a0',
|
|
18
|
-
md5: 'e8098ec21950f841731d28749129d3ee',
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
input: 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'),
|
|
22
|
-
sha1: 'f2753ebc390e5f637e333c2a4179644a93ae9f65',
|
|
23
|
-
md5: '231b309e277b6be8bb3d6c688b7f098b',
|
|
24
|
-
},
|
|
25
|
-
];
|
|
26
|
-
function hashToHex(hash) {
|
|
27
|
-
const chars = new Array(hash.length);
|
|
28
|
-
for (let i = 0; i < hash.length; i++) {
|
|
29
|
-
chars[i] = hash[i].toString(16).padStart(2, '0');
|
|
30
|
-
}
|
|
31
|
-
return chars.join('');
|
|
32
|
-
}
|
|
33
|
-
HASH_SAMPLES.forEach(function (sample, i) {
|
|
34
|
-
test(`sha1(node) HASH_SAMPLES[${i}]`, () => {
|
|
35
|
-
assert.equal(hashToHex(sha1(sample.input)), sample.sha1);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
HASH_SAMPLES.forEach(function (sample, i) {
|
|
39
|
-
test(`md5(node) HASH_SAMPLES[${i}]`, () => {
|
|
40
|
-
assert.equal(hashToHex(md5(sample.input)), sample.md5);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
test('v3', () => {
|
|
44
|
-
assert.strictEqual(v3('hello.example.com', v3.DNS), '9125a8dc-52ee-365b-a5aa-81b0b3681cf6');
|
|
45
|
-
assert.strictEqual(v3('http://example.com/hello', v3.URL), 'c6235813-3ba4-3801-ae84-e0a6ebb7d138');
|
|
46
|
-
assert.strictEqual(v3('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'), 'a981a0c2-68b1-35dc-bcfc-296e52ab01ec');
|
|
47
|
-
});
|
|
48
|
-
test('v3 namespace.toUpperCase', () => {
|
|
49
|
-
assert.strictEqual(v3('hello.example.com', v3.DNS.toUpperCase()), '9125a8dc-52ee-365b-a5aa-81b0b3681cf6');
|
|
50
|
-
assert.strictEqual(v3('http://example.com/hello', v3.URL.toUpperCase()), 'c6235813-3ba4-3801-ae84-e0a6ebb7d138');
|
|
51
|
-
assert.strictEqual(v3('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'.toUpperCase()), 'a981a0c2-68b1-35dc-bcfc-296e52ab01ec');
|
|
52
|
-
});
|
|
53
|
-
test('v3 namespace string validation', () => {
|
|
54
|
-
assert.throws(() => {
|
|
55
|
-
v3('hello.example.com', 'zyxwvuts-rqpo-nmlk-jihg-fedcba000000');
|
|
56
|
-
});
|
|
57
|
-
assert.throws(() => {
|
|
58
|
-
v3('hello.example.com', 'invalid uuid value');
|
|
59
|
-
});
|
|
60
|
-
assert.ok(v3('hello.example.com', '00000000-0000-0000-0000-000000000000'));
|
|
61
|
-
});
|
|
62
|
-
test('v3 namespace buffer validation', () => {
|
|
63
|
-
assert.throws(() => {
|
|
64
|
-
v3('hello.example.com', new Uint8Array(15));
|
|
65
|
-
});
|
|
66
|
-
assert.throws(() => {
|
|
67
|
-
v3('hello.example.com', new Uint8Array(17));
|
|
68
|
-
});
|
|
69
|
-
assert.ok(v3('hello.example.com', new Uint8Array(16).fill(0)));
|
|
70
|
-
});
|
|
71
|
-
test('v3 fill buffer', () => {
|
|
72
|
-
let buf = new Uint8Array(16);
|
|
73
|
-
const expectedUuid = Uint8Array.of(0x91, 0x25, 0xa8, 0xdc, 0x52, 0xee, 0x36, 0x5b, 0xa5, 0xaa, 0x81, 0xb0, 0xb3, 0x68, 0x1c, 0xf6);
|
|
74
|
-
const result = v3('hello.example.com', v3.DNS, buf);
|
|
75
|
-
assert.deepEqual(buf, expectedUuid);
|
|
76
|
-
assert.strictEqual(result, buf);
|
|
77
|
-
buf = new Uint8Array(19).fill(0xaa);
|
|
78
|
-
const expectedBuf = new Uint8Array(19).fill(0xaa);
|
|
79
|
-
expectedBuf.set(expectedUuid, 3);
|
|
80
|
-
v3('hello.example.com', v3.DNS, buf, 3);
|
|
81
|
-
assert.deepEqual(buf, expectedBuf);
|
|
82
|
-
});
|
|
83
|
-
test('v3 undefined/null', () => {
|
|
84
|
-
assert.throws(() => v3());
|
|
85
|
-
assert.throws(() => v3('hello'));
|
|
86
|
-
assert.throws(() => v3('hello.example.com', undefined));
|
|
87
|
-
assert.throws(() => v3('hello.example.com', null, new Uint8Array(16)));
|
|
88
|
-
});
|
|
89
|
-
test('v5', () => {
|
|
90
|
-
assert.strictEqual(v5('hello.example.com', v5.DNS), 'fdda765f-fc57-5604-a269-52a7df8164ec');
|
|
91
|
-
assert.strictEqual(v5('http://example.com/hello', v5.URL), '3bbcee75-cecc-5b56-8031-b6641c1ed1f1');
|
|
92
|
-
assert.strictEqual(v5('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'), '90123e1c-7512-523e-bb28-76fab9f2f73d');
|
|
93
|
-
});
|
|
94
|
-
test('v5 namespace.toUpperCase', () => {
|
|
95
|
-
assert.strictEqual(v5('hello.example.com', v5.DNS.toUpperCase()), 'fdda765f-fc57-5604-a269-52a7df8164ec');
|
|
96
|
-
assert.strictEqual(v5('http://example.com/hello', v5.URL.toUpperCase()), '3bbcee75-cecc-5b56-8031-b6641c1ed1f1');
|
|
97
|
-
assert.strictEqual(v5('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'.toUpperCase()), '90123e1c-7512-523e-bb28-76fab9f2f73d');
|
|
98
|
-
});
|
|
99
|
-
test('v5 namespace string validation', () => {
|
|
100
|
-
assert.throws(() => {
|
|
101
|
-
v5('hello.example.com', 'zyxwvuts-rqpo-nmlk-jihg-fedcba000000');
|
|
102
|
-
});
|
|
103
|
-
assert.throws(() => {
|
|
104
|
-
v5('hello.example.com', 'invalid uuid value');
|
|
105
|
-
});
|
|
106
|
-
assert.ok(v5('hello.example.com', '00000000-0000-0000-0000-000000000000'));
|
|
107
|
-
});
|
|
108
|
-
test('v5 namespace buffer validation', () => {
|
|
109
|
-
assert.throws(() => {
|
|
110
|
-
v5('hello.example.com', new Uint8Array(15));
|
|
111
|
-
});
|
|
112
|
-
assert.throws(() => {
|
|
113
|
-
v5('hello.example.com', new Uint8Array(17));
|
|
114
|
-
});
|
|
115
|
-
assert.ok(v5('hello.example.com', new Uint8Array(16).fill(0)));
|
|
116
|
-
});
|
|
117
|
-
test('v5 fill buffer', () => {
|
|
118
|
-
let buf = new Uint8Array(16);
|
|
119
|
-
const expectedUuid = Uint8Array.of(0xfd, 0xda, 0x76, 0x5f, 0xfc, 0x57, 0x56, 0x04, 0xa2, 0x69, 0x52, 0xa7, 0xdf, 0x81, 0x64, 0xec);
|
|
120
|
-
const result = v5('hello.example.com', v5.DNS, buf);
|
|
121
|
-
assert.deepEqual(buf, expectedUuid);
|
|
122
|
-
assert.strictEqual(result, buf);
|
|
123
|
-
buf = new Uint8Array(19).fill(0xaa);
|
|
124
|
-
const expectedBuf = new Uint8Array(19).fill(0xaa);
|
|
125
|
-
expectedBuf.set(expectedUuid, 3);
|
|
126
|
-
v5('hello.example.com', v5.DNS, buf, 3);
|
|
127
|
-
assert.deepEqual(buf, expectedBuf);
|
|
128
|
-
});
|
|
129
|
-
test('v5 undefined/null', () => {
|
|
130
|
-
assert.throws(() => v5());
|
|
131
|
-
assert.throws(() => v5('hello'));
|
|
132
|
-
assert.throws(() => v5('hello.example.com', undefined));
|
|
133
|
-
assert.throws(() => v5('hello.example.com', null, new Uint8Array(16)));
|
|
134
|
-
});
|
|
135
|
-
test('v3/v5 constants', () => {
|
|
136
|
-
assert.strictEqual(v3.DNS, '6ba7b810-9dad-11d1-80b4-00c04fd430c8');
|
|
137
|
-
assert.strictEqual(v3.URL, '6ba7b811-9dad-11d1-80b4-00c04fd430c8');
|
|
138
|
-
assert.strictEqual(v5.DNS, '6ba7b810-9dad-11d1-80b4-00c04fd430c8');
|
|
139
|
-
assert.strictEqual(v5.URL, '6ba7b811-9dad-11d1-80b4-00c04fd430c8');
|
|
140
|
-
});
|
|
141
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/test/v4.test.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import * as assert from 'assert';
|
|
2
|
-
import test, { describe } from 'node:test';
|
|
3
|
-
import native from '../native.js';
|
|
4
|
-
import v4 from '../v4.js';
|
|
5
|
-
const randomBytesFixture = Uint8Array.of(0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea, 0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36);
|
|
6
|
-
const expectedBytes = Uint8Array.of(16, 145, 86, 190, 196, 251, 65, 234, 177, 180, 239, 225, 103, 28, 88, 54);
|
|
7
|
-
describe('v4', () => {
|
|
8
|
-
test('subsequent UUIDs are different', () => {
|
|
9
|
-
const id1 = v4();
|
|
10
|
-
const id2 = v4();
|
|
11
|
-
assert.ok(id1 !== id2);
|
|
12
|
-
});
|
|
13
|
-
test('should uses native randomUUID() if no option is passed', async () => {
|
|
14
|
-
const mock = (await import('node:test')).default.mock;
|
|
15
|
-
if (!mock) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
const mockRandomUUID = mock.method(native, 'randomUUID');
|
|
19
|
-
assert.equal(mockRandomUUID.mock.callCount(), 0);
|
|
20
|
-
v4();
|
|
21
|
-
assert.equal(mockRandomUUID.mock.callCount(), 1);
|
|
22
|
-
mock.restoreAll();
|
|
23
|
-
});
|
|
24
|
-
test('should not use native randomUUID() if an option is passed', async () => {
|
|
25
|
-
const mock = (await import('node:test')).default.mock;
|
|
26
|
-
if (!mock) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const mockRandomUUID = mock.method(native, 'randomUUID');
|
|
30
|
-
assert.equal(mockRandomUUID.mock.callCount(), 0);
|
|
31
|
-
v4({});
|
|
32
|
-
assert.equal(mockRandomUUID.mock.callCount(), 0);
|
|
33
|
-
mock.restoreAll();
|
|
34
|
-
});
|
|
35
|
-
test('explicit options.random produces expected result', () => {
|
|
36
|
-
const id = v4({ random: randomBytesFixture });
|
|
37
|
-
assert.strictEqual(id, '109156be-c4fb-41ea-b1b4-efe1671c5836');
|
|
38
|
-
});
|
|
39
|
-
test('explicit options.rng produces expected result', () => {
|
|
40
|
-
const id = v4({ rng: () => randomBytesFixture });
|
|
41
|
-
assert.strictEqual(id, '109156be-c4fb-41ea-b1b4-efe1671c5836');
|
|
42
|
-
});
|
|
43
|
-
test('fills one UUID into a buffer as expected', () => {
|
|
44
|
-
const buffer = new Uint8Array(16);
|
|
45
|
-
const result = v4({ random: randomBytesFixture }, buffer);
|
|
46
|
-
assert.deepEqual(buffer, expectedBytes);
|
|
47
|
-
assert.strictEqual(buffer, result);
|
|
48
|
-
});
|
|
49
|
-
test('fills two UUIDs into a buffer as expected', () => {
|
|
50
|
-
const buffer = new Uint8Array(32);
|
|
51
|
-
v4({ random: randomBytesFixture }, buffer, 0);
|
|
52
|
-
v4({ random: randomBytesFixture }, buffer, 16);
|
|
53
|
-
const expectedBuf = new Uint8Array(32);
|
|
54
|
-
expectedBuf.set(expectedBytes);
|
|
55
|
-
expectedBuf.set(expectedBytes, 16);
|
|
56
|
-
assert.deepEqual(buffer, expectedBuf);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/test/v6.test.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import * as assert from 'assert';
|
|
2
|
-
import test, { describe } from 'node:test';
|
|
3
|
-
import v1ToV6 from '../v1ToV6.js';
|
|
4
|
-
import v6 from '../v6.js';
|
|
5
|
-
import v6ToV1 from '../v6ToV1.js';
|
|
6
|
-
describe('v6', () => {
|
|
7
|
-
const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
|
|
8
|
-
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
|
|
9
|
-
const fullOptions = {
|
|
10
|
-
msecs: 0x133b891f705,
|
|
11
|
-
nsecs: 0x1538,
|
|
12
|
-
clockseq: 0x385c,
|
|
13
|
-
node: Uint8Array.of(0x61, 0xcd, 0x3c, 0xbb, 0x32, 0x10),
|
|
14
|
-
};
|
|
15
|
-
const EXPECTED_BYTES = Uint8Array.of(0x1e, 0x11, 0x22, 0xbd, 0x94, 0x28, 0x68, 0x88, 0xb8, 0x5c, 0x61, 0xcd, 0x3c, 0xbb, 0x32, 0x10);
|
|
16
|
-
test('default behavior', () => {
|
|
17
|
-
const id = v6();
|
|
18
|
-
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');
|
|
19
|
-
});
|
|
20
|
-
test('default behavior (binary type)', () => {
|
|
21
|
-
const buffer = new Uint8Array(16);
|
|
22
|
-
const result = v6(fullOptions, buffer);
|
|
23
|
-
assert.deepEqual(buffer, EXPECTED_BYTES);
|
|
24
|
-
assert.strictEqual(buffer, result);
|
|
25
|
-
});
|
|
26
|
-
test('all options', () => {
|
|
27
|
-
const id = v6(fullOptions);
|
|
28
|
-
assert.equal(id, '1e1122bd-9428-6888-b85c-61cd3cbb3210');
|
|
29
|
-
});
|
|
30
|
-
test('sort by creation time', () => {
|
|
31
|
-
const ids = [];
|
|
32
|
-
for (let i = 0; i < 5; i++) {
|
|
33
|
-
ids.push(v6({ msecs: i * 1000 }));
|
|
34
|
-
}
|
|
35
|
-
assert.deepEqual(ids, ids.slice().sort());
|
|
36
|
-
});
|
|
37
|
-
test('creating at array offset', () => {
|
|
38
|
-
const buffer = new Uint8Array(32);
|
|
39
|
-
v6(fullOptions, buffer, 0);
|
|
40
|
-
v6(fullOptions, buffer, 16);
|
|
41
|
-
const expectedBuf = new Uint8Array(32);
|
|
42
|
-
expectedBuf.set(EXPECTED_BYTES, 0);
|
|
43
|
-
expectedBuf.set(EXPECTED_BYTES, 16);
|
|
44
|
-
assert.deepEqual(buffer, expectedBuf);
|
|
45
|
-
});
|
|
46
|
-
test('v1 -> v6 conversion', () => {
|
|
47
|
-
const id = v1ToV6(V1_ID);
|
|
48
|
-
assert.equal(id, V6_ID);
|
|
49
|
-
});
|
|
50
|
-
test('v6 -> v1 conversion', () => {
|
|
51
|
-
const id = v6ToV1(V6_ID);
|
|
52
|
-
assert.equal(id, V1_ID);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/test/v7.test.js
DELETED
|
@@ -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
|
-
});
|
|
@@ -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
|
-
})[];
|