@optique/core 1.0.0-dev.1236 → 1.0.0-dev.1242

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/dist/doc.cjs CHANGED
@@ -79,9 +79,42 @@ function formatDocPage(programName, page, options = {}) {
79
79
  if (options.maxWidth != null) {
80
80
  const hasEntries = page.sections.some((s) => s.entries.length > 0);
81
81
  const hasContent = (msg) => Array.isArray(msg) && msg.length > 0;
82
- const needsDescColumn = hasEntries && page.sections.some((s) => s.entries.some((e) => hasContent(e.description) || options.showDefault && hasContent(e.default) || options.showChoices && hasContent(e.choices)));
83
- const minWidth = needsDescColumn ? termIndent + 4 : hasEntries ? termIndent + 1 : 1;
82
+ const needsDescColumn = hasEntries && page.sections.some((s) => s.entries.some((e) => hasContent(e.description) || options.showDefault && e.default != null || options.showChoices && e.choices != null));
83
+ let minDescWidth = 1;
84
+ if (needsDescColumn) {
85
+ if (options.showDefault && page.sections.some((s) => s.entries.some((e) => e.default != null))) {
86
+ const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
87
+ const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
88
+ const hasEmptyDefault = page.sections.some((s) => s.entries.some((e) => e.default != null && Array.isArray(e.default) && e.default.length === 0));
89
+ minDescWidth = Math.max(minDescWidth, hasEmptyDefault ? prefix.length + suffix.length : prefix.length);
90
+ }
91
+ if (options.showChoices && page.sections.some((s) => s.entries.some((e) => e.choices != null))) {
92
+ const prefix = typeof options.showChoices === "object" ? options.showChoices.prefix ?? " (" : " (";
93
+ const suffix = typeof options.showChoices === "object" ? options.showChoices.suffix ?? ")" : ")";
94
+ const label = typeof options.showChoices === "object" ? options.showChoices.label ?? "choices: " : "choices: ";
95
+ const hasEmptyChoices = page.sections.some((s) => s.entries.some((e) => e.choices != null && Array.isArray(e.choices) && e.choices.length === 0));
96
+ minDescWidth = Math.max(minDescWidth, hasEmptyChoices ? prefix.length + label.length + suffix.length : prefix.length + label.length);
97
+ }
98
+ }
99
+ const splitEntryMin = termIndent + 2 + Math.max(2, 2 * minDescWidth - 1);
100
+ const fixedEntryMin = termIndent + 2 + termWidth + minDescWidth;
101
+ const entryMin = needsDescColumn ? Math.min(splitEntryMin, fixedEntryMin) : hasEntries ? termIndent + 1 : 1;
102
+ const usageMin = page.usage != null ? 8 + programName.length : 1;
103
+ let sectionMin = 1;
104
+ if (page.examples != null) sectionMin = Math.max(sectionMin, 9);
105
+ if (page.author != null) sectionMin = Math.max(sectionMin, 7);
106
+ if (page.bugs != null) sectionMin = Math.max(sectionMin, 5);
107
+ const minWidth = Math.max(entryMin, usageMin, sectionMin);
84
108
  if (options.maxWidth < minWidth) throw new RangeError(`maxWidth must be at least ${minWidth}, got ${options.maxWidth}.`);
109
+ if (needsDescColumn && minDescWidth > 1) {
110
+ const avail = options.maxWidth - termIndent - 2;
111
+ const effTW = avail >= termWidth + 1 ? termWidth : Math.max(1, Math.floor(avail / 2));
112
+ const descW = avail - effTW;
113
+ if (descW < minDescWidth) {
114
+ const needed = termIndent + termWidth + 2 + minDescWidth;
115
+ throw new RangeError(`maxWidth must be at least ${needed}, got ${options.maxWidth}.`);
116
+ }
117
+ }
85
118
  }
86
119
  let effectiveTermWidth;
87
120
  if (options.maxWidth == null) effectiveTermWidth = termWidth;
package/dist/doc.js CHANGED
@@ -79,9 +79,42 @@ function formatDocPage(programName, page, options = {}) {
79
79
  if (options.maxWidth != null) {
80
80
  const hasEntries = page.sections.some((s) => s.entries.length > 0);
81
81
  const hasContent = (msg) => Array.isArray(msg) && msg.length > 0;
82
- const needsDescColumn = hasEntries && page.sections.some((s) => s.entries.some((e) => hasContent(e.description) || options.showDefault && hasContent(e.default) || options.showChoices && hasContent(e.choices)));
83
- const minWidth = needsDescColumn ? termIndent + 4 : hasEntries ? termIndent + 1 : 1;
82
+ const needsDescColumn = hasEntries && page.sections.some((s) => s.entries.some((e) => hasContent(e.description) || options.showDefault && e.default != null || options.showChoices && e.choices != null));
83
+ let minDescWidth = 1;
84
+ if (needsDescColumn) {
85
+ if (options.showDefault && page.sections.some((s) => s.entries.some((e) => e.default != null))) {
86
+ const prefix = typeof options.showDefault === "object" ? options.showDefault.prefix ?? " [" : " [";
87
+ const suffix = typeof options.showDefault === "object" ? options.showDefault.suffix ?? "]" : "]";
88
+ const hasEmptyDefault = page.sections.some((s) => s.entries.some((e) => e.default != null && Array.isArray(e.default) && e.default.length === 0));
89
+ minDescWidth = Math.max(minDescWidth, hasEmptyDefault ? prefix.length + suffix.length : prefix.length);
90
+ }
91
+ if (options.showChoices && page.sections.some((s) => s.entries.some((e) => e.choices != null))) {
92
+ const prefix = typeof options.showChoices === "object" ? options.showChoices.prefix ?? " (" : " (";
93
+ const suffix = typeof options.showChoices === "object" ? options.showChoices.suffix ?? ")" : ")";
94
+ const label = typeof options.showChoices === "object" ? options.showChoices.label ?? "choices: " : "choices: ";
95
+ const hasEmptyChoices = page.sections.some((s) => s.entries.some((e) => e.choices != null && Array.isArray(e.choices) && e.choices.length === 0));
96
+ minDescWidth = Math.max(minDescWidth, hasEmptyChoices ? prefix.length + label.length + suffix.length : prefix.length + label.length);
97
+ }
98
+ }
99
+ const splitEntryMin = termIndent + 2 + Math.max(2, 2 * minDescWidth - 1);
100
+ const fixedEntryMin = termIndent + 2 + termWidth + minDescWidth;
101
+ const entryMin = needsDescColumn ? Math.min(splitEntryMin, fixedEntryMin) : hasEntries ? termIndent + 1 : 1;
102
+ const usageMin = page.usage != null ? 8 + programName.length : 1;
103
+ let sectionMin = 1;
104
+ if (page.examples != null) sectionMin = Math.max(sectionMin, 9);
105
+ if (page.author != null) sectionMin = Math.max(sectionMin, 7);
106
+ if (page.bugs != null) sectionMin = Math.max(sectionMin, 5);
107
+ const minWidth = Math.max(entryMin, usageMin, sectionMin);
84
108
  if (options.maxWidth < minWidth) throw new RangeError(`maxWidth must be at least ${minWidth}, got ${options.maxWidth}.`);
109
+ if (needsDescColumn && minDescWidth > 1) {
110
+ const avail = options.maxWidth - termIndent - 2;
111
+ const effTW = avail >= termWidth + 1 ? termWidth : Math.max(1, Math.floor(avail / 2));
112
+ const descW = avail - effTW;
113
+ if (descW < minDescWidth) {
114
+ const needed = termIndent + termWidth + 2 + minDescWidth;
115
+ throw new RangeError(`maxWidth must be at least ${needed}, got ${options.maxWidth}.`);
116
+ }
117
+ }
85
118
  }
86
119
  let effectiveTermWidth;
87
120
  if (options.maxWidth == null) effectiveTermWidth = termWidth;
@@ -810,6 +810,10 @@ function locale(options = {}) {
810
810
  * @param options Configuration options for the UUID parser.
811
811
  * @returns A {@link ValueParser} that converts string input to {@link Uuid}
812
812
  * strings.
813
+ * @throws {TypeError} If any element of
814
+ * {@link UuidOptions.allowedVersions} is not an integer.
815
+ * @throws {RangeError} If any element of
816
+ * {@link UuidOptions.allowedVersions} is outside the range 1 to 8.
813
817
  */
814
818
  function uuid(options = {}) {
815
819
  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -817,7 +821,15 @@ function uuid(options = {}) {
817
821
  require_nonempty.ensureNonEmptyString(metavar);
818
822
  checkBooleanOption(options, "strict");
819
823
  const strict = options.strict !== false;
820
- const allowedVersions = options.allowedVersions != null ? Object.freeze([...options.allowedVersions]) : null;
824
+ const allowedVersions = options.allowedVersions != null ? (() => {
825
+ const unique = /* @__PURE__ */ new Set();
826
+ for (const v of options.allowedVersions) {
827
+ if (!Number.isInteger(v)) throw new TypeError(`Expected every element of allowedVersions to be an integer, but got value "${typeof v === "symbol" ? v.toString() : String(v)}" of type "${Array.isArray(v) ? "array" : v === null ? "null" : typeof v}".`);
828
+ if (v < 1 || v > 8) throw new RangeError(`Expected every element of allowedVersions to be between 1 and 8, but got: ${v}.`);
829
+ unique.add(v);
830
+ }
831
+ return Object.freeze([...unique]);
832
+ })() : null;
821
833
  const invalidUuid = options.errors?.invalidUuid;
822
834
  const disallowedVersion = options.errors?.disallowedVersion;
823
835
  const invalidVariant = options.errors?.invalidVariant;
@@ -562,9 +562,13 @@ interface UuidOptions {
562
562
  readonly metavar?: NonEmptyString;
563
563
  /**
564
564
  * List of allowed UUID versions (e.g., `[4, 5]` for UUIDs version 4 and 5).
565
+ * Each version must be an integer between 1 and 8 (the standardized
566
+ * [RFC 9562] versions). Duplicate entries are automatically removed.
565
567
  * If specified, the parser will validate that the UUID matches one of the
566
568
  * allowed versions. If not specified, the accepted versions depend on
567
569
  * the {@link strict} option.
570
+ *
571
+ * [RFC 9562]: https://www.rfc-editor.org/rfc/rfc9562
568
572
  */
569
573
  readonly allowedVersions?: readonly number[];
570
574
  /**
@@ -633,6 +637,10 @@ interface UuidOptions {
633
637
  * @param options Configuration options for the UUID parser.
634
638
  * @returns A {@link ValueParser} that converts string input to {@link Uuid}
635
639
  * strings.
640
+ * @throws {TypeError} If any element of
641
+ * {@link UuidOptions.allowedVersions} is not an integer.
642
+ * @throws {RangeError} If any element of
643
+ * {@link UuidOptions.allowedVersions} is outside the range 1 to 8.
636
644
  */
637
645
  declare function uuid(options?: UuidOptions): ValueParser<"sync", Uuid>;
638
646
  /**
@@ -562,9 +562,13 @@ interface UuidOptions {
562
562
  readonly metavar?: NonEmptyString;
563
563
  /**
564
564
  * List of allowed UUID versions (e.g., `[4, 5]` for UUIDs version 4 and 5).
565
+ * Each version must be an integer between 1 and 8 (the standardized
566
+ * [RFC 9562] versions). Duplicate entries are automatically removed.
565
567
  * If specified, the parser will validate that the UUID matches one of the
566
568
  * allowed versions. If not specified, the accepted versions depend on
567
569
  * the {@link strict} option.
570
+ *
571
+ * [RFC 9562]: https://www.rfc-editor.org/rfc/rfc9562
568
572
  */
569
573
  readonly allowedVersions?: readonly number[];
570
574
  /**
@@ -633,6 +637,10 @@ interface UuidOptions {
633
637
  * @param options Configuration options for the UUID parser.
634
638
  * @returns A {@link ValueParser} that converts string input to {@link Uuid}
635
639
  * strings.
640
+ * @throws {TypeError} If any element of
641
+ * {@link UuidOptions.allowedVersions} is not an integer.
642
+ * @throws {RangeError} If any element of
643
+ * {@link UuidOptions.allowedVersions} is outside the range 1 to 8.
636
644
  */
637
645
  declare function uuid(options?: UuidOptions): ValueParser<"sync", Uuid>;
638
646
  /**
@@ -810,6 +810,10 @@ function locale(options = {}) {
810
810
  * @param options Configuration options for the UUID parser.
811
811
  * @returns A {@link ValueParser} that converts string input to {@link Uuid}
812
812
  * strings.
813
+ * @throws {TypeError} If any element of
814
+ * {@link UuidOptions.allowedVersions} is not an integer.
815
+ * @throws {RangeError} If any element of
816
+ * {@link UuidOptions.allowedVersions} is outside the range 1 to 8.
813
817
  */
814
818
  function uuid(options = {}) {
815
819
  const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
@@ -817,7 +821,15 @@ function uuid(options = {}) {
817
821
  ensureNonEmptyString(metavar);
818
822
  checkBooleanOption(options, "strict");
819
823
  const strict = options.strict !== false;
820
- const allowedVersions = options.allowedVersions != null ? Object.freeze([...options.allowedVersions]) : null;
824
+ const allowedVersions = options.allowedVersions != null ? (() => {
825
+ const unique = /* @__PURE__ */ new Set();
826
+ for (const v of options.allowedVersions) {
827
+ if (!Number.isInteger(v)) throw new TypeError(`Expected every element of allowedVersions to be an integer, but got value "${typeof v === "symbol" ? v.toString() : String(v)}" of type "${Array.isArray(v) ? "array" : v === null ? "null" : typeof v}".`);
828
+ if (v < 1 || v > 8) throw new RangeError(`Expected every element of allowedVersions to be between 1 and 8, but got: ${v}.`);
829
+ unique.add(v);
830
+ }
831
+ return Object.freeze([...unique]);
832
+ })() : null;
821
833
  const invalidUuid = options.errors?.invalidUuid;
822
834
  const disallowedVersion = options.errors?.disallowedVersion;
823
835
  const invalidVariant = options.errors?.invalidVariant;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1236+3ee9891d",
3
+ "version": "1.0.0-dev.1242+dd1a7a84",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",