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.
Files changed (122) hide show
  1. package/README.md +29 -16
  2. package/dist/cjs/md5.d.ts +1 -1
  3. package/dist/cjs/parse.d.ts +1 -1
  4. package/dist/cjs/rng.d.ts +1 -1
  5. package/dist/cjs/sha1.d.ts +1 -1
  6. package/dist/cjs/v1.js +8 -0
  7. package/dist/cjs/v35.d.ts +2 -2
  8. package/dist/cjs/v4.js +7 -1
  9. package/dist/cjs/v7.js +8 -0
  10. package/dist/cjs-browser/md5.d.ts +1 -1
  11. package/dist/cjs-browser/parse.d.ts +1 -1
  12. package/dist/cjs-browser/rng.d.ts +1 -1
  13. package/dist/cjs-browser/v1.js +8 -0
  14. package/dist/cjs-browser/v35.d.ts +2 -2
  15. package/dist/cjs-browser/v4.js +7 -1
  16. package/dist/cjs-browser/v7.js +8 -0
  17. package/dist/esm/md5.d.ts +1 -1
  18. package/dist/esm/parse.d.ts +1 -1
  19. package/dist/esm/rng.d.ts +1 -1
  20. package/dist/esm/sha1.d.ts +1 -1
  21. package/dist/esm/v1.js +8 -0
  22. package/dist/esm/v35.d.ts +2 -2
  23. package/dist/esm/v4.js +7 -1
  24. package/dist/esm/v7.js +8 -0
  25. package/dist/esm-browser/md5.d.ts +1 -1
  26. package/dist/esm-browser/parse.d.ts +1 -1
  27. package/dist/esm-browser/rng.d.ts +1 -1
  28. package/dist/esm-browser/v1.js +8 -0
  29. package/dist/esm-browser/v35.d.ts +2 -2
  30. package/dist/esm-browser/v4.js +7 -1
  31. package/dist/esm-browser/v7.js +8 -0
  32. package/package.json +17 -20
  33. package/CHANGELOG.md +0 -335
  34. package/CONTRIBUTING.md +0 -18
  35. package/dist/cjs/test/parse.test.d.ts +0 -1
  36. package/dist/cjs/test/parse.test.js +0 -50
  37. package/dist/cjs/test/rng.test.d.ts +0 -1
  38. package/dist/cjs/test/rng.test.js +0 -14
  39. package/dist/cjs/test/stringify.test.d.ts +0 -1
  40. package/dist/cjs/test/stringify.test.js +0 -23
  41. package/dist/cjs/test/test_constants.d.ts +0 -33
  42. package/dist/cjs/test/test_constants.js +0 -91
  43. package/dist/cjs/test/v1.test.d.ts +0 -1
  44. package/dist/cjs/test/v1.test.js +0 -127
  45. package/dist/cjs/test/v35.test.d.ts +0 -1
  46. package/dist/cjs/test/v35.test.js +0 -143
  47. package/dist/cjs/test/v4.test.d.ts +0 -1
  48. package/dist/cjs/test/v4.test.js +0 -60
  49. package/dist/cjs/test/v6.test.d.ts +0 -1
  50. package/dist/cjs/test/v6.test.js +0 -56
  51. package/dist/cjs/test/v7.test.d.ts +0 -1
  52. package/dist/cjs/test/v7.test.js +0 -194
  53. package/dist/cjs/test/validate.test.d.ts +0 -1
  54. package/dist/cjs/test/validate.test.js +0 -13
  55. package/dist/cjs/test/version.test.d.ts +0 -1
  56. package/dist/cjs/test/version.test.js +0 -20
  57. package/dist/cjs-browser/test/parse.test.d.ts +0 -1
  58. package/dist/cjs-browser/test/parse.test.js +0 -50
  59. package/dist/cjs-browser/test/rng.test.d.ts +0 -1
  60. package/dist/cjs-browser/test/rng.test.js +0 -14
  61. package/dist/cjs-browser/test/stringify.test.d.ts +0 -1
  62. package/dist/cjs-browser/test/stringify.test.js +0 -23
  63. package/dist/cjs-browser/test/test_constants.d.ts +0 -33
  64. package/dist/cjs-browser/test/test_constants.js +0 -91
  65. package/dist/cjs-browser/test/v1.test.d.ts +0 -1
  66. package/dist/cjs-browser/test/v1.test.js +0 -127
  67. package/dist/cjs-browser/test/v35.test.d.ts +0 -1
  68. package/dist/cjs-browser/test/v35.test.js +0 -143
  69. package/dist/cjs-browser/test/v4.test.d.ts +0 -1
  70. package/dist/cjs-browser/test/v4.test.js +0 -60
  71. package/dist/cjs-browser/test/v6.test.d.ts +0 -1
  72. package/dist/cjs-browser/test/v6.test.js +0 -56
  73. package/dist/cjs-browser/test/v7.test.d.ts +0 -1
  74. package/dist/cjs-browser/test/v7.test.js +0 -194
  75. package/dist/cjs-browser/test/validate.test.d.ts +0 -1
  76. package/dist/cjs-browser/test/validate.test.js +0 -13
  77. package/dist/cjs-browser/test/version.test.d.ts +0 -1
  78. package/dist/cjs-browser/test/version.test.js +0 -20
  79. package/dist/esm/test/parse.test.d.ts +0 -1
  80. package/dist/esm/test/parse.test.js +0 -48
  81. package/dist/esm/test/rng.test.d.ts +0 -1
  82. package/dist/esm/test/rng.test.js +0 -12
  83. package/dist/esm/test/stringify.test.d.ts +0 -1
  84. package/dist/esm/test/stringify.test.js +0 -21
  85. package/dist/esm/test/test_constants.d.ts +0 -33
  86. package/dist/esm/test/test_constants.js +0 -88
  87. package/dist/esm/test/v1.test.d.ts +0 -1
  88. package/dist/esm/test/v1.test.js +0 -125
  89. package/dist/esm/test/v35.test.d.ts +0 -1
  90. package/dist/esm/test/v35.test.js +0 -141
  91. package/dist/esm/test/v4.test.d.ts +0 -1
  92. package/dist/esm/test/v4.test.js +0 -58
  93. package/dist/esm/test/v6.test.d.ts +0 -1
  94. package/dist/esm/test/v6.test.js +0 -54
  95. package/dist/esm/test/v7.test.d.ts +0 -1
  96. package/dist/esm/test/v7.test.js +0 -192
  97. package/dist/esm/test/validate.test.d.ts +0 -1
  98. package/dist/esm/test/validate.test.js +0 -11
  99. package/dist/esm/test/version.test.d.ts +0 -1
  100. package/dist/esm/test/version.test.js +0 -18
  101. package/dist/esm-browser/test/parse.test.d.ts +0 -1
  102. package/dist/esm-browser/test/parse.test.js +0 -48
  103. package/dist/esm-browser/test/rng.test.d.ts +0 -1
  104. package/dist/esm-browser/test/rng.test.js +0 -12
  105. package/dist/esm-browser/test/stringify.test.d.ts +0 -1
  106. package/dist/esm-browser/test/stringify.test.js +0 -21
  107. package/dist/esm-browser/test/test_constants.d.ts +0 -33
  108. package/dist/esm-browser/test/test_constants.js +0 -88
  109. package/dist/esm-browser/test/v1.test.d.ts +0 -1
  110. package/dist/esm-browser/test/v1.test.js +0 -125
  111. package/dist/esm-browser/test/v35.test.d.ts +0 -1
  112. package/dist/esm-browser/test/v35.test.js +0 -141
  113. package/dist/esm-browser/test/v4.test.d.ts +0 -1
  114. package/dist/esm-browser/test/v4.test.js +0 -58
  115. package/dist/esm-browser/test/v6.test.d.ts +0 -1
  116. package/dist/esm-browser/test/v6.test.js +0 -54
  117. package/dist/esm-browser/test/v7.test.d.ts +0 -1
  118. package/dist/esm-browser/test/v7.test.js +0 -192
  119. package/dist/esm-browser/test/validate.test.d.ts +0 -1
  120. package/dist/esm-browser/test/validate.test.js +0 -11
  121. package/dist/esm-browser/test/version.test.d.ts +0 -1
  122. package/dist/esm-browser/test/version.test.js +0 -18
