@fgv/ts-utils 5.1.0-21 → 5.1.0-23

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.
@@ -25,4 +25,5 @@ export * from './messageAggregator';
25
25
  export { Normalizer } from './normalize';
26
26
  export * from './result';
27
27
  export * from './utils';
28
+ export * from './uuid';
28
29
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './brand';\nexport * from './mapResults';\nexport * from './messageAggregator';\nexport { Normalizer } from './normalize';\nexport * from './result';\nexport * from './utils';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './brand';\nexport * from './mapResults';\nexport * from './messageAggregator';\nexport { Normalizer } from './normalize';\nexport * from './result';\nexport * from './utils';\nexport * from './uuid';\n"]}
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright (c) 2026 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ /**
23
+ * Canonical UUIDv4 format: 8-4-4-4-12 lowercase hex digits with the version
24
+ * nibble `4` in the third group and the variant nibble (8, 9, a, or b) at the
25
+ * start of the fourth group. Matches what `crypto.randomUUID()` returns.
26
+ */
27
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
28
+ /**
29
+ * Type guard that returns `true` when the input is a canonical UUIDv4 string.
30
+ * @param value - The string to test.
31
+ * @returns `true` if `value` is a canonical UUIDv4, narrowing it to {@link Uuid}.
32
+ * @public
33
+ */
34
+ export function isValidUuid(value) {
35
+ return uuidRegex.test(value);
36
+ }
37
+ /**
38
+ * Generates a cryptographically random UUIDv4 using the platform's Web Crypto
39
+ * API (`globalThis.crypto.randomUUID`). Works in Node.js \>= 18 and modern
40
+ * browsers without per-call runtime checks.
41
+ * @returns A new {@link Uuid}.
42
+ * @throws An `Error` if the runtime does not expose `globalThis.crypto.randomUUID`.
43
+ * This indicates an unsupported platform, not a per-call failure mode, so it is
44
+ * surfaced as a thrown error rather than a `Result`.
45
+ * @public
46
+ */
47
+ export function generateUuid() {
48
+ const cryptoObj = globalThis.crypto;
49
+ /* c8 ignore next 5 - all supported runtimes (node >= 18, modern browsers) expose globalThis.crypto.randomUUID */
50
+ if (typeof (cryptoObj === null || cryptoObj === void 0 ? void 0 : cryptoObj.randomUUID) !== 'function') {
51
+ throw new Error('generateUuid: globalThis.crypto.randomUUID is not available; requires Node.js >= 18 or a modern browser');
52
+ }
53
+ return cryptoObj.randomUUID();
54
+ }
55
+ //# sourceMappingURL=uuid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../../src/packlets/base/uuid.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAYH;;;;GAIG;AACH,MAAM,SAAS,GAAW,uEAAuE,CAAC;AAElG;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC;IACpC,iHAAiH;IACjH,IAAI,OAAO,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,UAAU,CAAA,KAAK,UAAU,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACb,yGAAyG,CAC1G,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC,UAAU,EAAU,CAAC;AACxC,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Brand } from './brand';\n\n/**\n * A canonical UUIDv4 string: 8-4-4-4-12 lowercase hex digits with version\n * nibble `4` and variant nibble in `[89ab]`. Produced by {@link generateUuid}\n * and validated by {@link isValidUuid}.\n * @public\n */\nexport type Uuid = Brand<string, 'Uuid'>;\n\n/**\n * Canonical UUIDv4 format: 8-4-4-4-12 lowercase hex digits with the version\n * nibble `4` in the third group and the variant nibble (8, 9, a, or b) at the\n * start of the fourth group. Matches what `crypto.randomUUID()` returns.\n */\nconst uuidRegex: RegExp = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;\n\n/**\n * Type guard that returns `true` when the input is a canonical UUIDv4 string.\n * @param value - The string to test.\n * @returns `true` if `value` is a canonical UUIDv4, narrowing it to {@link Uuid}.\n * @public\n */\nexport function isValidUuid(value: string): value is Uuid {\n return uuidRegex.test(value);\n}\n\n/**\n * Generates a cryptographically random UUIDv4 using the platform's Web Crypto\n * API (`globalThis.crypto.randomUUID`). Works in Node.js \\>= 18 and modern\n * browsers without per-call runtime checks.\n * @returns A new {@link Uuid}.\n * @throws An `Error` if the runtime does not expose `globalThis.crypto.randomUUID`.\n * This indicates an unsupported platform, not a per-call failure mode, so it is\n * surfaced as a thrown error rather than a `Result`.\n * @public\n */\nexport function generateUuid(): Uuid {\n const cryptoObj = globalThis.crypto;\n /* c8 ignore next 5 - all supported runtimes (node >= 18, modern browsers) expose globalThis.crypto.randomUUID */\n if (typeof cryptoObj?.randomUUID !== 'function') {\n throw new Error(\n 'generateUuid: globalThis.crypto.randomUUID is not available; requires Node.js >= 18 or a modern browser'\n );\n }\n return cryptoObj.randomUUID() as Uuid;\n}\n"]}
@@ -2603,6 +2603,18 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
2603
2603
  type: 'function';
