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 +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
- })[];
@@ -1,88 +0,0 @@
1
- import MAX from '../max.js';
2
- import NIL from '../nil.js';
3
- export const TESTS = [
4
- { value: NIL, expectedValidate: true, expectedVersion: 0 },
5
- { value: MAX, expectedValidate: true, expectedVersion: 15 },
6
- { value: '00000000-0000-1000-8000-000000000000', expectedValidate: true, expectedVersion: 1 },
7
- { value: 'ffffffff-ffff-1fff-8fff-ffffffffffff', expectedValidate: true, expectedVersion: 1 },
8
- { value: '00000000-0000-2000-8000-000000000000', expectedValidate: true, expectedVersion: 2 },
9
- { value: 'ffffffff-ffff-2fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 2 },
10
- { value: '00000000-0000-3000-8000-000000000000', expectedValidate: true, expectedVersion: 3 },
11
- { value: 'ffffffff-ffff-3fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 3 },
12
- { value: '00000000-0000-4000-8000-000000000000', expectedValidate: true, expectedVersion: 4 },
13
- { value: 'ffffffff-ffff-4fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 4 },
14
- { value: '00000000-0000-5000-8000-000000000000', expectedValidate: true, expectedVersion: 5 },
15
- { value: 'ffffffff-ffff-5fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 5 },
16
- { value: '00000000-0000-6000-8000-000000000000', expectedValidate: true, expectedVersion: 6 },
17
- { value: 'ffffffff-ffff-6fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 6 },
18
- { value: '00000000-0000-7000-8000-000000000000', expectedValidate: true, expectedVersion: 7 },
19
- { value: 'ffffffff-ffff-7fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 7 },
20
- { value: '00000000-0000-8000-8000-000000000000', expectedValidate: true, expectedVersion: 8 },
21
- { value: 'ffffffff-ffff-8fff-bfff-ffffffffffff', expectedValidate: true, expectedVersion: 8 },
22
- { value: '00000000-0000-9000-8000-000000000000', expectedValidate: false },
23
- { value: 'ffffffff-ffff-9fff-bfff-ffffffffffff', expectedValidate: false },
24
- { value: '00000000-0000-a000-8000-000000000000', expectedValidate: false },
25
- { value: 'ffffffff-ffff-afff-bfff-ffffffffffff', expectedValidate: false },
26
- { value: '00000000-0000-b000-8000-000000000000', expectedValidate: false },
27
- { value: 'ffffffff-ffff-bfff-bfff-ffffffffffff', expectedValidate: false },
28
- { value: '00000000-0000-c000-8000-000000000000', expectedValidate: false },
29
- { value: 'ffffffff-ffff-cfff-bfff-ffffffffffff', expectedValidate: false },
30
- { value: '00000000-0000-d000-8000-000000000000', expectedValidate: false },
31
- { value: 'ffffffff-ffff-dfff-bfff-ffffffffffff', expectedValidate: false },
32
- { value: '00000000-0000-e000-8000-000000000000', expectedValidate: false },
33
- { value: 'ffffffff-ffff-efff-bfff-ffffffffffff', expectedValidate: false },
34
- { value: 'd9428888-122b-11e1-b85c-61cd3cbb3210', expectedValidate: true, expectedVersion: 1 },
35
- { value: '000003e8-2363-21ef-b200-325096b39f47', expectedValidate: true, expectedVersion: 2 },
36
- { value: 'a981a0c2-68b1-35dc-bcfc-296e52ab01ec', expectedValidate: true, expectedVersion: 3 },
37
- { value: '109156be-c4fb-41ea-b1b4-efe1671c5836', expectedValidate: true, expectedVersion: 4 },
38
- { value: '90123e1c-7512-523e-bb28-76fab9f2f73d', expectedValidate: true, expectedVersion: 5 },
39
- { value: '1ef21d2f-1207-6660-8c4f-419efbd44d48', expectedValidate: true, expectedVersion: 6 },
40
- { value: '017f22e2-79b0-7cc3-98c4-dc0c0c07398f', expectedValidate: true, expectedVersion: 7 },
41
- { value: '0d8f23a0-697f-83ae-802e-48f3756dd581', expectedValidate: true, expectedVersion: 8 },
42
- { value: '00000000-0000-1000-0000-000000000000', expectedValidate: false },
43
- { value: '00000000-0000-1000-1000-000000000000', expectedValidate: false },
44
- { value: '00000000-0000-1000-2000-000000000000', expectedValidate: false },
45
- { value: '00000000-0000-1000-3000-000000000000', expectedValidate: false },
46
- { value: '00000000-0000-1000-4000-000000000000', expectedValidate: false },
47
- { value: '00000000-0000-1000-5000-000000000000', expectedValidate: false },
48
- { value: '00000000-0000-1000-6000-000000000000', expectedValidate: false },
49
- { value: '00000000-0000-1000-7000-000000000000', expectedValidate: false },
50
- { value: '00000000-0000-1000-8000-000000000000', expectedValidate: true, expectedVersion: 1 },
51
- { value: '00000000-0000-1000-9000-000000000000', expectedValidate: true, expectedVersion: 1 },
52
- { value: '00000000-0000-1000-a000-000000000000', expectedValidate: true, expectedVersion: 1 },
53
- { value: '00000000-0000-1000-b000-000000000000', expectedValidate: true, expectedVersion: 1 },
54
- { value: '00000000-0000-1000-c000-000000000000', expectedValidate: false },
55
- { value: '00000000-0000-1000-d000-000000000000', expectedValidate: false },
56
- { value: '00000000-0000-1000-e000-000000000000', expectedValidate: false },
57
- { value: '00000000-0000-1000-f000-000000000000', expectedValidate: false },
58
- { value: '00000000000000000000000000000000', expectedValidate: false },
59
- { value: '', expectedValidate: false },
60
- { value: 'invalid uuid string', expectedValidate: false },
61
- {
62
- value: '=Y00a-f*vb*-c-d#-p00f\b-g0h-#i^-j*3&-L00k-\nl---00n-fg000-00p-00r+',
63
- expectedValidate: false,
64
- },
65
- { value: undefined, expectedValidate: false },
66
- { value: null, expectedValidate: false },
67
- { value: 123, expectedValidate: false },
68
- { value: /regex/, expectedValidate: false },
69
- { value: new Date(0), expectedValidate: false },
70
- { value: false, expectedValidate: false },
71
- ];
72
- for (let charIndex = 0; charIndex < 36; charIndex++) {
73
- if (charIndex === 8 ||
74
- charIndex === 13 ||
75
- charIndex === 14 ||
76
- charIndex === 18 ||
77
- charIndex === 23) {
78
- continue;
79
- }
80
- const nilChars = NIL.split('');
81
- const maxChars = MAX.split('');
82
- for (let i = 0; i < 4; i++) {
83
- nilChars[charIndex] = (0x0 ^ (1 << i)).toString(16);
84
- TESTS.push({ value: nilChars.join(''), expectedValidate: false });
85
- maxChars[charIndex] = (0xf ^ (1 << i)).toString(16);
86
- TESTS.push({ value: maxChars.join(''), expectedValidate: false });
87
- }
88
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,125 +0,0 @@
1
- import * as assert from 'assert';
2
- import test, { describe } from 'node:test';
3
- import parse from '../parse.js';
4
- import v1, { updateV1State } from '../v1.js';
5
- const TIME = 1321644961388;
6
- const RFC_V1 = 'c232ab00-9414-11ec-b3c8-9f68deced846';
7
- const RFC_V1_BYTES = parse(RFC_V1);
8
- const RFC_OPTIONS = {
9
- msecs: 0x17f22e279b0,
10
- nsecs: 0,
11
- clockseq: 0x33c8,
12
- node: Uint8Array.of(0x9f, 0x68, 0xde, 0xce, 0xd8, 0x46),
13
- };
14
- const RFC_RANDOM = Uint8Array.of(0, 0, 0, 0, 0, 0, 0, 0, RFC_OPTIONS.clockseq >> 8, RFC_OPTIONS.clockseq & 0xff, ...RFC_OPTIONS.node);
15
- function compareV1TimeField(a, b) {
16
- a = a.split('-').slice(0, 3).reverse().join('');
17
- b = b.split('-').slice(0, 3).reverse().join('');
18
- return a < b ? -1 : a > b ? 1 : 0;
19
- }
20
- describe('v1', () => {
21
- test('v1 sort order (default)', () => {
22
- const ids = [v1(), v1(), v1(), v1(), v1()];
23
- const sorted = [...ids].sort(compareV1TimeField);
24
- assert.deepEqual(ids, sorted);
25
- });
26
- test('v1 sort order (time option)', () => {
27
- const ids = [
28
- v1({ msecs: TIME - 10 * 3600 * 1000 }),
29
- v1({ msecs: TIME - 1 }),
30
- v1({ msecs: TIME }),
31
- v1({ msecs: TIME + 1 }),
32
- v1({ msecs: TIME + 28 * 24 * 3600 * 1000 }),
33
- ];
34
- const sorted = [...ids].sort(compareV1TimeField);
35
- assert.deepEqual(ids, sorted);
36
- });
37
- test('v1(options)', () => {
38
- assert.equal(v1({ msecs: RFC_OPTIONS.msecs, random: RFC_RANDOM }), RFC_V1, 'minimal options');
39
- assert.equal(v1(RFC_OPTIONS), RFC_V1, 'full options');
40
- });
41
- test('v1(options) equality', () => {
42
- assert.notEqual(v1({ msecs: TIME }), v1({ msecs: TIME }), 'UUIDs with minimal options differ');
43
- assert.equal(v1(RFC_OPTIONS), v1(RFC_OPTIONS), 'UUIDs with full options are identical');
44
- });
45
- test('fills one UUID into a buffer as expected', () => {
46
- const buffer = new Uint8Array(16);
47
- const result = v1(RFC_OPTIONS, buffer);
48
- assert.deepEqual(buffer, RFC_V1_BYTES);
49
- assert.strictEqual(buffer, result);
50
- });
51
- test('fills two UUIDs into a buffer as expected', () => {
52
- const buffer = new Uint8Array(32);
53
- v1(RFC_OPTIONS, buffer, 0);
54
- v1(RFC_OPTIONS, buffer, 16);
55
- const expectedBuf = new Uint8Array(32);
56
- expectedBuf.set(RFC_V1_BYTES);
57
- expectedBuf.set(RFC_V1_BYTES, 16);
58
- assert.deepEqual(buffer, expectedBuf);
59
- });
60
- test('v1() state transitions', () => {
61
- const PRE_STATE = {
62
- msecs: 10,
63
- nsecs: 20,
64
- clockseq: 0x1234,
65
- node: Uint8Array.of(0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc),
66
- };
67
- const tests = [
68
- {
69
- title: 'initial state',
70
- state: {},
71
- now: 10,
72
- expected: {
73
- msecs: 10,
74
- nsecs: 0,
75
- clockseq: RFC_OPTIONS.clockseq,
76
- node: RFC_OPTIONS.node,
77
- },
78
- },
79
- {
80
- title: 'same time interval',
81
- state: { ...PRE_STATE },
82
- now: PRE_STATE.msecs,
83
- expected: {
84
- ...PRE_STATE,
85
- nsecs: 21,
86
- },
87
- },
88
- {
89
- title: 'new time interval',
90
- state: { ...PRE_STATE },
91
- now: PRE_STATE.msecs + 1,
92
- expected: {
93
- ...PRE_STATE,
94
- msecs: PRE_STATE.msecs + 1,
95
- nsecs: 0,
96
- },
97
- },
98
- {
99
- title: 'same time interval (nsecs overflow)',
100
- state: { ...PRE_STATE, nsecs: 9999 },
101
- now: PRE_STATE.msecs,
102
- expected: {
103
- ...PRE_STATE,
104
- nsecs: 0,
105
- clockseq: RFC_OPTIONS.clockseq,
106
- node: RFC_OPTIONS.node,
107
- },
108
- },
109
- {
110
- title: 'time regression',
111
- state: { ...PRE_STATE },
112
- now: PRE_STATE.msecs - 1,
113
- expected: {
114
- ...PRE_STATE,
115
- msecs: PRE_STATE.msecs - 1,
116
- clockseq: RFC_OPTIONS.clockseq,
117
- node: RFC_OPTIONS.node,
118
- },
119
- },
120
- ];
121
- for (const { title, state, now, expected } of tests) {
122
- assert.deepStrictEqual(updateV1State(state, now, RFC_RANDOM), expected, `Failed: ${title}`);
123
- }
124
- });
125
- });
@@ -1 +0,0 @@
1
- export {};
@@ -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 {};
@@ -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 {};
@@ -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 {};