@@ -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 {};
@@ -1,143 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const node_test_1 = require("node:test");
5
- const md5_js_1 = require("../md5.js");
6
- const sha1_js_1 = require("../sha1.js");
7
- const v3_js_1 = require("../v3.js");
8
- const v35_js_1 = require("../v35.js");
9
- const v5_js_1 = require("../v5.js");
10
- (0, node_test_1.describe)('v35', () => {
11
- const HASH_SAMPLES = [
12
- {
13
- input: (0, v35_js_1.stringToBytes)(''),
14
- sha1: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
15
- md5: 'd41d8cd98f00b204e9800998ecf8427e',
16
- },
17
- {
18
- input: (0, v35_js_1.stringToBytes)('\t\b\f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u00A1\u00A2\u00A3\u00A4\u00A5\u00A6\u00A7\u00A8\u00A9\u00AA\u00AB\u00AC\u00AE\u00AF\u00B0\u00B1\u00B2\u00B3\u00B4\u00B5\u00B6\u00B7\u00B8\u00B9\u00BA\u00BB\u00BC\u00BD\u00BE\u00BF\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5\u00C6\u00C7\u00C8\u00C9\u00CA\u00CB\u00CC\u00CD\u00CE\u00CF\u00D0\u00D1\u00D2\u00D3\u00D4\u00D5\u00D6\u00D7\u00D8\u00D9\u00DA\u00DB\u00DC\u00DD\u00DE\u00DF\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u00E6\u00E7\u00E8\u00E9\u00EA\u00EB\u00EC\u00ED\u00EE\u00EF\u00F0\u00F1\u00F2\u00F3\u00F4\u00F5\u00F6\u00F7\u00F8\u00F9\u00FA\u00FB\u00FC\u00FD\u00FE\u00FF'),
19
- sha1: 'ca4a426a3d536f14cfd79011e79e10d64de950a0',
20
- md5: 'e8098ec21950f841731d28749129d3ee',
21
- },
22
- {
23
- input: (0, v35_js_1.stringToBytes)('\u00A5\u0104\u018F\u0256\u02B1o\u0315\u038E\u0409\u0500\u0531\u05E1\u05B6\u0920\u0903\u09A4\u0983\u0A20\u0A02\u0AA0\u0A83\u0B06\u0C05\u0C03\u1401\u16A0'),
24
- sha1: 'f2753ebc390e5f637e333c2a4179644a93ae9f65',
25
- md5: '231b309e277b6be8bb3d6c688b7f098b',
26
- },
27
- ];
28
- function hashToHex(hash) {
29
- const chars = new Array(hash.length);
30
- for (let i = 0; i < hash.length; i++) {
31
- chars[i] = hash[i].toString(16).padStart(2, '0');
32
- }
33
- return chars.join('');
34
- }
35
- HASH_SAMPLES.forEach(function (sample, i) {
36
- (0, node_test_1.default)(`sha1(node) HASH_SAMPLES[${i}]`, () => {
37
- assert.equal(hashToHex((0, sha1_js_1.default)(sample.input)), sample.sha1);
38
- });
39
- });
40
- HASH_SAMPLES.forEach(function (sample, i) {
41
- (0, node_test_1.default)(`md5(node) HASH_SAMPLES[${i}]`, () => {
42
- assert.equal(hashToHex((0, md5_js_1.default)(sample.input)), sample.md5);
43
- });
44
- });
45
- (0, node_test_1.default)('v3', () => {
46
- assert.strictEqual((0, v3_js_1.default)('hello.example.com', v3_js_1.default.DNS), '9125a8dc-52ee-365b-a5aa-81b0b3681cf6');
47
- assert.strictEqual((0, v3_js_1.default)('http://example.com/hello', v3_js_1.default.URL), 'c6235813-3ba4-3801-ae84-e0a6ebb7d138');
48
- assert.strictEqual((0, v3_js_1.default)('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'), 'a981a0c2-68b1-35dc-bcfc-296e52ab01ec');
49
- });
50
- (0, node_test_1.default)('v3 namespace.toUpperCase', () => {
51
- assert.strictEqual((0, v3_js_1.default)('hello.example.com', v3_js_1.default.DNS.toUpperCase()), '9125a8dc-52ee-365b-a5aa-81b0b3681cf6');
52
- assert.strictEqual((0, v3_js_1.default)('http://example.com/hello', v3_js_1.default.URL.toUpperCase()), 'c6235813-3ba4-3801-ae84-e0a6ebb7d138');
53
- assert.strictEqual((0, v3_js_1.default)('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'.toUpperCase()), 'a981a0c2-68b1-35dc-bcfc-296e52ab01ec');
54
- });
55
- (0, node_test_1.default)('v3 namespace string validation', () => {
56
- assert.throws(() => {
57
- (0, v3_js_1.default)('hello.example.com', 'zyxwvuts-rqpo-nmlk-jihg-fedcba000000');
58
- });
59
- assert.throws(() => {
60
- (0, v3_js_1.default)('hello.example.com', 'invalid uuid value');
61
- });
62
- assert.ok((0, v3_js_1.default)('hello.example.com', '00000000-0000-0000-0000-000000000000'));
63
- });
64
- (0, node_test_1.default)('v3 namespace buffer validation', () => {
65
- assert.throws(() => {
66
- (0, v3_js_1.default)('hello.example.com', new Uint8Array(15));
67
- });
68
- assert.throws(() => {
69
- (0, v3_js_1.default)('hello.example.com', new Uint8Array(17));
70
- });
71
- assert.ok((0, v3_js_1.default)('hello.example.com', new Uint8Array(16).fill(0)));
72
- });
73
- (0, node_test_1.default)('v3 fill buffer', () => {
74
- let buf = new Uint8Array(16);
75
- const expectedUuid = Uint8Array.of(0x91, 0x25, 0xa8, 0xdc, 0x52, 0xee, 0x36, 0x5b, 0xa5, 0xaa, 0x81, 0xb0, 0xb3, 0x68, 0x1c, 0xf6);
76
- const result = (0, v3_js_1.default)('hello.example.com', v3_js_1.default.DNS, buf);
77
- assert.deepEqual(buf, expectedUuid);
78
- assert.strictEqual(result, buf);
79
- buf = new Uint8Array(19).fill(0xaa);
80
- const expectedBuf = new Uint8Array(19).fill(0xaa);
81
- expectedBuf.set(expectedUuid, 3);
82
- (0, v3_js_1.default)('hello.example.com', v3_js_1.default.DNS, buf, 3);
83
- assert.deepEqual(buf, expectedBuf);
84
- });
85
- (0, node_test_1.default)('v3 undefined/null', () => {
86
- assert.throws(() => (0, v3_js_1.default)());
87
- assert.throws(() => (0, v3_js_1.default)('hello'));
88
- assert.throws(() => (0, v3_js_1.default)('hello.example.com', undefined));
89
- assert.throws(() => (0, v3_js_1.default)('hello.example.com', null, new Uint8Array(16)));
90
- });
91
- (0, node_test_1.default)('v5', () => {
92
- assert.strictEqual((0, v5_js_1.default)('hello.example.com', v5_js_1.default.DNS), 'fdda765f-fc57-5604-a269-52a7df8164ec');
93
- assert.strictEqual((0, v5_js_1.default)('http://example.com/hello', v5_js_1.default.URL), '3bbcee75-cecc-5b56-8031-b6641c1ed1f1');
94
- assert.strictEqual((0, v5_js_1.default)('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'), '90123e1c-7512-523e-bb28-76fab9f2f73d');
95
- });
96
- (0, node_test_1.default)('v5 namespace.toUpperCase', () => {
97
- assert.strictEqual((0, v5_js_1.default)('hello.example.com', v5_js_1.default.DNS.toUpperCase()), 'fdda765f-fc57-5604-a269-52a7df8164ec');
98
- assert.strictEqual((0, v5_js_1.default)('http://example.com/hello', v5_js_1.default.URL.toUpperCase()), '3bbcee75-cecc-5b56-8031-b6641c1ed1f1');
99
- assert.strictEqual((0, v5_js_1.default)('hello', '0f5abcd1-c194-47f3-905b-2df7263a084b'.toUpperCase()), '90123e1c-7512-523e-bb28-76fab9f2f73d');
100
- });
101
- (0, node_test_1.default)('v5 namespace string validation', () => {
102
- assert.throws(() => {
103
- (0, v5_js_1.default)('hello.example.com', 'zyxwvuts-rqpo-nmlk-jihg-fedcba000000');
104
- });
105
- assert.throws(() => {
106
- (0, v5_js_1.default)('hello.example.com', 'invalid uuid value');
107
- });
108
- assert.ok((0, v5_js_1.default)('hello.example.com', '00000000-0000-0000-0000-000000000000'));
109
- });
110
- (0, node_test_1.default)('v5 namespace buffer validation', () => {
111
- assert.throws(() => {
112
- (0, v5_js_1.default)('hello.example.com', new Uint8Array(15));
113
- });
114
- assert.throws(() => {
115
- (0, v5_js_1.default)('hello.example.com', new Uint8Array(17));
116
- });
117
- assert.ok((0, v5_js_1.default)('hello.example.com', new Uint8Array(16).fill(0)));
118
- });
119
- (0, node_test_1.default)('v5 fill buffer', () => {
120
- let buf = new Uint8Array(16);
121
- const expectedUuid = Uint8Array.of(0xfd, 0xda, 0x76, 0x5f, 0xfc, 0x57, 0x56, 0x04, 0xa2, 0x69, 0x52, 0xa7, 0xdf, 0x81, 0x64, 0xec);
122
- const result = (0, v5_js_1.default)('hello.example.com', v5_js_1.default.DNS, buf);
123
- assert.deepEqual(buf, expectedUuid);
124
- assert.strictEqual(result, buf);
125
- buf = new Uint8Array(19).fill(0xaa);
126
- const expectedBuf = new Uint8Array(19).fill(0xaa);
127
- expectedBuf.set(expectedUuid, 3);
128
- (0, v5_js_1.default)('hello.example.com', v5_js_1.default.DNS, buf, 3);
129
- assert.deepEqual(buf, expectedBuf);
130
- });
131
- (0, node_test_1.default)('v5 undefined/null', () => {
132
- assert.throws(() => (0, v5_js_1.default)());
133
- assert.throws(() => (0, v5_js_1.default)('hello'));
134
- assert.throws(() => (0, v5_js_1.default)('hello.example.com', undefined));
135
- assert.throws(() => (0, v5_js_1.default)('hello.example.com', null, new Uint8Array(16)));
136
- });
137
- (0, node_test_1.default)('v3/v5 constants', () => {
138
- assert.strictEqual(v3_js_1.default.DNS, '6ba7b810-9dad-11d1-80b4-00c04fd430c8');
139
- assert.strictEqual(v3_js_1.default.URL, '6ba7b811-9dad-11d1-80b4-00c04fd430c8');
140
- assert.strictEqual(v5_js_1.default.DNS, '6ba7b810-9dad-11d1-80b4-00c04fd430c8');
141
- assert.strictEqual(v5_js_1.default.URL, '6ba7b811-9dad-11d1-80b4-00c04fd430c8');
142
- });
143
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,60 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const node_test_1 = require("node:test");
5
- const native_js_1 = require("../native.js");
6
- const v4_js_1 = require("../v4.js");
7
- const randomBytesFixture = Uint8Array.of(0x10, 0x91, 0x56, 0xbe, 0xc4, 0xfb, 0xc1, 0xea, 0x71, 0xb4, 0xef, 0xe1, 0x67, 0x1c, 0x58, 0x36);
8
- const expectedBytes = Uint8Array.of(16, 145, 86, 190, 196, 251, 65, 234, 177, 180, 239, 225, 103, 28, 88, 54);
9
- (0, node_test_1.describe)('v4', () => {
10
- (0, node_test_1.default)('subsequent UUIDs are different', () => {
11
- const id1 = (0, v4_js_1.default)();
12
- const id2 = (0, v4_js_1.default)();
13
- assert.ok(id1 !== id2);
14
- });
15
- (0, node_test_1.default)('should uses native randomUUID() if no option is passed', async () => {
16
- const mock = (await Promise.resolve().then(() => require('node:test'))).default.mock;
17
- if (!mock) {
18
- return;
19
- }
20
- const mockRandomUUID = mock.method(native_js_1.default, 'randomUUID');
21
- assert.equal(mockRandomUUID.mock.callCount(), 0);
22
- (0, v4_js_1.default)();
23
- assert.equal(mockRandomUUID.mock.callCount(), 1);
24
- mock.restoreAll();
25
- });
26
- (0, node_test_1.default)('should not use native randomUUID() if an option is passed', async () => {
27
- const mock = (await Promise.resolve().then(() => require('node:test'))).default.mock;
28
- if (!mock) {
29
- return;
30
- }
31
- const mockRandomUUID = mock.method(native_js_1.default, 'randomUUID');
32
- assert.equal(mockRandomUUID.mock.callCount(), 0);
33
- (0, v4_js_1.default)({});
34
- assert.equal(mockRandomUUID.mock.callCount(), 0);
35
- mock.restoreAll();
36
- });
37
- (0, node_test_1.default)('explicit options.random produces expected result', () => {
38
- const id = (0, v4_js_1.default)({ random: randomBytesFixture });
39
- assert.strictEqual(id, '109156be-c4fb-41ea-b1b4-efe1671c5836');
40
- });
41
- (0, node_test_1.default)('explicit options.rng produces expected result', () => {
42
- const id = (0, v4_js_1.default)({ rng: () => randomBytesFixture });
43
- assert.strictEqual(id, '109156be-c4fb-41ea-b1b4-efe1671c5836');
44
- });
45
- (0, node_test_1.default)('fills one UUID into a buffer as expected', () => {
46
- const buffer = new Uint8Array(16);
47
- const result = (0, v4_js_1.default)({ random: randomBytesFixture }, buffer);
48
- assert.deepEqual(buffer, expectedBytes);
49
- assert.strictEqual(buffer, result);
50
- });
51
- (0, node_test_1.default)('fills two UUIDs into a buffer as expected', () => {
52
- const buffer = new Uint8Array(32);
53
- (0, v4_js_1.default)({ random: randomBytesFixture }, buffer, 0);
54
- (0, v4_js_1.default)({ random: randomBytesFixture }, buffer, 16);
55
- const expectedBuf = new Uint8Array(32);
56
- expectedBuf.set(expectedBytes);
57
- expectedBuf.set(expectedBytes, 16);
58
- assert.deepEqual(buffer, expectedBuf);
59
- });
60
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const assert = require("assert");
4
- const node_test_1 = require("node:test");
5
- const v1ToV6_js_1 = require("../v1ToV6.js");
6
- const v6_js_1 = require("../v6.js");
7
- const v6ToV1_js_1 = require("../v6ToV1.js");
8
- (0, node_test_1.describe)('v6', () => {
9
- const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
10
- const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
11
- const fullOptions = {
12
- msecs: 0x133b891f705,
13
- nsecs: 0x1538,
14
- clockseq: 0x385c,
15
- node: Uint8Array.of(0x61, 0xcd, 0x3c, 0xbb, 0x32, 0x10),
16
- };
17
- const EXPECTED_BYTES = Uint8Array.of(0x1e, 0x11, 0x22, 0xbd, 0x94, 0x28, 0x68, 0x88, 0xb8, 0x5c, 0x61, 0xcd, 0x3c, 0xbb, 0x32, 0x10);
18
- (0, node_test_1.default)('default behavior', () => {
19
- const id = (0, v6_js_1.default)();
20
- assert.ok(/[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/.test(id), 'id is valid v6 UUID');
21
- });
22
- (0, node_test_1.default)('default behavior (binary type)', () => {
23
- const buffer = new Uint8Array(16);
24
- const result = (0, v6_js_1.default)(fullOptions, buffer);
25
- assert.deepEqual(buffer, EXPECTED_BYTES);
26
- assert.strictEqual(buffer, result);
27
- });
28
- (0, node_test_1.default)('all options', () => {
29
- const id = (0, v6_js_1.default)(fullOptions);
30
- assert.equal(id, '1e1122bd-9428-6888-b85c-61cd3cbb3210');
31
- });
32
- (0, node_test_1.default)('sort by creation time', () => {
33
- const ids = [];
34
- for (let i = 0; i < 5; i++) {
35
- ids.push((0, v6_js_1.default)({ msecs: i * 1000 }));
36
- }
37
- assert.deepEqual(ids, ids.slice().sort());
38
- });
39
- (0, node_test_1.default)('creating at array offset', () => {
40
- const buffer = new Uint8Array(32);
41
- (0, v6_js_1.default)(fullOptions, buffer, 0);
42
- (0, v6_js_1.default)(fullOptions, buffer, 16);
43
- const expectedBuf = new Uint8Array(32);
44
- expectedBuf.set(EXPECTED_BYTES, 0);
45
- expectedBuf.set(EXPECTED_BYTES, 16);
46
- assert.deepEqual(buffer, expectedBuf);
47
- });
48
- (0, node_test_1.default)('v1 -> v6 conversion', () => {
49
- const id = (0, v1ToV6_js_1.default)(V1_ID);
50
- assert.equal(id, V6_ID);
51
- });
52
- (0, node_test_1.default)('v6 -> v1 conversion', () => {
53
- const id = (0, v6ToV1_js_1.default)(V6_ID);
54
- assert.equal(id, V1_ID);
55
- });
56
- });
@@ -1 +0,0 @@
1
- export {};