2604
2604
  }
2605
2605
 
2606
+ /**
2607
+ * Generates a cryptographically random UUIDv4 using the platform's Web Crypto
2608
+ * API (`globalThis.crypto.randomUUID`). Works in Node.js \>= 18 and modern
2609
+ * browsers without per-call runtime checks.
2610
+ * @returns A new {@link Uuid}.
2611
+ * @throws An `Error` if the runtime does not expose `globalThis.crypto.randomUUID`.
2612
+ * This indicates an unsupported platform, not a per-call failure mode, so it is
2613
+ * surfaced as a thrown error rather than a `Result`.
2614
+ * @public
2615
+ */
2616
+ export declare function generateUuid(): Uuid;
2617
+
2606
2618
  /**
2607
2619
  * Helper function to create a {@link Converter | Converter} from a supplied {@link Conversion.ConverterFunc | ConverterFunc}.
2608
2620
  * @param convert - the function to be wrapped
@@ -3906,6 +3918,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
3906
3918
  */
3907
3919
  declare function isValidator<T, TC>(converterOrValidator: Converter<T, TC> | Validator<T, TC>): converterOrValidator is Validator<T, TC>;
3908
3920
 
3921
+ /**
3922
+ * Type guard that returns `true` when the input is a canonical UUIDv4 string.
3923
+ * @param value - The string to test.
3924
+ * @returns `true` if `value` is a canonical UUIDv4, narrowing it to {@link Uuid}.
3925
+ * @public
3926
+ */
3927
+ export declare function isValidUuid(value: string): value is Uuid;
3928
+
3909
3929
  /**
3910
3930
  * Parameters for constructing a {@link Collections.ValidatingCollector | ValidatingCollector}.
3911
3931
  * @public
@@ -6131,6 +6151,14 @@ declare class Collectible<TKEY extends string = string, TINDEX extends number =
6131
6151
  }
6132
6152
  }
6133
6153
 
6154
+ /**
6155
+ * A canonical UUIDv4 string: 8-4-4-4-12 lowercase hex digits with version
6156
+ * nibble `4` and variant nibble in `[89ab]`. Produced by {@link generateUuid}
6157
+ * and validated by {@link isValidUuid}.
6158
+ * @public
6159
+ */
6160
+ export declare type Uuid = Brand<string, 'Uuid'>;
6161
+
6134
6162
  /**
6135
6163
  * Helper function to create a {@link Converter | Converter} from any {@link Validation.Validator}
6136
6164
  * @param converterOrValidator - the {@link Validation.Validator} to be wrapped or {@link Converter | Converter}
@@ -4,4 +4,5 @@ export * from './messageAggregator';
4
4
  export { Normalizer } from './normalize';
5
5
  export * from './result';
6
6
  export * from './utils';
7
+ export * from './uuid';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":"AAsBA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":"AAsBA,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
@@ -43,4 +43,5 @@ var normalize_1 = require("./normalize");
43
43
  Object.defineProperty(exports, "Normalizer", { enumerable: true, get: function () { return normalize_1.Normalizer; } });
44
44
  __exportStar(require("./result"), exports);
45
45
  __exportStar(require("./utils"), exports);
46
+ __exportStar(require("./uuid"), exports);
46
47
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,+CAA6B;AAC7B,sDAAoC;AACpC,yCAAyC;AAAhC,uGAAA,UAAU,OAAA;AACnB,2CAAyB;AACzB,0CAAwB","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './brand';\nexport * from './mapResults';\nexport * from './messageAggregator';\nexport { Normalizer } from './normalize';\nexport * from './result';\nexport * from './utils';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/packlets/base/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,+CAA6B;AAC7B,sDAAoC;AACpC,yCAAyC;AAAhC,uGAAA,UAAU,OAAA;AACnB,2CAAyB;AACzB,0CAAwB;AACxB,yCAAuB","sourcesContent":["/*\n * Copyright (c) 2020 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nexport * from './brand';\nexport * from './mapResults';\nexport * from './messageAggregator';\nexport { Normalizer } from './normalize';\nexport * from './result';\nexport * from './utils';\nexport * from './uuid';\n"]}
@@ -0,0 +1,27 @@
1
+ import { Brand } from './brand';
2
+ /**
3
+ * A canonical UUIDv4 string: 8-4-4-4-12 lowercase hex digits with version
4
+ * nibble `4` and variant nibble in `[89ab]`. Produced by {@link generateUuid}
5
+ * and validated by {@link isValidUuid}.
6
+ * @public
7
+ */
8
+ export type Uuid = Brand<string, 'Uuid'>;
9
+ /**
10
+ * Type guard that returns `true` when the input is a canonical UUIDv4 string.
11
+ * @param value - The string to test.
12
+ * @returns `true` if `value` is a canonical UUIDv4, narrowing it to {@link Uuid}.
13
+ * @public
14
+ */
15
+ export declare function isValidUuid(value: string): value is Uuid;
16
+ /**
17
+ * Generates a cryptographically random UUIDv4 using the platform's Web Crypto
18
+ * API (`globalThis.crypto.randomUUID`). Works in Node.js \>= 18 and modern
19
+ * browsers without per-call runtime checks.
20
+ * @returns A new {@link Uuid}.
21
+ * @throws An `Error` if the runtime does not expose `globalThis.crypto.randomUUID`.
22
+ * This indicates an unsupported platform, not a per-call failure mode, so it is
23
+ * surfaced as a thrown error rather than a `Result`.
24
+ * @public
25
+ */
26
+ export declare function generateUuid(): Uuid;
27
+ //# sourceMappingURL=uuid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../../src/packlets/base/uuid.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AASzC;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI,CAExD;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,IAAI,IAAI,CASnC"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Erik Fortune
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in all
13
+ * copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ * SOFTWARE.
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.isValidUuid = isValidUuid;
25
+ exports.generateUuid = generateUuid;
26
+ /**
27
+ * Canonical UUIDv4 format: 8-4-4-4-12 lowercase hex digits with the version
28
+ * nibble `4` in the third group and the variant nibble (8, 9, a, or b) at the
29
+ * start of the fourth group. Matches what `crypto.randomUUID()` returns.
30
+ */
31
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
32
+ /**
33
+ * Type guard that returns `true` when the input is a canonical UUIDv4 string.
34
+ * @param value - The string to test.
35
+ * @returns `true` if `value` is a canonical UUIDv4, narrowing it to {@link Uuid}.
36
+ * @public
37
+ */
38
+ function isValidUuid(value) {
39
+ return uuidRegex.test(value);
40
+ }
41
+ /**
42
+ * Generates a cryptographically random UUIDv4 using the platform's Web Crypto
43
+ * API (`globalThis.crypto.randomUUID`). Works in Node.js \>= 18 and modern
44
+ * browsers without per-call runtime checks.
45
+ * @returns A new {@link Uuid}.
46
+ * @throws An `Error` if the runtime does not expose `globalThis.crypto.randomUUID`.
47
+ * This indicates an unsupported platform, not a per-call failure mode, so it is
48
+ * surfaced as a thrown error rather than a `Result`.
49
+ * @public
50
+ */
51
+ function generateUuid() {
52
+ const cryptoObj = globalThis.crypto;
53
+ /* c8 ignore next 5 - all supported runtimes (node >= 18, modern browsers) expose globalThis.crypto.randomUUID */
54
+ if (typeof (cryptoObj === null || cryptoObj === void 0 ? void 0 : cryptoObj.randomUUID) !== 'function') {
55
+ throw new Error('generateUuid: globalThis.crypto.randomUUID is not available; requires Node.js >= 18 or a modern browser');
56
+ }
57
+ return cryptoObj.randomUUID();
58
+ }
59
+ //# sourceMappingURL=uuid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../../src/packlets/base/uuid.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;AAyBH,kCAEC;AAYD,oCASC;AApCD;;;;GAIG;AACH,MAAM,SAAS,GAAW,uEAAuE,CAAC;AAElG;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,KAAa;IACvC,OAAO,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,YAAY;IAC1B,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC;IACpC,iHAAiH;IACjH,IAAI,OAAO,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,UAAU,CAAA,KAAK,UAAU,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CACb,yGAAyG,CAC1G,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC,UAAU,EAAU,CAAC;AACxC,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { Brand } from './brand';\n\n/**\n * A canonical UUIDv4 string: 8-4-4-4-12 lowercase hex digits with version\n * nibble `4` and variant nibble in `[89ab]`. Produced by {@link generateUuid}\n * and validated by {@link isValidUuid}.\n * @public\n */\nexport type Uuid = Brand<string, 'Uuid'>;\n\n/**\n * Canonical UUIDv4 format: 8-4-4-4-12 lowercase hex digits with the version\n * nibble `4` in the third group and the variant nibble (8, 9, a, or b) at the\n * start of the fourth group. Matches what `crypto.randomUUID()` returns.\n */\nconst uuidRegex: RegExp = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;\n\n/**\n * Type guard that returns `true` when the input is a canonical UUIDv4 string.\n * @param value - The string to test.\n * @returns `true` if `value` is a canonical UUIDv4, narrowing it to {@link Uuid}.\n * @public\n */\nexport function isValidUuid(value: string): value is Uuid {\n return uuidRegex.test(value);\n}\n\n/**\n * Generates a cryptographically random UUIDv4 using the platform's Web Crypto\n * API (`globalThis.crypto.randomUUID`). Works in Node.js \\>= 18 and modern\n * browsers without per-call runtime checks.\n * @returns A new {@link Uuid}.\n * @throws An `Error` if the runtime does not expose `globalThis.crypto.randomUUID`.\n * This indicates an unsupported platform, not a per-call failure mode, so it is\n * surfaced as a thrown error rather than a `Result`.\n * @public\n */\nexport function generateUuid(): Uuid {\n const cryptoObj = globalThis.crypto;\n /* c8 ignore next 5 - all supported runtimes (node >= 18, modern browsers) expose globalThis.crypto.randomUUID */\n if (typeof cryptoObj?.randomUUID !== 'function') {\n throw new Error(\n 'generateUuid: globalThis.crypto.randomUUID is not available; requires Node.js >= 18 or a modern browser'\n );\n }\n return cryptoObj.randomUUID() as Uuid;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgv/ts-utils",
3
- "version": "5.1.0-21",
3
+ "version": "5.1.0-23",
4
4
  "description": "Assorted Typescript Utilities",
5
5
  "main": "lib/index.js",
6
6
  "module": "dist/index.js",
@@ -54,8 +54,8 @@
54
54
  "@rushstack/heft-jest-plugin": "1.2.6",
55
55
  "eslint-plugin-tsdoc": "~0.5.2",
56
56
  "typedoc": "~0.28.16",
57
- "@fgv/heft-dual-rig": "5.1.0-21",
58
- "@fgv/typedoc-compact-theme": "5.1.0-21"
57
+ "@fgv/heft-dual-rig": "5.1.0-23",
58
+ "@fgv/typedoc-compact-theme": "5.1.0-23"
59
59
  },
60
60
  "repository": {
61
61
  "type": "git",