@optique/core 1.0.0-dev.1211 → 1.0.0-dev.1215

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.
@@ -797,16 +797,9 @@ function locale(options = {}) {
797
797
  *
798
798
  * This parser validates that the input is a well-formed UUID string in the
799
799
  * standard format: `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` where each `x`
800
- * is a hexadecimal digit.
800
+ * is a hexadecimal digit. The parser can optionally restrict to specific
801
+ * UUID versions.
801
802
  *
802
- * By default, the parser enforces strict [RFC 9562] validation: it requires
803
- * a standardized version digit (1 through 8) and the RFC 9562 variant bits
804
- * (`10xx`). The nil and max UUIDs are accepted as special standard values.
805
- * Set `strict: false` to disable the default RFC 9562 version/variant
806
- * checks. An explicit {@link UuidOptions.allowedVersions} list still
807
- * constrains the version nibble even in lenient mode.
808
- *
809
- * [RFC 9562]: https://www.rfc-editor.org/rfc/rfc9562
810
803
  * @param options Configuration options for the UUID parser.
811
804
  * @returns A {@link ValueParser} that converts string input to {@link Uuid}
812
805
  * strings.
@@ -815,12 +808,9 @@ function uuid(options = {}) {
815
808
  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
816
809
  const metavar = options.metavar ?? "UUID";
817
810
  require_nonempty.ensureNonEmptyString(metavar);
818
- checkBooleanOption(options, "strict");
819
- const strict = options.strict !== false;
820
811
  const allowedVersions = options.allowedVersions != null ? Object.freeze([...options.allowedVersions]) : null;
821
812
  const invalidUuid = options.errors?.invalidUuid;
822
813
  const disallowedVersion = options.errors?.disallowedVersion;
823
- const invalidVariant = options.errors?.invalidVariant;
824
814
  return {
825
815
  $mode: "sync",
826
816
  metavar,
@@ -829,14 +819,9 @@ function uuid(options = {}) {
829
819
  success: false,
830
820
  error: invalidUuid ? typeof invalidUuid === "function" ? invalidUuid(input) : invalidUuid : require_message.message`Expected a valid UUID in format ${"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}, but got ${input}.`
831
821
  };
832
- const lower = input.toLowerCase();
833
- if (lower === "00000000-0000-0000-0000-000000000000" || lower === "ffffffff-ffff-ffff-ffff-ffffffffffff") return {
834
- success: true,
835
- value: input
836
- };
837
- const versionChar = input.charAt(14);
838
- const version = parseInt(versionChar, 16);
839
822
  if (allowedVersions != null && allowedVersions.length > 0) {
823
+ const versionChar = input.charAt(14);
824
+ const version = parseInt(versionChar, 16);
840
825
  if (!allowedVersions.includes(version)) return {
841
826
  success: false,
842
827
  error: disallowedVersion ? typeof disallowedVersion === "function" ? disallowedVersion(version, allowedVersions) : disallowedVersion : (() => {
@@ -849,25 +834,6 @@ function uuid(options = {}) {
849
834
  return require_message.message`Expected UUID version ${expectedVersions}, but got version ${version.toLocaleString("en")}.`;
850
835
  })()
851
836
  };
852
- } else if (strict && (version < 1 || version > 8)) return {
853
- success: false,
854
- error: disallowedVersion ? typeof disallowedVersion === "function" ? disallowedVersion(version, [
855
- 1,
856
- 2,
857
- 3,
858
- 4,
859
- 5,
860
- 6,
861
- 7,
862
- 8
863
- ]) : disallowedVersion : require_message.message`Expected UUID version 1 through 8, but got version ${version.toLocaleString("en")}.`
864
- };
865
- if (strict) {
866
- const variantChar = input.charAt(19).toLowerCase();
867
- if (variantChar !== "8" && variantChar !== "9" && variantChar !== "a" && variantChar !== "b") return {
868
- success: false,
869
- error: invalidVariant ? typeof invalidVariant === "function" ? invalidVariant(input) : invalidVariant : require_message.message`Expected RFC 9562 variant (8, 9, a, or b at position 20), but got ${variantChar} in ${input}.`
870
- };
871
837
  }
872
838
  return {
873
839
  success: true,
@@ -563,33 +563,9 @@ interface UuidOptions {
563
563
  /**
564
564
  * List of allowed UUID versions (e.g., `[4, 5]` for UUIDs version 4 and 5).
565
565
  * If specified, the parser will validate that the UUID matches one of the
566
- * allowed versions. If not specified, the accepted versions depend on
567
- * the {@link strict} option.
566
+ * allowed versions. If not specified, any valid UUID format is accepted.
568
567
  */
569
568
  readonly allowedVersions?: readonly number[];
570
- /**
571
- * Whether to enforce strict [RFC 9562] validation. When `true` (the
572
- * default), the parser validates that the version digit is one of the
573
- * currently standardized versions (1 through 8) and that the variant bits
574
- * follow the RFC 9562 layout (`10xx`, i.e., hex digits `8`, `9`, `a`,
575
- * or `b` at position 20 of the UUID string).
576
- *
577
- * The nil UUID (`00000000-0000-0000-0000-000000000000`) and max UUID
578
- * (`ffffffff-ffff-ffff-ffff-ffffffffffff`) are accepted as special
579
- * standard values regardless of this setting.
580
- *
581
- * When `false`, the parser only validates the UUID format without
582
- * checking version or variant fields.
583
- *
584
- * When {@link allowedVersions} is provided, it takes precedence over the
585
- * strict version check, but variant bit validation still applies if
586
- * `strict` is `true`.
587
- *
588
- * [RFC 9562]: https://www.rfc-editor.org/rfc/rfc9562
589
- * @default true
590
- * @since 1.0.0
591
- */
592
- readonly strict?: boolean;
593
569
  /**
594
570
  * Custom error messages for UUID parsing failures.
595
571
  * @since 0.5.0
@@ -607,12 +583,6 @@ interface UuidOptions {
607
583
  * @since 0.5.0
608
584
  */
609
585
  disallowedVersion?: Message | ((version: number, allowedVersions: readonly number[]) => Message);
610
- /**
611
- * Custom error message when UUID variant bits are not RFC 9562 compliant.
612
- * Can be a static message or a function that receives the input.
613
- * @since 1.0.0
614
- */
615
- invalidVariant?: Message | ((input: string) => Message);
616
586
  };
617
587
  }
618
588
  /**
@@ -620,16 +590,9 @@ interface UuidOptions {
620
590
  *
621
591
  * This parser validates that the input is a well-formed UUID string in the
622
592
  * standard format: `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` where each `x`
623
- * is a hexadecimal digit.
624
- *
625
- * By default, the parser enforces strict [RFC 9562] validation: it requires
626
- * a standardized version digit (1 through 8) and the RFC 9562 variant bits
627
- * (`10xx`). The nil and max UUIDs are accepted as special standard values.
628
- * Set `strict: false` to disable the default RFC 9562 version/variant
629
- * checks. An explicit {@link UuidOptions.allowedVersions} list still
630
- * constrains the version nibble even in lenient mode.
593
+ * is a hexadecimal digit. The parser can optionally restrict to specific
594
+ * UUID versions.
631
595
  *
632
- * [RFC 9562]: https://www.rfc-editor.org/rfc/rfc9562
633
596
  * @param options Configuration options for the UUID parser.
634
597
  * @returns A {@link ValueParser} that converts string input to {@link Uuid}
635
598
  * strings.
@@ -563,33 +563,9 @@ interface UuidOptions {
563
563
  /**
564
564
  * List of allowed UUID versions (e.g., `[4, 5]` for UUIDs version 4 and 5).
565
565
  * If specified, the parser will validate that the UUID matches one of the
566
- * allowed versions. If not specified, the accepted versions depend on
567
- * the {@link strict} option.
566
+ * allowed versions. If not specified, any valid UUID format is accepted.
568
567
  */
569
568
  readonly allowedVersions?: readonly number[];
570
- /**
571
- * Whether to enforce strict [RFC 9562] validation. When `true` (the
572
- * default), the parser validates that the version digit is one of the
573
- * currently standardized versions (1 through 8) and that the variant bits
574
- * follow the RFC 9562 layout (`10xx`, i.e., hex digits `8`, `9`, `a`,
575
- * or `b` at position 20 of the UUID string).
576
- *
577
- * The nil UUID (`00000000-0000-0000-0000-000000000000`) and max UUID
578
- * (`ffffffff-ffff-ffff-ffff-ffffffffffff`) are accepted as special
579
- * standard values regardless of this setting.
580
- *
581
- * When `false`, the parser only validates the UUID format without
582
- * checking version or variant fields.
583
- *
584
- * When {@link allowedVersions} is provided, it takes precedence over the
585
- * strict version check, but variant bit validation still applies if
586
- * `strict` is `true`.
587
- *
588
- * [RFC 9562]: https://www.rfc-editor.org/rfc/rfc9562
589
- * @default true
590
- * @since 1.0.0
591
- */
592
- readonly strict?: boolean;
593
569
  /**
594
570
  * Custom error messages for UUID parsing failures.
595
571
  * @since 0.5.0
@@ -607,12 +583,6 @@ interface UuidOptions {
607
583
  * @since 0.5.0
608
584
  */
609
585
  disallowedVersion?: Message | ((version: number, allowedVersions: readonly number[]) => Message);
610
- /**
611
- * Custom error message when UUID variant bits are not RFC 9562 compliant.
612
- * Can be a static message or a function that receives the input.
613
- * @since 1.0.0
614
- */
615
- invalidVariant?: Message | ((input: string) => Message);
616
586
  };
617
587
  }
618
588
  /**
@@ -620,16 +590,9 @@ interface UuidOptions {
620
590
  *
621
591
  * This parser validates that the input is a well-formed UUID string in the
622
592
  * standard format: `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` where each `x`
623
- * is a hexadecimal digit.
624
- *
625
- * By default, the parser enforces strict [RFC 9562] validation: it requires
626
- * a standardized version digit (1 through 8) and the RFC 9562 variant bits
627
- * (`10xx`). The nil and max UUIDs are accepted as special standard values.
628
- * Set `strict: false` to disable the default RFC 9562 version/variant
629
- * checks. An explicit {@link UuidOptions.allowedVersions} list still
630
- * constrains the version nibble even in lenient mode.
593
+ * is a hexadecimal digit. The parser can optionally restrict to specific
594
+ * UUID versions.
631
595
  *
632
- * [RFC 9562]: https://www.rfc-editor.org/rfc/rfc9562
633
596
  * @param options Configuration options for the UUID parser.
634
597
  * @returns A {@link ValueParser} that converts string input to {@link Uuid}
635
598
  * strings.
@@ -797,16 +797,9 @@ function locale(options = {}) {
797
797
  *
798
798
  * This parser validates that the input is a well-formed UUID string in the
799
799
  * standard format: `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` where each `x`
800
- * is a hexadecimal digit.
800
+ * is a hexadecimal digit. The parser can optionally restrict to specific
801
+ * UUID versions.
801
802
  *
802
- * By default, the parser enforces strict [RFC 9562] validation: it requires
803
- * a standardized version digit (1 through 8) and the RFC 9562 variant bits
804
- * (`10xx`). The nil and max UUIDs are accepted as special standard values.
805
- * Set `strict: false` to disable the default RFC 9562 version/variant
806
- * checks. An explicit {@link UuidOptions.allowedVersions} list still
807
- * constrains the version nibble even in lenient mode.
808
- *
809
- * [RFC 9562]: https://www.rfc-editor.org/rfc/rfc9562
810
803
  * @param options Configuration options for the UUID parser.
811
804
  * @returns A {@link ValueParser} that converts string input to {@link Uuid}
812
805
  * strings.
@@ -815,12 +808,9 @@ function uuid(options = {}) {
815
808
  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
816
809
  const metavar = options.metavar ?? "UUID";
817
810
  ensureNonEmptyString(metavar);
818
- checkBooleanOption(options, "strict");
819
- const strict = options.strict !== false;
820
811
  const allowedVersions = options.allowedVersions != null ? Object.freeze([...options.allowedVersions]) : null;
821
812
  const invalidUuid = options.errors?.invalidUuid;
822
813
  const disallowedVersion = options.errors?.disallowedVersion;
823
- const invalidVariant = options.errors?.invalidVariant;
824
814
  return {
825
815
  $mode: "sync",
826
816
  metavar,
@@ -829,14 +819,9 @@ function uuid(options = {}) {
829
819
  success: false,
830
820
  error: invalidUuid ? typeof invalidUuid === "function" ? invalidUuid(input) : invalidUuid : message`Expected a valid UUID in format ${"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}, but got ${input}.`
831
821
  };
832
- const lower = input.toLowerCase();
833
- if (lower === "00000000-0000-0000-0000-000000000000" || lower === "ffffffff-ffff-ffff-ffff-ffffffffffff") return {
834
- success: true,
835
- value: input
836
- };
837
- const versionChar = input.charAt(14);
838
- const version = parseInt(versionChar, 16);
839
822
  if (allowedVersions != null && allowedVersions.length > 0) {
823
+ const versionChar = input.charAt(14);
824
+ const version = parseInt(versionChar, 16);
840
825
  if (!allowedVersions.includes(version)) return {
841
826
  success: false,
842
827
  error: disallowedVersion ? typeof disallowedVersion === "function" ? disallowedVersion(version, allowedVersions) : disallowedVersion : (() => {
@@ -849,25 +834,6 @@ function uuid(options = {}) {
849
834
  return message`Expected UUID version ${expectedVersions}, but got version ${version.toLocaleString("en")}.`;
850
835
  })()
851
836
  };
852
- } else if (strict && (version < 1 || version > 8)) return {
853
- success: false,
854
- error: disallowedVersion ? typeof disallowedVersion === "function" ? disallowedVersion(version, [
855
- 1,
856
- 2,
857
- 3,
858
- 4,
859
- 5,
860
- 6,
861
- 7,
862
- 8
863
- ]) : disallowedVersion : message`Expected UUID version 1 through 8, but got version ${version.toLocaleString("en")}.`
864
- };
865
- if (strict) {
866
- const variantChar = input.charAt(19).toLowerCase();
867
- if (variantChar !== "8" && variantChar !== "9" && variantChar !== "a" && variantChar !== "b") return {
868
- success: false,
869
- error: invalidVariant ? typeof invalidVariant === "function" ? invalidVariant(input) : invalidVariant : message`Expected RFC 9562 variant (8, 9, a, or b at position 20), but got ${variantChar} in ${input}.`
870
- };
871
837
  }
872
838
  return {
873
839
  success: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1211+c89574c4",
3
+ "version": "1.0.0-dev.1215+0665a336",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",