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
package/README.md CHANGED
@@ -2,16 +2,15 @@
2
2
  -- This file is auto-generated from README_js.md. Changes should be made there.
3
3
  -->
4
4
 
5
-
6
5
  # uuid [![CI](https://github.com/uuidjs/uuid/workflows/CI/badge.svg)](https://github.com/uuidjs/uuid/actions?query=workflow%3ACI) [![Browser](https://github.com/uuidjs/uuid/workflows/Browser/badge.svg)](https://github.com/uuidjs/uuid/actions?query=workflow%3ABrowser)
7
6
 
8
7
  For the creation of [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html) (formally [RFC4122](https://www.rfc-editor.org/rfc/rfc4122.html)) UUIDs
9
8
 
10
9
  - **Complete** - Support for all RFC9562 UUID versions
11
- - **Cross-platform** - Support for ...
12
- - CommonJS, [ECMAScript Modules](#ecmascript-modules)
13
- - NodeJS 16+ ([LTS releases](https://github.com/nodejs/Release))
14
- - Chrome, Safari, Firefox, Edge browsers
10
+ - **Cross-platform** - Support for...
11
+ - ESM & Common JS
12
+ - [Chrome, Safari, Firefox, Edge browsers](#support)
13
+ - [NodeJS](#support)
15
14
  - [React Native / Expo](#react-native--expo)
16
15
  - **Secure** - Cryptographically-strong random values
17
16
  - **Compact** - No dependencies, [tree-shakable](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking)
@@ -117,13 +116,13 @@ Example:
117
116
  import { parse as uuidParse } from 'uuid';
118
117
 
119
118
  // Parse a UUID
120
- uuidParse('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // ⇨
121
- // Uint8Array(16) [
122
- // 110, 192, 189, 127, 17,
123
- // 192, 67, 218, 151, 94,
124
- // 42, 138, 217, 235, 174,
125
- // 11
126
- // ]
119
+ uuidParse('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // ⇨
120
+ // Uint8Array(16) [
121
+ // 110, 192, 189, 127, 17,
122
+ // 192, 67, 218, 151, 94,
123
+ // 42, 138, 217, 235, 174,
124
+ // 11
125
+ // ]
127
126
  ```
128
127
 
129
128
  ### uuid.stringify(arr[, offset])
@@ -367,7 +366,7 @@ Create an RFC version 7 (random) UUID
367
366
  | [`options.msecs = (current time)`] | RFC "timestamp" field (`Number` of milliseconds, unix epoch) |
368
367
  | [`options.random = (random)`] | `Array` of 16 random bytes (0-255) used to generate other fields, above |
369
368
  | [`options.rng`] | Alternative to `options.random`, a `Function` that returns an `Array` of 16 random bytes (0-255) |
370
- | [`options.seq = (random)`] | 32-bit sequence `Number` between 0 - 0xffffffff. This may be provided to help insure uniqueness for UUIDs generated within the same millisecond time interval. Default = random value. |
369
+ | [`options.seq = (random)`] | 32-bit sequence `Number` between 0 - 0xffffffff. This may be provided to help ensure uniqueness for UUIDs generated within the same millisecond time interval. Default = random value. |
371
370
  | [`buffer`] | `Array \| Buffer` If specified, uuid will be written here in byte-form, starting at `offset` |
372
371
  | [`offset` = 0] | `Number` Index to start writing UUID bytes in `buffer` |
373
372
  | _returns_ | UUID `String` if no `buffer` is specified, otherwise returns `buffer` |
@@ -475,14 +474,28 @@ defined by RFC9562
475
474
 
476
475
  ## `options` Handling for Timestamp UUIDs
477
476
 
478
- Prior to `uuid@11`, it was possible for `options` state to interfere with the internal state used to insure uniqueness of timestamp-based UUIDs (the `v1()`, `v6()`, and `v7()` methods). Starting with `uuid@11`, this issue has been addressed by using the presence of the `options` argument as a flag to select between two possible behaviors:
477
+ Prior to `uuid@11`, it was possible for `options` state to interfere with the internal state used to ensure uniqueness of timestamp-based UUIDs (the `v1()`, `v6()`, and `v7()` methods). Starting with `uuid@11`, this issue has been addressed by using the presence of the `options` argument as a flag to select between two possible behaviors:
479
478
 
480
479
  - Without `options`: Internal state is utilized to improve UUID uniqueness.
481
480
  - With `options`: Internal state is **NOT** used and, instead, appropriate defaults are applied as needed.
482
481
 
482
+ ## Support
483
+
484
+ **Browsers**: `uuid` [builds are tested](/uuidjs/uuid/blob/main/wdio.conf.js) against the latest version of desktop Chrome, Safari, Firefox, and Edge. Mobile versions of these same browsers are expected to work but aren't currently tested.
485
+
486
+ **Node**: `uuid` [builds are tested](https://github.com/uuidjs/uuid/blob/main/.github/workflows/ci.yml#L26-L27) against node ([LTS releases](https://github.com/nodejs/Release)), plus one prior. E.g. `node@18` is in maintainence mode, and `node@22` is the current LTS release. So `uuid` supports `node@16`-`node@22`.
487
+
488
+ **Typescript**: TS versions released within the past two years are supported. [source](https://github.com/microsoft/TypeScript/issues/49088#issuecomment-2468723715)
489
+
483
490
  ## Known issues
484
491
 
485
- ### React Native / Expo
492
+ <!-- This header is referenced as an anchor in src/rng-browser.ts -->
493
+
494
+ ### "getRandomValues() not supported"
495
+
496
+ This error occurs in environments where the standard [`crypto.getRandomValues()`](https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues) API is not supported. This issue can be resolved by adding an appropriate polyfill:
497
+
498
+ #### React Native / Expo
486
499
 
487
500
  1. Install [`react-native-get-random-values`](https://github.com/LinusU/react-native-get-random-values#readme)
488
501
  1. Import it _before_ `uuid`. Since `uuid` might also appear as a transitive dependency of some other imports it's safest to just import `react-native-get-random-values` as the very first thing in your entry point:
@@ -494,4 +507,4 @@ import { v4 as uuidv4 } from 'uuid';
494
507
 
495
508
  ---
496
509
 
497
- Markdown generated from [README_js.md](README_js.md) by <a href="https://github.com/broofa/runmd"><image height="12px" src="https://camo.githubusercontent.com/5c7c603cd1e6a43370b0a5063d457e0dabb74cf317adc7baba183acb686ee8d0/687474703a2f2f692e696d6775722e636f6d2f634a4b6f3662552e706e67" /></a>
510
+ Markdown generated from [README_js.md](README_js.md) by <a href="https://github.com/broofa/runmd"><image height="13" src="https://camo.githubusercontent.com/5c7c603cd1e6a43370b0a5063d457e0dabb74cf317adc7baba183acb686ee8d0/687474703a2f2f692e696d6775722e636f6d2f634a4b6f3662552e706e67" /></a>
package/dist/cjs/md5.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare function md5(bytes: Uint8Array): Buffer;
1
+ declare function md5(bytes: Uint8Array): Buffer<ArrayBufferLike>;
2
2
  export default md5;
@@ -1,2 +1,2 @@
1
- declare function parse(uuid: string): Uint8Array;
1
+ declare function parse(uuid: string): Uint8Array<ArrayBuffer>;
2
2
  export default parse;
package/dist/cjs/rng.d.ts CHANGED
@@ -1 +1 @@
1
- export default function rng(): Uint8Array;
1
+ export default function rng(): Uint8Array<ArrayBuffer>;
@@ -1,2 +1,2 @@
1
- declare function sha1(bytes: Uint8Array): Buffer;
1
+ declare function sha1(bytes: Uint8Array): Buffer<ArrayBufferLike>;
2
2
  export default sha1;
package/dist/cjs/v1.js CHANGED
@@ -49,10 +49,18 @@ function updateV1State(state, now, rnds) {
49
49
  return state;
50
50
  }
51
51
  function v1Bytes(rnds, msecs, nsecs, clockseq, node, buf, offset = 0) {
52
+ if (rnds.length < 16) {
53
+ throw new Error('Random bytes length must be >= 16');
54
+ }
52
55
  if (!buf) {
53
56
  buf = new Uint8Array(16);
54
57
  offset = 0;
55
58
  }
59
+ else {
60
+ if (offset < 0 || offset + 16 > buf.length) {
61
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
62
+ }
63
+ }
56
64
  msecs ??= Date.now();
57
65
  nsecs ??= 0;
58
66
  clockseq ??= ((rnds[8] << 8) | rnds[9]) & 0x3fff;
package/dist/cjs/v35.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { UUIDTypes } from './types.js';
2
- export declare function stringToBytes(str: string): Uint8Array;
2
+ export declare function stringToBytes(str: string): Uint8Array<ArrayBuffer>;
3
3
  export declare const DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
4
4
  export declare const URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
5
5
  type HashFunction = (bytes: Uint8Array) => Uint8Array;
6
- export default function v35(version: 0x30 | 0x50, hash: HashFunction, value: string | Uint8Array, namespace: UUIDTypes, buf?: Uint8Array, offset?: number): string | Uint8Array;
6
+ export default function v35(version: 0x30 | 0x50, hash: HashFunction, value: string | Uint8Array, namespace: UUIDTypes, buf?: Uint8Array, offset?: number): string | Uint8Array<ArrayBufferLike>;
7
7
  export {};
package/dist/cjs/v4.js CHANGED
@@ -8,11 +8,17 @@ function v4(options, buf, offset) {
8
8
  return native_js_1.default.randomUUID();
9
9
  }
10
10
  options = options || {};
11
- const rnds = options.random || (options.rng || rng_js_1.default)();
11
+ const rnds = options.random ?? options.rng?.() ?? (0, rng_js_1.default)();
12
+ if (rnds.length < 16) {
13
+ throw new Error('Random bytes length must be >= 16');
14
+ }
12
15
  rnds[6] = (rnds[6] & 0x0f) | 0x40;
13
16
  rnds[8] = (rnds[8] & 0x3f) | 0x80;
14
17
  if (buf) {
15
18
  offset = offset || 0;
19
+ if (offset < 0 || offset + 16 > buf.length) {
20
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
21
+ }
16
22
  for (let i = 0; i < 16; ++i) {
17
23
  buf[offset + i] = rnds[i];
18
24
  }
package/dist/cjs/v7.js CHANGED
@@ -33,10 +33,18 @@ function updateV7State(state, now, rnds) {
33
33
  return state;
34
34
  }
35
35
  function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
36
+ if (rnds.length < 16) {
37
+ throw new Error('Random bytes length must be >= 16');
38
+ }
36
39
  if (!buf) {
37
40
  buf = new Uint8Array(16);
38
41
  offset = 0;
39
42
  }
43
+ else {
44
+ if (offset < 0 || offset + 16 > buf.length) {
45
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
46
+ }
47
+ }
40
48
  msecs ??= Date.now();
41
49
  seq ??= ((rnds[6] * 0x7f) << 24) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
42
50
  buf[offset++] = (msecs / 0x10000000000) & 0xff;
@@ -1,2 +1,2 @@
1
- declare function md5(bytes: Uint8Array): Uint8Array;
1
+ declare function md5(bytes: Uint8Array): Uint8Array<ArrayBuffer>;
2
2
  export default md5;
@@ -1,2 +1,2 @@
1
- declare function parse(uuid: string): Uint8Array;
1
+ declare function parse(uuid: string): Uint8Array<ArrayBuffer>;
2
2
  export default parse;
@@ -1 +1 @@
1
- export default function rng(): Uint8Array;
1
+ export default function rng(): Uint8Array<ArrayBuffer>;
@@ -49,10 +49,18 @@ function updateV1State(state, now, rnds) {
49
49
  return state;
50
50
  }
51
51
  function v1Bytes(rnds, msecs, nsecs, clockseq, node, buf, offset = 0) {
52
+ if (rnds.length < 16) {
53
+ throw new Error('Random bytes length must be >= 16');
54
+ }
52
55
  if (!buf) {
53
56
  buf = new Uint8Array(16);
54
57
  offset = 0;
55
58
  }
59
+ else {
60
+ if (offset < 0 || offset + 16 > buf.length) {
61
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
62
+ }
63
+ }
56
64
  msecs ??= Date.now();
57
65
  nsecs ??= 0;
58
66
  clockseq ??= ((rnds[8] << 8) | rnds[9]) & 0x3fff;
@@ -1,7 +1,7 @@
1
1
  import { UUIDTypes } from './types.js';
2
- export declare function stringToBytes(str: string): Uint8Array;
2
+ export declare function stringToBytes(str: string): Uint8Array<ArrayBuffer>;
3
3
  export declare const DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
4
4
  export declare const URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
5
5
  type HashFunction = (bytes: Uint8Array) => Uint8Array;
6
- export default function v35(version: 0x30 | 0x50, hash: HashFunction, value: string | Uint8Array, namespace: UUIDTypes, buf?: Uint8Array, offset?: number): string | Uint8Array;
6
+ export default function v35(version: 0x30 | 0x50, hash: HashFunction, value: string | Uint8Array, namespace: UUIDTypes, buf?: Uint8Array, offset?: number): string | Uint8Array<ArrayBufferLike>;
7
7
  export {};
@@ -8,11 +8,17 @@ function v4(options, buf, offset) {
8
8
  return native_js_1.default.randomUUID();
9
9
  }
10
10
  options = options || {};
11
- const rnds = options.random || (options.rng || rng_js_1.default)();
11
+ const rnds = options.random ?? options.rng?.() ?? (0, rng_js_1.default)();
12
+ if (rnds.length < 16) {
13
+ throw new Error('Random bytes length must be >= 16');
14
+ }
12
15
  rnds[6] = (rnds[6] & 0x0f) | 0x40;
13
16
  rnds[8] = (rnds[8] & 0x3f) | 0x80;
14
17
  if (buf) {
15
18
  offset = offset || 0;
19
+ if (offset < 0 || offset + 16 > buf.length) {
20
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
21
+ }
16
22
  for (let i = 0; i < 16; ++i) {
17
23
  buf[offset + i] = rnds[i];
18
24
  }
@@ -33,10 +33,18 @@ function updateV7State(state, now, rnds) {
33
33
  return state;
34
34
  }
35
35
  function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
36
+ if (rnds.length < 16) {
37
+ throw new Error('Random bytes length must be >= 16');
38
+ }
36
39
  if (!buf) {
37
40
  buf = new Uint8Array(16);
38
41
  offset = 0;
39
42
  }
43
+ else {
44
+ if (offset < 0 || offset + 16 > buf.length) {
45
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
46
+ }
47
+ }
40
48
  msecs ??= Date.now();
41
49
  seq ??= ((rnds[6] * 0x7f) << 24) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
42
50
  buf[offset++] = (msecs / 0x10000000000) & 0xff;
package/dist/esm/md5.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare function md5(bytes: Uint8Array): Buffer;
1
+ declare function md5(bytes: Uint8Array): Buffer<ArrayBufferLike>;
2
2
  export default md5;
@@ -1,2 +1,2 @@
1
- declare function parse(uuid: string): Uint8Array;
1
+ declare function parse(uuid: string): Uint8Array<ArrayBuffer>;
2
2
  export default parse;
package/dist/esm/rng.d.ts CHANGED
@@ -1 +1 @@
1
- export default function rng(): Uint8Array;
1
+ export default function rng(): Uint8Array<ArrayBuffer>;
@@ -1,2 +1,2 @@
1
- declare function sha1(bytes: Uint8Array): Buffer;
1
+ declare function sha1(bytes: Uint8Array): Buffer<ArrayBufferLike>;
2
2
  export default sha1;
package/dist/esm/v1.js CHANGED
@@ -46,10 +46,18 @@ export function updateV1State(state, now, rnds) {
46
46
  return state;
47
47
  }
48
48
  function v1Bytes(rnds, msecs, nsecs, clockseq, node, buf, offset = 0) {
49
+ if (rnds.length < 16) {
50
+ throw new Error('Random bytes length must be >= 16');
51
+ }
49
52
  if (!buf) {
50
53
  buf = new Uint8Array(16);
51
54
  offset = 0;
52
55
  }
56
+ else {
57
+ if (offset < 0 || offset + 16 > buf.length) {
58
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
59
+ }
60
+ }
53
61
  msecs ??= Date.now();
54
62
  nsecs ??= 0;
55
63
  clockseq ??= ((rnds[8] << 8) | rnds[9]) & 0x3fff;
package/dist/esm/v35.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { UUIDTypes } from './types.js';
2
- export declare function stringToBytes(str: string): Uint8Array;
2
+ export declare function stringToBytes(str: string): Uint8Array<ArrayBuffer>;
3
3
  export declare const DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
4
4
  export declare const URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
5
5
  type HashFunction = (bytes: Uint8Array) => Uint8Array;
6
- export default function v35(version: 0x30 | 0x50, hash: HashFunction, value: string | Uint8Array, namespace: UUIDTypes, buf?: Uint8Array, offset?: number): string | Uint8Array;
6
+ export default function v35(version: 0x30 | 0x50, hash: HashFunction, value: string | Uint8Array, namespace: UUIDTypes, buf?: Uint8Array, offset?: number): string | Uint8Array<ArrayBufferLike>;
7
7
  export {};
package/dist/esm/v4.js CHANGED
@@ -6,11 +6,17 @@ function v4(options, buf, offset) {
6
6
  return native.randomUUID();
7
7
  }
8
8
  options = options || {};
9
- const rnds = options.random || (options.rng || rng)();
9
+ const rnds = options.random ?? options.rng?.() ?? rng();
10
+ if (rnds.length < 16) {
11
+ throw new Error('Random bytes length must be >= 16');
12
+ }
10
13
  rnds[6] = (rnds[6] & 0x0f) | 0x40;
11
14
  rnds[8] = (rnds[8] & 0x3f) | 0x80;
12
15
  if (buf) {
13
16
  offset = offset || 0;
17
+ if (offset < 0 || offset + 16 > buf.length) {
18
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
19
+ }
14
20
  for (let i = 0; i < 16; ++i) {
15
21
  buf[offset + i] = rnds[i];
16
22
  }
package/dist/esm/v7.js CHANGED
@@ -30,10 +30,18 @@ export function updateV7State(state, now, rnds) {
30
30
  return state;
31
31
  }
32
32
  function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
33
+ if (rnds.length < 16) {
34
+ throw new Error('Random bytes length must be >= 16');
35
+ }
33
36
  if (!buf) {
34
37
  buf = new Uint8Array(16);
35
38
  offset = 0;
36
39
  }
40
+ else {
41
+ if (offset < 0 || offset + 16 > buf.length) {
42
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
43
+ }
44
+ }
37
45
  msecs ??= Date.now();
38
46
  seq ??= ((rnds[6] * 0x7f) << 24) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
39
47
  buf[offset++] = (msecs / 0x10000000000) & 0xff;
@@ -1,2 +1,2 @@
1
- declare function md5(bytes: Uint8Array): Uint8Array;
1
+ declare function md5(bytes: Uint8Array): Uint8Array<ArrayBuffer>;
2
2
  export default md5;
@@ -1,2 +1,2 @@
1
- declare function parse(uuid: string): Uint8Array;
1
+ declare function parse(uuid: string): Uint8Array<ArrayBuffer>;
2
2
  export default parse;
@@ -1 +1 @@
1
- export default function rng(): Uint8Array;
1
+ export default function rng(): Uint8Array<ArrayBuffer>;
@@ -46,10 +46,18 @@ export function updateV1State(state, now, rnds) {
46
46
  return state;
47
47
  }
48
48
  function v1Bytes(rnds, msecs, nsecs, clockseq, node, buf, offset = 0) {
49
+ if (rnds.length < 16) {
50
+ throw new Error('Random bytes length must be >= 16');
51
+ }
49
52
  if (!buf) {
50
53
  buf = new Uint8Array(16);
51
54
  offset = 0;
52
55
  }
56
+ else {
57
+ if (offset < 0 || offset + 16 > buf.length) {
58
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
59
+ }
60
+ }
53
61
  msecs ??= Date.now();
54
62
  nsecs ??= 0;
55
63
  clockseq ??= ((rnds[8] << 8) | rnds[9]) & 0x3fff;
@@ -1,7 +1,7 @@
1
1
  import { UUIDTypes } from './types.js';
2
- export declare function stringToBytes(str: string): Uint8Array;
2
+ export declare function stringToBytes(str: string): Uint8Array<ArrayBuffer>;
3
3
  export declare const DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
4
4
  export declare const URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
5
5
  type HashFunction = (bytes: Uint8Array) => Uint8Array;
6
- export default function v35(version: 0x30 | 0x50, hash: HashFunction, value: string | Uint8Array, namespace: UUIDTypes, buf?: Uint8Array, offset?: number): string | Uint8Array;
6
+ export default function v35(version: 0x30 | 0x50, hash: HashFunction, value: string | Uint8Array, namespace: UUIDTypes, buf?: Uint8Array, offset?: number): string | Uint8Array<ArrayBufferLike>;
7
7
  export {};
@@ -6,11 +6,17 @@ function v4(options, buf, offset) {
6
6
  return native.randomUUID();
7
7
  }
8
8
  options = options || {};
9
- const rnds = options.random || (options.rng || rng)();
9
+ const rnds = options.random ?? options.rng?.() ?? rng();
10
+ if (rnds.length < 16) {
11
+ throw new Error('Random bytes length must be >= 16');
12
+ }
10
13
  rnds[6] = (rnds[6] & 0x0f) | 0x40;
11
14
  rnds[8] = (rnds[8] & 0x3f) | 0x80;
12
15
  if (buf) {
13
16
  offset = offset || 0;
17
+ if (offset < 0 || offset + 16 > buf.length) {
18
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
19
+ }
14
20
  for (let i = 0; i < 16; ++i) {
15
21
  buf[offset + i] = rnds[i];
16
22
  }
@@ -30,10 +30,18 @@ export function updateV7State(state, now, rnds) {
30
30
  return state;
31
31
  }
32
32
  function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
33
+ if (rnds.length < 16) {
34
+ throw new Error('Random bytes length must be >= 16');
35
+ }
33
36
  if (!buf) {
34
37
  buf = new Uint8Array(16);
35
38
  offset = 0;
36
39
  }
40
+ else {
41
+ if (offset < 0 || offset + 16 > buf.length) {
42
+ throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
43
+ }
44
+ }
37
45
  msecs ??= Date.now();
38
46
  seq ??= ((rnds[6] * 0x7f) << 24) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
39
47
  buf[offset++] = (msecs / 0x10000000000) & 0xff;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uuid",
3
- "version": "11.0.3",
3
+ "version": "11.0.4",
4
4
  "description": "RFC9562 UUIDs",
5
5
  "type": "module",
6
6
  "funding": [
@@ -44,35 +44,32 @@
44
44
  "./dist/cjs/index.js": "./dist/cjs-browser/index.js"
45
45
  },
46
46
  "files": [
47
- "CHANGELOG.md",
48
- "CONTRIBUTING.md",
49
- "LICENSE.md",
50
- "README.md",
51
- "dist"
47
+ "dist",
48
+ "!dist/**/test"
52
49
  ],
53
50
  "devDependencies": {
54
51
  "@babel/eslint-parser": "7.25.9",
55
- "@commitlint/cli": "19.5.0",
56
- "@commitlint/config-conventional": "19.5.0",
57
- "@eslint/js": "9.13.0",
52
+ "@commitlint/cli": "19.6.1",
53
+ "@commitlint/config-conventional": "19.6.0",
54
+ "@eslint/js": "9.17.0",
58
55
  "@types/eslint__js": "8.42.3",
59
56
  "bundlewatch": "0.4.0",
60
57
  "commander": "12.1.0",
61
- "eslint": "9.13.0",
58
+ "eslint": "9.17.0",
62
59
  "eslint-config-prettier": "9.1.0",
63
60
  "eslint-plugin-prettier": "5.2.1",
64
- "globals": "15.11.0",
65
- "husky": "9.1.6",
61
+ "globals": "15.14.0",
62
+ "husky": "9.1.7",
66
63
  "jest": "29.7.0",
67
- "lint-staged": "15.2.10",
68
- "neostandard": "0.11.7",
64
+ "lint-staged": "15.2.11",
65
+ "neostandard": "0.12.0",
69
66
  "npm-run-all": "4.1.5",
70
- "prettier": "3.3.3",
71
- "release-please": "16.14.3",
72
- "runmd": "1.3.9",
67
+ "prettier": "3.4.2",
68
+ "release-please": "16.15.0",
69
+ "runmd": "1.4.1",
73
70
  "standard-version": "9.5.0",
74
- "typescript": "5.6.3",
75
- "typescript-eslint": "8.11.0"
71
+ "typescript": "5.7.2",
72
+ "typescript-eslint": "8.18.2"
76
73
  },
77
74
  "optionalDevDependencies": {
78
75
  "@wdio/browserstack-service": "9.2.1",
@@ -130,5 +127,5 @@
130
127
  "postchangelog": "prettier --write CHANGELOG.md"
131
128
  }
132
129
  },
133
- "packageManager": "npm@10.9.0"
130
+ "packageManager": "npm@11.0.0"
134
131
  }