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.
- package/README.md +29 -16
- package/dist/cjs/md5.d.ts +2 -0
- package/dist/cjs/native.d.ts +1 -0
- package/dist/cjs/rng.js +1 -1
- package/dist/cjs/sha1.d.ts +2 -0
- package/dist/cjs/stringify.js +2 -1
- package/dist/cjs/v1.js +10 -1
- package/dist/cjs/v1ToV6.js +1 -1
- package/dist/cjs/v35.js +3 -3
- package/dist/cjs/v4.js +7 -1
- package/dist/cjs/v6ToV1.js +1 -1
- package/dist/cjs/v7.js +10 -1
- package/dist/cjs-browser/rng.js +1 -1
- package/dist/cjs-browser/stringify.js +2 -1
- package/dist/cjs-browser/v1.js +10 -1
- package/dist/cjs-browser/v1ToV6.js +1 -1
- package/dist/cjs-browser/v35.js +3 -3
- package/dist/cjs-browser/v4.js +7 -1
- package/dist/cjs-browser/v6ToV1.js +1 -1
- package/dist/cjs-browser/v7.js +10 -1
- package/dist/esm/md5.d.ts +2 -0
- package/dist/esm/native.d.ts +1 -0
- package/dist/esm/sha1.d.ts +2 -0
- package/dist/esm/v1.js +8 -0
- package/dist/esm/v4.js +7 -1
- package/dist/esm/v7.js +8 -0
- package/dist/esm-browser/v1.js +8 -0
- package/dist/esm-browser/v4.js +7 -1
- package/dist/esm-browser/v7.js +8 -0
- package/package.json +26 -28
- package/CHANGELOG.md +0 -335
- package/CONTRIBUTING.md +0 -18
- package/dist/cjs/test/parse.test.d.ts +0 -1
- package/dist/cjs/test/parse.test.js +0 -50
- package/dist/cjs/test/rng.test.d.ts +0 -1
- package/dist/cjs/test/rng.test.js +0 -14
- package/dist/cjs/test/stringify.test.d.ts +0 -1
- package/dist/cjs/test/stringify.test.js +0 -23
- package/dist/cjs/test/test_constants.d.ts +0 -33
- package/dist/cjs/test/test_constants.js +0 -91
- package/dist/cjs/test/v1.test.d.ts +0 -1
- package/dist/cjs/test/v1.test.js +0 -127
- package/dist/cjs/test/v35.test.d.ts +0 -1
- package/dist/cjs/test/v35.test.js +0 -143
- package/dist/cjs/test/v4.test.d.ts +0 -1
- package/dist/cjs/test/v4.test.js +0 -60
- package/dist/cjs/test/v6.test.d.ts +0 -1
- package/dist/cjs/test/v6.test.js +0 -56
- package/dist/cjs/test/v7.test.d.ts +0 -1
- package/dist/cjs/test/v7.test.js +0 -194
- package/dist/cjs/test/validate.test.d.ts +0 -1
- package/dist/cjs/test/validate.test.js +0 -13
- package/dist/cjs/test/version.test.d.ts +0 -1
- package/dist/cjs/test/version.test.js +0 -20
- package/dist/cjs-browser/test/parse.test.d.ts +0 -1
- package/dist/cjs-browser/test/parse.test.js +0 -50
- package/dist/cjs-browser/test/rng.test.d.ts +0 -1
- package/dist/cjs-browser/test/rng.test.js +0 -14
- package/dist/cjs-browser/test/stringify.test.d.ts +0 -1
- package/dist/cjs-browser/test/stringify.test.js +0 -23
- package/dist/cjs-browser/test/test_constants.d.ts +0 -33
- package/dist/cjs-browser/test/test_constants.js +0 -91
- package/dist/cjs-browser/test/v1.test.d.ts +0 -1
- package/dist/cjs-browser/test/v1.test.js +0 -127
- package/dist/cjs-browser/test/v35.test.d.ts +0 -1
- package/dist/cjs-browser/test/v35.test.js +0 -143
- package/dist/cjs-browser/test/v4.test.d.ts +0 -1
- package/dist/cjs-browser/test/v4.test.js +0 -60
- package/dist/cjs-browser/test/v6.test.d.ts +0 -1
- package/dist/cjs-browser/test/v6.test.js +0 -56
- package/dist/cjs-browser/test/v7.test.d.ts +0 -1
- package/dist/cjs-browser/test/v7.test.js +0 -194
- package/dist/cjs-browser/test/validate.test.d.ts +0 -1
- package/dist/cjs-browser/test/validate.test.js +0 -13
- package/dist/cjs-browser/test/version.test.d.ts +0 -1
- package/dist/cjs-browser/test/version.test.js +0 -20
- package/dist/esm/test/parse.test.d.ts +0 -1
- package/dist/esm/test/parse.test.js +0 -48
- package/dist/esm/test/rng.test.d.ts +0 -1
- package/dist/esm/test/rng.test.js +0 -12
- package/dist/esm/test/stringify.test.d.ts +0 -1
- package/dist/esm/test/stringify.test.js +0 -21
- package/dist/esm/test/test_constants.d.ts +0 -33
- package/dist/esm/test/test_constants.js +0 -88
- package/dist/esm/test/v1.test.d.ts +0 -1
- package/dist/esm/test/v1.test.js +0 -125
- package/dist/esm/test/v35.test.d.ts +0 -1
- package/dist/esm/test/v35.test.js +0 -141
- package/dist/esm/test/v4.test.d.ts +0 -1
- package/dist/esm/test/v4.test.js +0 -58
- package/dist/esm/test/v6.test.d.ts +0 -1
- package/dist/esm/test/v6.test.js +0 -54
- package/dist/esm/test/v7.test.d.ts +0 -1
- package/dist/esm/test/v7.test.js +0 -192
- package/dist/esm/test/validate.test.d.ts +0 -1
- package/dist/esm/test/validate.test.js +0 -11
- package/dist/esm/test/version.test.d.ts +0 -1
- package/dist/esm/test/version.test.js +0 -18
- package/dist/esm-browser/test/parse.test.d.ts +0 -1
- package/dist/esm-browser/test/parse.test.js +0 -48
- package/dist/esm-browser/test/rng.test.d.ts +0 -1
- package/dist/esm-browser/test/rng.test.js +0 -12
- package/dist/esm-browser/test/stringify.test.d.ts +0 -1
- package/dist/esm-browser/test/stringify.test.js +0 -21
- package/dist/esm-browser/test/test_constants.d.ts +0 -33
- package/dist/esm-browser/test/test_constants.js +0 -88
- package/dist/esm-browser/test/v1.test.d.ts +0 -1
- package/dist/esm-browser/test/v1.test.js +0 -125
- package/dist/esm-browser/test/v35.test.d.ts +0 -1
- package/dist/esm-browser/test/v35.test.js +0 -141
- package/dist/esm-browser/test/v4.test.d.ts +0 -1
- package/dist/esm-browser/test/v4.test.js +0 -58
- package/dist/esm-browser/test/v6.test.d.ts +0 -1
- package/dist/esm-browser/test/v6.test.js +0 -54
- package/dist/esm-browser/test/v7.test.d.ts +0 -1
- package/dist/esm-browser/test/v7.test.js +0 -192
- package/dist/esm-browser/test/validate.test.d.ts +0 -1
- package/dist/esm-browser/test/validate.test.js +0 -11
- package/dist/esm-browser/test/version.test.d.ts +0 -1
- package/dist/esm-browser/test/version.test.js +0 -18
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 [](https://github.com/uuidjs/uuid/actions?query=workflow%3ACI) [](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
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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="
|
|
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
package/dist/cjs/native.d.ts
CHANGED
package/dist/cjs/rng.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = rng;
|
|
4
3
|
const crypto_1 = require("crypto");
|
|
5
4
|
const rnds8Pool = new Uint8Array(256);
|
|
6
5
|
let poolPtr = rnds8Pool.length;
|
|
@@ -11,3 +10,4 @@ function rng() {
|
|
|
11
10
|
}
|
|
12
11
|
return rnds8Pool.slice(poolPtr, (poolPtr += 16));
|
|
13
12
|
}
|
|
13
|
+
exports.default = rng;
|
package/dist/cjs/sha1.d.ts
CHANGED
package/dist/cjs/stringify.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unsafeStringify =
|
|
3
|
+
exports.unsafeStringify = void 0;
|
|
4
4
|
const validate_js_1 = require("./validate.js");
|
|
5
5
|
const byteToHex = [];
|
|
6
6
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -28,6 +28,7 @@ function unsafeStringify(arr, offset = 0) {
|
|
|
28
28
|
byteToHex[arr[offset + 14]] +
|
|
29
29
|
byteToHex[arr[offset + 15]]).toLowerCase();
|
|
30
30
|
}
|
|
31
|
+
exports.unsafeStringify = unsafeStringify;
|
|
31
32
|
function stringify(arr, offset = 0) {
|
|
32
33
|
const uuid = unsafeStringify(arr, offset);
|
|
33
34
|
if (!(0, validate_js_1.default)(uuid)) {
|
package/dist/cjs/v1.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateV1State =
|
|
3
|
+
exports.updateV1State = void 0;
|
|
4
4
|
const rng_js_1 = require("./rng.js");
|
|
5
5
|
const stringify_js_1 = require("./stringify.js");
|
|
6
6
|
const _state = {};
|
|
@@ -48,11 +48,20 @@ function updateV1State(state, now, rnds) {
|
|
|
48
48
|
state.msecs = now;
|
|
49
49
|
return state;
|
|
50
50
|
}
|
|
51
|
+
exports.updateV1State = updateV1State;
|
|
51
52
|
function v1Bytes(rnds, msecs, nsecs, clockseq, node, buf, offset = 0) {
|
|
53
|
+
if (rnds.length < 16) {
|
|
54
|
+
throw new Error('Random bytes length must be >= 16');
|
|
55
|
+
}
|
|
52
56
|
if (!buf) {
|
|
53
57
|
buf = new Uint8Array(16);
|
|
54
58
|
offset = 0;
|
|
55
59
|
}
|
|
60
|
+
else {
|
|
61
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
62
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
56
65
|
msecs ??= Date.now();
|
|
57
66
|
nsecs ??= 0;
|
|
58
67
|
clockseq ??= ((rnds[8] << 8) | rnds[9]) & 0x3fff;
|
package/dist/cjs/v1ToV6.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = v1ToV6;
|
|
4
3
|
const parse_js_1 = require("./parse.js");
|
|
5
4
|
const stringify_js_1 = require("./stringify.js");
|
|
6
5
|
function v1ToV6(uuid) {
|
|
@@ -8,6 +7,7 @@ function v1ToV6(uuid) {
|
|
|
8
7
|
const v6Bytes = _v1ToV6(v1Bytes);
|
|
9
8
|
return typeof uuid === 'string' ? (0, stringify_js_1.unsafeStringify)(v6Bytes) : v6Bytes;
|
|
10
9
|
}
|
|
10
|
+
exports.default = v1ToV6;
|
|
11
11
|
function _v1ToV6(v1Bytes) {
|
|
12
12
|
return Uint8Array.of(((v1Bytes[6] & 0x0f) << 4) | ((v1Bytes[7] >> 4) & 0x0f), ((v1Bytes[7] & 0x0f) << 4) | ((v1Bytes[4] & 0xf0) >> 4), ((v1Bytes[4] & 0x0f) << 4) | ((v1Bytes[5] & 0xf0) >> 4), ((v1Bytes[5] & 0x0f) << 4) | ((v1Bytes[0] & 0xf0) >> 4), ((v1Bytes[0] & 0x0f) << 4) | ((v1Bytes[1] & 0xf0) >> 4), ((v1Bytes[1] & 0x0f) << 4) | ((v1Bytes[2] & 0xf0) >> 4), 0x60 | (v1Bytes[2] & 0x0f), v1Bytes[3], v1Bytes[8], v1Bytes[9], v1Bytes[10], v1Bytes[11], v1Bytes[12], v1Bytes[13], v1Bytes[14], v1Bytes[15]);
|
|
13
13
|
}
|
package/dist/cjs/v35.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.URL = exports.DNS = void 0;
|
|
4
|
-
exports.stringToBytes = stringToBytes;
|
|
5
|
-
exports.default = v35;
|
|
3
|
+
exports.URL = exports.DNS = exports.stringToBytes = void 0;
|
|
6
4
|
const parse_js_1 = require("./parse.js");
|
|
7
5
|
const stringify_js_1 = require("./stringify.js");
|
|
8
6
|
function stringToBytes(str) {
|
|
@@ -13,6 +11,7 @@ function stringToBytes(str) {
|
|
|
13
11
|
}
|
|
14
12
|
return bytes;
|
|
15
13
|
}
|
|
14
|
+
exports.stringToBytes = stringToBytes;
|
|
16
15
|
exports.DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
17
16
|
exports.URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
|
|
18
17
|
function v35(version, hash, value, namespace, buf, offset) {
|
|
@@ -39,3 +38,4 @@ function v35(version, hash, value, namespace, buf, offset) {
|
|
|
39
38
|
}
|
|
40
39
|
return (0, stringify_js_1.unsafeStringify)(bytes);
|
|
41
40
|
}
|
|
41
|
+
exports.default = v35;
|
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
|
|
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/v6ToV1.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = v6ToV1;
|
|
4
3
|
const parse_js_1 = require("./parse.js");
|
|
5
4
|
const stringify_js_1 = require("./stringify.js");
|
|
6
5
|
function v6ToV1(uuid) {
|
|
@@ -8,6 +7,7 @@ function v6ToV1(uuid) {
|
|
|
8
7
|
const v1Bytes = _v6ToV1(v6Bytes);
|
|
9
8
|
return typeof uuid === 'string' ? (0, stringify_js_1.unsafeStringify)(v1Bytes) : v1Bytes;
|
|
10
9
|
}
|
|
10
|
+
exports.default = v6ToV1;
|
|
11
11
|
function _v6ToV1(v6Bytes) {
|
|
12
12
|
return Uint8Array.of(((v6Bytes[3] & 0x0f) << 4) | ((v6Bytes[4] >> 4) & 0x0f), ((v6Bytes[4] & 0x0f) << 4) | ((v6Bytes[5] & 0xf0) >> 4), ((v6Bytes[5] & 0x0f) << 4) | (v6Bytes[6] & 0x0f), v6Bytes[7], ((v6Bytes[1] & 0x0f) << 4) | ((v6Bytes[2] & 0xf0) >> 4), ((v6Bytes[2] & 0x0f) << 4) | ((v6Bytes[3] & 0xf0) >> 4), 0x10 | ((v6Bytes[0] & 0xf0) >> 4), ((v6Bytes[0] & 0x0f) << 4) | ((v6Bytes[1] & 0xf0) >> 4), v6Bytes[8], v6Bytes[9], v6Bytes[10], v6Bytes[11], v6Bytes[12], v6Bytes[13], v6Bytes[14], v6Bytes[15]);
|
|
13
13
|
}
|
package/dist/cjs/v7.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateV7State =
|
|
3
|
+
exports.updateV7State = void 0;
|
|
4
4
|
const rng_js_1 = require("./rng.js");
|
|
5
5
|
const stringify_js_1 = require("./stringify.js");
|
|
6
6
|
const _state = {};
|
|
@@ -32,11 +32,20 @@ function updateV7State(state, now, rnds) {
|
|
|
32
32
|
}
|
|
33
33
|
return state;
|
|
34
34
|
}
|
|
35
|
+
exports.updateV7State = updateV7State;
|
|
35
36
|
function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
|
|
37
|
+
if (rnds.length < 16) {
|
|
38
|
+
throw new Error('Random bytes length must be >= 16');
|
|
39
|
+
}
|
|
36
40
|
if (!buf) {
|
|
37
41
|
buf = new Uint8Array(16);
|
|
38
42
|
offset = 0;
|
|
39
43
|
}
|
|
44
|
+
else {
|
|
45
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
46
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
40
49
|
msecs ??= Date.now();
|
|
41
50
|
seq ??= ((rnds[6] * 0x7f) << 24) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
|
|
42
51
|
buf[offset++] = (msecs / 0x10000000000) & 0xff;
|
package/dist/cjs-browser/rng.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = rng;
|
|
4
3
|
let getRandomValues;
|
|
5
4
|
const rnds8 = new Uint8Array(16);
|
|
6
5
|
function rng() {
|
|
@@ -12,3 +11,4 @@ function rng() {
|
|
|
12
11
|
}
|
|
13
12
|
return getRandomValues(rnds8);
|
|
14
13
|
}
|
|
14
|
+
exports.default = rng;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unsafeStringify =
|
|
3
|
+
exports.unsafeStringify = void 0;
|
|
4
4
|
const validate_js_1 = require("./validate.js");
|
|
5
5
|
const byteToHex = [];
|
|
6
6
|
for (let i = 0; i < 256; ++i) {
|
|
@@ -28,6 +28,7 @@ function unsafeStringify(arr, offset = 0) {
|
|
|
28
28
|
byteToHex[arr[offset + 14]] +
|
|
29
29
|
byteToHex[arr[offset + 15]]).toLowerCase();
|
|
30
30
|
}
|
|
31
|
+
exports.unsafeStringify = unsafeStringify;
|
|
31
32
|
function stringify(arr, offset = 0) {
|
|
32
33
|
const uuid = unsafeStringify(arr, offset);
|
|
33
34
|
if (!(0, validate_js_1.default)(uuid)) {
|
package/dist/cjs-browser/v1.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateV1State =
|
|
3
|
+
exports.updateV1State = void 0;
|
|
4
4
|
const rng_js_1 = require("./rng.js");
|
|
5
5
|
const stringify_js_1 = require("./stringify.js");
|
|
6
6
|
const _state = {};
|
|
@@ -48,11 +48,20 @@ function updateV1State(state, now, rnds) {
|
|
|
48
48
|
state.msecs = now;
|
|
49
49
|
return state;
|
|
50
50
|
}
|
|
51
|
+
exports.updateV1State = updateV1State;
|
|
51
52
|
function v1Bytes(rnds, msecs, nsecs, clockseq, node, buf, offset = 0) {
|
|
53
|
+
if (rnds.length < 16) {
|
|
54
|
+
throw new Error('Random bytes length must be >= 16');
|
|
55
|
+
}
|
|
52
56
|
if (!buf) {
|
|
53
57
|
buf = new Uint8Array(16);
|
|
54
58
|
offset = 0;
|
|
55
59
|
}
|
|
60
|
+
else {
|
|
61
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
62
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
56
65
|
msecs ??= Date.now();
|
|
57
66
|
nsecs ??= 0;
|
|
58
67
|
clockseq ??= ((rnds[8] << 8) | rnds[9]) & 0x3fff;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = v1ToV6;
|
|
4
3
|
const parse_js_1 = require("./parse.js");
|
|
5
4
|
const stringify_js_1 = require("./stringify.js");
|
|
6
5
|
function v1ToV6(uuid) {
|
|
@@ -8,6 +7,7 @@ function v1ToV6(uuid) {
|
|
|
8
7
|
const v6Bytes = _v1ToV6(v1Bytes);
|
|
9
8
|
return typeof uuid === 'string' ? (0, stringify_js_1.unsafeStringify)(v6Bytes) : v6Bytes;
|
|
10
9
|
}
|
|
10
|
+
exports.default = v1ToV6;
|
|
11
11
|
function _v1ToV6(v1Bytes) {
|
|
12
12
|
return Uint8Array.of(((v1Bytes[6] & 0x0f) << 4) | ((v1Bytes[7] >> 4) & 0x0f), ((v1Bytes[7] & 0x0f) << 4) | ((v1Bytes[4] & 0xf0) >> 4), ((v1Bytes[4] & 0x0f) << 4) | ((v1Bytes[5] & 0xf0) >> 4), ((v1Bytes[5] & 0x0f) << 4) | ((v1Bytes[0] & 0xf0) >> 4), ((v1Bytes[0] & 0x0f) << 4) | ((v1Bytes[1] & 0xf0) >> 4), ((v1Bytes[1] & 0x0f) << 4) | ((v1Bytes[2] & 0xf0) >> 4), 0x60 | (v1Bytes[2] & 0x0f), v1Bytes[3], v1Bytes[8], v1Bytes[9], v1Bytes[10], v1Bytes[11], v1Bytes[12], v1Bytes[13], v1Bytes[14], v1Bytes[15]);
|
|
13
13
|
}
|
package/dist/cjs-browser/v35.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.URL = exports.DNS = void 0;
|
|
4
|
-
exports.stringToBytes = stringToBytes;
|
|
5
|
-
exports.default = v35;
|
|
3
|
+
exports.URL = exports.DNS = exports.stringToBytes = void 0;
|
|
6
4
|
const parse_js_1 = require("./parse.js");
|
|
7
5
|
const stringify_js_1 = require("./stringify.js");
|
|
8
6
|
function stringToBytes(str) {
|
|
@@ -13,6 +11,7 @@ function stringToBytes(str) {
|
|
|
13
11
|
}
|
|
14
12
|
return bytes;
|
|
15
13
|
}
|
|
14
|
+
exports.stringToBytes = stringToBytes;
|
|
16
15
|
exports.DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
|
|
17
16
|
exports.URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
|
|
18
17
|
function v35(version, hash, value, namespace, buf, offset) {
|
|
@@ -39,3 +38,4 @@ function v35(version, hash, value, namespace, buf, offset) {
|
|
|
39
38
|
}
|
|
40
39
|
return (0, stringify_js_1.unsafeStringify)(bytes);
|
|
41
40
|
}
|
|
41
|
+
exports.default = v35;
|
package/dist/cjs-browser/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
|
|
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
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = v6ToV1;
|
|
4
3
|
const parse_js_1 = require("./parse.js");
|
|
5
4
|
const stringify_js_1 = require("./stringify.js");
|
|
6
5
|
function v6ToV1(uuid) {
|
|
@@ -8,6 +7,7 @@ function v6ToV1(uuid) {
|
|
|
8
7
|
const v1Bytes = _v6ToV1(v6Bytes);
|
|
9
8
|
return typeof uuid === 'string' ? (0, stringify_js_1.unsafeStringify)(v1Bytes) : v1Bytes;
|
|
10
9
|
}
|
|
10
|
+
exports.default = v6ToV1;
|
|
11
11
|
function _v6ToV1(v6Bytes) {
|
|
12
12
|
return Uint8Array.of(((v6Bytes[3] & 0x0f) << 4) | ((v6Bytes[4] >> 4) & 0x0f), ((v6Bytes[4] & 0x0f) << 4) | ((v6Bytes[5] & 0xf0) >> 4), ((v6Bytes[5] & 0x0f) << 4) | (v6Bytes[6] & 0x0f), v6Bytes[7], ((v6Bytes[1] & 0x0f) << 4) | ((v6Bytes[2] & 0xf0) >> 4), ((v6Bytes[2] & 0x0f) << 4) | ((v6Bytes[3] & 0xf0) >> 4), 0x10 | ((v6Bytes[0] & 0xf0) >> 4), ((v6Bytes[0] & 0x0f) << 4) | ((v6Bytes[1] & 0xf0) >> 4), v6Bytes[8], v6Bytes[9], v6Bytes[10], v6Bytes[11], v6Bytes[12], v6Bytes[13], v6Bytes[14], v6Bytes[15]);
|
|
13
13
|
}
|
package/dist/cjs-browser/v7.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateV7State =
|
|
3
|
+
exports.updateV7State = void 0;
|
|
4
4
|
const rng_js_1 = require("./rng.js");
|
|
5
5
|
const stringify_js_1 = require("./stringify.js");
|
|
6
6
|
const _state = {};
|
|
@@ -32,11 +32,20 @@ function updateV7State(state, now, rnds) {
|
|
|
32
32
|
}
|
|
33
33
|
return state;
|
|
34
34
|
}
|
|
35
|
+
exports.updateV7State = updateV7State;
|
|
35
36
|
function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
|
|
37
|
+
if (rnds.length < 16) {
|
|
38
|
+
throw new Error('Random bytes length must be >= 16');
|
|
39
|
+
}
|
|
36
40
|
if (!buf) {
|
|
37
41
|
buf = new Uint8Array(16);
|
|
38
42
|
offset = 0;
|
|
39
43
|
}
|
|
44
|
+
else {
|
|
45
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
46
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
40
49
|
msecs ??= Date.now();
|
|
41
50
|
seq ??= ((rnds[6] * 0x7f) << 24) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
|
|
42
51
|
buf[offset++] = (msecs / 0x10000000000) & 0xff;
|
package/dist/esm/md5.d.ts
CHANGED
package/dist/esm/native.d.ts
CHANGED
package/dist/esm/sha1.d.ts
CHANGED
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/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
|
|
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;
|
package/dist/esm-browser/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-browser/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
|
|
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-browser/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;
|