@optique/core 1.0.0-dev.1313 → 1.0.0-dev.1323

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.
@@ -304,6 +304,7 @@ function or(...args) {
304
304
  parsers = args;
305
305
  options = void 0;
306
306
  }
307
+ if (parsers.length < 1) throw new TypeError("or() requires at least one parser argument.");
307
308
  const noMatchContext = analyzeNoMatchContext(parsers);
308
309
  const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
309
310
  const syncParsers = parsers;
@@ -505,6 +506,7 @@ function longestMatch(...args) {
505
506
  parsers = args;
506
507
  options = void 0;
507
508
  }
509
+ if (parsers.length < 1) throw new TypeError("longestMatch() requires at least one parser argument.");
508
510
  const noMatchContext = analyzeNoMatchContext(parsers);
509
511
  const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
510
512
  const syncParsers = parsers;
@@ -1656,6 +1658,7 @@ function merge(...args) {
1656
1658
  const startIndex = typeof args[0] === "string" ? 1 : 0;
1657
1659
  const endIndex = hasOptions ? args.length - 1 : args.length;
1658
1660
  const rawParsers = args.slice(startIndex, endIndex);
1661
+ if (rawParsers.length < 1) throw new TypeError("merge() requires at least one parser argument.");
1659
1662
  const combinedMode = rawParsers.some((p) => p.$mode === "async") ? "async" : "sync";
1660
1663
  const isAsync = combinedMode === "async";
1661
1664
  const syncRawParsers = rawParsers;
@@ -2098,6 +2101,7 @@ function tryParseSuggestList(context, stateArray, parsers, matchedParsers, remai
2098
2101
  return null;
2099
2102
  }
2100
2103
  function concat(...parsers) {
2104
+ if (parsers.length < 1) throw new TypeError("concat() requires at least one parser argument.");
2101
2105
  const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
2102
2106
  const isAsync = combinedMode === "async";
2103
2107
  const syncParsers = parsers;
@@ -730,6 +730,7 @@ declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extend
730
730
  * @param options Custom error message options.
731
731
  * @return A {@link Parser} that tries to parse using the provided parsers
732
732
  * in order, returning the result of the first successful parser.
733
+ * @throws {TypeError} If no parser arguments are provided.
733
734
  * @since 0.5.0
734
735
  */
735
736
  declare function or<MA extends Mode, MB extends Mode, TA, TB, TStateA, TStateB>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, options: OrOptions): Parser<CombineModes<readonly [MA, MB]>, TA | TB, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>]>;
@@ -751,6 +752,7 @@ declare function or<MA extends Mode, MB extends Mode, TA, TB, TStateA, TStateB>(
751
752
  * @param options Custom error message options.
752
753
  * @return A {@link Parser} that tries to parse using the provided parsers
753
754
  * in order, returning the result of the first successful parser.
755
+ * @throws {TypeError} If no parser arguments are provided.
754
756
  * @since 0.5.0
755
757
  */
756
758
  declare function or<MA extends Mode, MB extends Mode, MC extends Mode, TA, TB, TC, TStateA, TStateB, TStateC>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, options: OrOptions): Parser<CombineModes<readonly [MA, MB, MC]>, TA | TB | TC, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>]>;
@@ -760,6 +762,7 @@ declare function or<MA extends Mode, MB extends Mode, MC extends Mode, TA, TB, T
760
762
  * @param rest Parsers to try, followed by {@link OrOptions} for error
761
763
  * customization.
762
764
  * @returns A parser that succeeds if any of the input parsers succeed.
765
+ * @throws {TypeError} If no parser arguments are provided.
763
766
  * @since 0.5.0
764
767
  */
765
768
  declare function or<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...rest: [...parsers: TParsers, options: OrTailOptions] & OrArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, undefined | [number, ParserResult<unknown>]>;
@@ -767,6 +770,7 @@ declare function or<const TParsers extends readonly Parser<Mode, unknown, unknow
767
770
  * Creates a parser that tries each parser in sequence until one succeeds.
768
771
  * @param parsers Parsers to try in order.
769
772
  * @returns A parser that succeeds if any of the input parsers succeed.
773
+ * @throws {TypeError} If no parser arguments are provided.
770
774
  * @since 0.5.0
771
775
  */
772
776
  declare function or<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...parsers: TParsers & OrArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, undefined | [number, ParserResult<unknown>]>;
@@ -860,6 +864,7 @@ declare function longestMatch<const TParsers extends readonly Parser<"sync", unk
860
864
  * @param rest Parsers to compare, followed by error customization options.
861
865
  * @returns A parser that yields the best successful branch result.
862
866
  * Type inference is precise for tuple calls up to 15 parser arguments.
867
+ * @throws {TypeError} If no parser arguments are provided.
863
868
  * @since 0.5.0
864
869
  */
865
870
  declare function longestMatch<const TParsers extends readonly Parser<"sync", unknown, unknown>[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard<TParsers>): Parser<"sync", InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
@@ -870,6 +875,7 @@ declare function longestMatch<const TParsers extends readonly Parser<"sync", unk
870
875
  * @param rest Parsers to compare, followed by error customization options.
871
876
  * @returns A parser that yields the best successful branch result.
872
877
  * Type inference is precise for tuple calls up to 15 parser arguments.
878
+ * @throws {TypeError} If no parser arguments are provided.
873
879
  * @since 0.5.0
874
880
  */
875
881
  declare function longestMatch<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
@@ -1131,6 +1137,7 @@ type MergeReturnType<TParsers extends MergeParsers> = Parser<CombineModes<{ read
1131
1137
  * @param rest Parsers to merge, followed by merge options.
1132
1138
  * @returns A parser that merges parsed object fields from all parsers.
1133
1139
  * Type inference is precise for tuple calls up to 15 parser arguments.
1140
+ * @throws {TypeError} If no parser arguments are provided.
1134
1141
  * @since 0.7.0
1135
1142
  */
1136
1143
  declare function merge<const TParsers extends MergeParsers>(...rest: [...parsers: EnsureMergeParsers<TParsers>, options: MergeTailOptions] & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1144,6 +1151,7 @@ declare function merge<const TParsers extends MergeParsers>(...rest: [...parsers
1144
1151
  * @param parsers Parsers to merge in declaration order.
1145
1152
  * @returns A parser that merges parsed object fields from all parsers.
1146
1153
  * Type inference is precise for tuple calls up to 15 parser arguments.
1154
+ * @throws {TypeError} If no parser arguments are provided.
1147
1155
  * @since 0.4.0
1148
1156
  */
1149
1157
  declare function merge<const TParsers extends MergeParsers>(label: string, ...parsers: EnsureMergeParsers<TParsers> & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1157,6 +1165,7 @@ declare function merge<const TParsers extends MergeParsers>(label: string, ...pa
1157
1165
  * @param rest Parsers to merge, followed by merge options.
1158
1166
  * @returns A parser that merges parsed object fields from all parsers.
1159
1167
  * Type inference is precise for tuple calls up to 15 parser arguments.
1168
+ * @throws {TypeError} If no parser arguments are provided.
1160
1169
  * @since 0.7.0
1161
1170
  */
1162
1171
  declare function merge<const TParsers extends MergeParsers>(label: string, ...rest: [...parsers: EnsureMergeParsers<TParsers>, options: MergeTailOptions] & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1169,6 +1178,7 @@ declare function merge<const TParsers extends MergeParsers>(label: string, ...re
1169
1178
  * @param parsers Parsers to merge in declaration order.
1170
1179
  * @returns A parser that merges parsed object fields from all parsers.
1171
1180
  * Type inference is precise for tuple calls up to 15 parser arguments.
1181
+ * @throws {TypeError} If no parser arguments are provided.
1172
1182
  * @since 0.1.0
1173
1183
  */
1174
1184
  declare function merge<const TParsers extends MergeParsers>(...parsers: EnsureMergeParsers<TParsers> & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1216,6 +1226,7 @@ type ConcatValues<TParsers extends ConcatParsers> = IsTuple<TParsers> extends tr
1216
1226
  * @param parsers Tuple parsers to concatenate.
1217
1227
  * @returns A parser with flattened tuple values from all parsers.
1218
1228
  * Type inference is precise for tuple calls up to 15 parser arguments.
1229
+ * @throws {TypeError} If no parser arguments are provided.
1219
1230
  * @since 0.2.0
1220
1231
  */
1221
1232
  declare function concat<const TParsers extends ConcatParsers>(...parsers: TParsers & ConcatArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, ConcatValues<TParsers>, ConcatStates<TParsers>>;
@@ -730,6 +730,7 @@ declare function or<MA extends Mode, MB extends Mode, MC extends Mode, MD extend
730
730
  * @param options Custom error message options.
731
731
  * @return A {@link Parser} that tries to parse using the provided parsers
732
732
  * in order, returning the result of the first successful parser.
733
+ * @throws {TypeError} If no parser arguments are provided.
733
734
  * @since 0.5.0
734
735
  */
735
736
  declare function or<MA extends Mode, MB extends Mode, TA, TB, TStateA, TStateB>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, options: OrOptions): Parser<CombineModes<readonly [MA, MB]>, TA | TB, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>]>;
@@ -751,6 +752,7 @@ declare function or<MA extends Mode, MB extends Mode, TA, TB, TStateA, TStateB>(
751
752
  * @param options Custom error message options.
752
753
  * @return A {@link Parser} that tries to parse using the provided parsers
753
754
  * in order, returning the result of the first successful parser.
755
+ * @throws {TypeError} If no parser arguments are provided.
754
756
  * @since 0.5.0
755
757
  */
756
758
  declare function or<MA extends Mode, MB extends Mode, MC extends Mode, TA, TB, TC, TStateA, TStateB, TStateC>(a: Parser<MA, TA, TStateA>, b: Parser<MB, TB, TStateB>, c: Parser<MC, TC, TStateC>, options: OrOptions): Parser<CombineModes<readonly [MA, MB, MC]>, TA | TB | TC, undefined | [0, ParserResult<TStateA>] | [1, ParserResult<TStateB>] | [2, ParserResult<TStateC>]>;
@@ -760,6 +762,7 @@ declare function or<MA extends Mode, MB extends Mode, MC extends Mode, TA, TB, T
760
762
  * @param rest Parsers to try, followed by {@link OrOptions} for error
761
763
  * customization.
762
764
  * @returns A parser that succeeds if any of the input parsers succeed.
765
+ * @throws {TypeError} If no parser arguments are provided.
763
766
  * @since 0.5.0
764
767
  */
765
768
  declare function or<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...rest: [...parsers: TParsers, options: OrTailOptions] & OrArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, undefined | [number, ParserResult<unknown>]>;
@@ -767,6 +770,7 @@ declare function or<const TParsers extends readonly Parser<Mode, unknown, unknow
767
770
  * Creates a parser that tries each parser in sequence until one succeeds.
768
771
  * @param parsers Parsers to try in order.
769
772
  * @returns A parser that succeeds if any of the input parsers succeed.
773
+ * @throws {TypeError} If no parser arguments are provided.
770
774
  * @since 0.5.0
771
775
  */
772
776
  declare function or<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...parsers: TParsers & OrArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, undefined | [number, ParserResult<unknown>]>;
@@ -860,6 +864,7 @@ declare function longestMatch<const TParsers extends readonly Parser<"sync", unk
860
864
  * @param rest Parsers to compare, followed by error customization options.
861
865
  * @returns A parser that yields the best successful branch result.
862
866
  * Type inference is precise for tuple calls up to 15 parser arguments.
867
+ * @throws {TypeError} If no parser arguments are provided.
863
868
  * @since 0.5.0
864
869
  */
865
870
  declare function longestMatch<const TParsers extends readonly Parser<"sync", unknown, unknown>[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard<TParsers>): Parser<"sync", InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
@@ -870,6 +875,7 @@ declare function longestMatch<const TParsers extends readonly Parser<"sync", unk
870
875
  * @param rest Parsers to compare, followed by error customization options.
871
876
  * @returns A parser that yields the best successful branch result.
872
877
  * Type inference is precise for tuple calls up to 15 parser arguments.
878
+ * @throws {TypeError} If no parser arguments are provided.
873
879
  * @since 0.5.0
874
880
  */
875
881
  declare function longestMatch<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
@@ -1131,6 +1137,7 @@ type MergeReturnType<TParsers extends MergeParsers> = Parser<CombineModes<{ read
1131
1137
  * @param rest Parsers to merge, followed by merge options.
1132
1138
  * @returns A parser that merges parsed object fields from all parsers.
1133
1139
  * Type inference is precise for tuple calls up to 15 parser arguments.
1140
+ * @throws {TypeError} If no parser arguments are provided.
1134
1141
  * @since 0.7.0
1135
1142
  */
1136
1143
  declare function merge<const TParsers extends MergeParsers>(...rest: [...parsers: EnsureMergeParsers<TParsers>, options: MergeTailOptions] & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1144,6 +1151,7 @@ declare function merge<const TParsers extends MergeParsers>(...rest: [...parsers
1144
1151
  * @param parsers Parsers to merge in declaration order.
1145
1152
  * @returns A parser that merges parsed object fields from all parsers.
1146
1153
  * Type inference is precise for tuple calls up to 15 parser arguments.
1154
+ * @throws {TypeError} If no parser arguments are provided.
1147
1155
  * @since 0.4.0
1148
1156
  */
1149
1157
  declare function merge<const TParsers extends MergeParsers>(label: string, ...parsers: EnsureMergeParsers<TParsers> & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1157,6 +1165,7 @@ declare function merge<const TParsers extends MergeParsers>(label: string, ...pa
1157
1165
  * @param rest Parsers to merge, followed by merge options.
1158
1166
  * @returns A parser that merges parsed object fields from all parsers.
1159
1167
  * Type inference is precise for tuple calls up to 15 parser arguments.
1168
+ * @throws {TypeError} If no parser arguments are provided.
1160
1169
  * @since 0.7.0
1161
1170
  */
1162
1171
  declare function merge<const TParsers extends MergeParsers>(label: string, ...rest: [...parsers: EnsureMergeParsers<TParsers>, options: MergeTailOptions] & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1169,6 +1178,7 @@ declare function merge<const TParsers extends MergeParsers>(label: string, ...re
1169
1178
  * @param parsers Parsers to merge in declaration order.
1170
1179
  * @returns A parser that merges parsed object fields from all parsers.
1171
1180
  * Type inference is precise for tuple calls up to 15 parser arguments.
1181
+ * @throws {TypeError} If no parser arguments are provided.
1172
1182
  * @since 0.1.0
1173
1183
  */
1174
1184
  declare function merge<const TParsers extends MergeParsers>(...parsers: EnsureMergeParsers<TParsers> & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
@@ -1216,6 +1226,7 @@ type ConcatValues<TParsers extends ConcatParsers> = IsTuple<TParsers> extends tr
1216
1226
  * @param parsers Tuple parsers to concatenate.
1217
1227
  * @returns A parser with flattened tuple values from all parsers.
1218
1228
  * Type inference is precise for tuple calls up to 15 parser arguments.
1229
+ * @throws {TypeError} If no parser arguments are provided.
1219
1230
  * @since 0.2.0
1220
1231
  */
1221
1232
  declare function concat<const TParsers extends ConcatParsers>(...parsers: TParsers & ConcatArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, ConcatValues<TParsers>, ConcatStates<TParsers>>;
@@ -304,6 +304,7 @@ function or(...args) {
304
304
  parsers = args;
305
305
  options = void 0;
306
306
  }
307
+ if (parsers.length < 1) throw new TypeError("or() requires at least one parser argument.");
307
308
  const noMatchContext = analyzeNoMatchContext(parsers);
308
309
  const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
309
310
  const syncParsers = parsers;
@@ -505,6 +506,7 @@ function longestMatch(...args) {
505
506
  parsers = args;
506
507
  options = void 0;
507
508
  }
509
+ if (parsers.length < 1) throw new TypeError("longestMatch() requires at least one parser argument.");
508
510
  const noMatchContext = analyzeNoMatchContext(parsers);
509
511
  const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
510
512
  const syncParsers = parsers;
@@ -1656,6 +1658,7 @@ function merge(...args) {
1656
1658
  const startIndex = typeof args[0] === "string" ? 1 : 0;
1657
1659
  const endIndex = hasOptions ? args.length - 1 : args.length;
1658
1660
  const rawParsers = args.slice(startIndex, endIndex);
1661
+ if (rawParsers.length < 1) throw new TypeError("merge() requires at least one parser argument.");
1659
1662
  const combinedMode = rawParsers.some((p) => p.$mode === "async") ? "async" : "sync";
1660
1663
  const isAsync = combinedMode === "async";
1661
1664
  const syncRawParsers = rawParsers;
@@ -2098,6 +2101,7 @@ function tryParseSuggestList(context, stateArray, parsers, matchedParsers, remai
2098
2101
  return null;
2099
2102
  }
2100
2103
  function concat(...parsers) {
2104
+ if (parsers.length < 1) throw new TypeError("concat() requires at least one parser argument.");
2101
2105
  const combinedMode = parsers.some((p) => p.$mode === "async") ? "async" : "sync";
2102
2106
  const isAsync = combinedMode === "async";
2103
2107
  const syncParsers = parsers;
package/dist/doc.cjs CHANGED
@@ -51,7 +51,8 @@ function defaultSectionOrder(a, b) {
51
51
  * any non-empty section's title is empty, whitespace-only, or contains a CR
52
52
  * or LF character, or if `maxWidth` is not a finite integer.
53
53
  * @throws {RangeError} If any entry needs a description column and `maxWidth`
54
- * is too small to fit the minimum layout (less than `termIndent + 4`).
54
+ * is too small to fit the minimum layout (less than `termIndent + 4`), or if
55
+ * `showChoices.maxItems` is less than `1`.
55
56
  *
56
57
  * @example
57
58
  * ```typescript
@@ -87,6 +88,10 @@ function formatDocPage(programName, page, options = {}) {
87
88
  ...page,
88
89
  sections: filteredSections
89
90
  };
91
+ if (typeof options.showChoices === "object" && options.showChoices.maxItems != null) {
92
+ const maxItems = options.showChoices.maxItems;
93
+ if (maxItems < 1) throw new RangeError(`showChoices.maxItems must be at least 1, but got ${maxItems}.`);
94
+ }
90
95
  const hasContent = (msg) => Array.isArray(msg) && msg.length > 0;
91
96
  if (options.maxWidth != null) {
92
97
  const hasEntries = page.sections.some((s) => s.entries.length > 0);
package/dist/doc.d.cts CHANGED
@@ -148,9 +148,10 @@ interface ShowChoicesOptions {
148
148
  readonly label?: string;
149
149
  /**
150
150
  * Maximum number of choice values to display before truncating with
151
- * `...`. Set to `Infinity` to show all choices.
151
+ * `...`. Must be at least `1`. Set to `Infinity` to show all choices.
152
152
  *
153
153
  * @default `8`
154
+ * @throws {RangeError} If the value is less than `1`.
154
155
  */
155
156
  readonly maxItems?: number;
156
157
  }
@@ -267,7 +268,8 @@ interface DocPageFormatOptions {
267
268
  * any non-empty section's title is empty, whitespace-only, or contains a CR
268
269
  * or LF character, or if `maxWidth` is not a finite integer.
269
270
  * @throws {RangeError} If any entry needs a description column and `maxWidth`
270
- * is too small to fit the minimum layout (less than `termIndent + 4`).
271
+ * is too small to fit the minimum layout (less than `termIndent + 4`), or if
272
+ * `showChoices.maxItems` is less than `1`.
271
273
  *
272
274
  * @example
273
275
  * ```typescript
package/dist/doc.d.ts CHANGED
@@ -148,9 +148,10 @@ interface ShowChoicesOptions {
148
148
  readonly label?: string;
149
149
  /**
150
150
  * Maximum number of choice values to display before truncating with
151
- * `...`. Set to `Infinity` to show all choices.
151
+ * `...`. Must be at least `1`. Set to `Infinity` to show all choices.
152
152
  *
153
153
  * @default `8`
154
+ * @throws {RangeError} If the value is less than `1`.
154
155
  */
155
156
  readonly maxItems?: number;
156
157
  }
@@ -267,7 +268,8 @@ interface DocPageFormatOptions {
267
268
  * any non-empty section's title is empty, whitespace-only, or contains a CR
268
269
  * or LF character, or if `maxWidth` is not a finite integer.
269
270
  * @throws {RangeError} If any entry needs a description column and `maxWidth`
270
- * is too small to fit the minimum layout (less than `termIndent + 4`).
271
+ * is too small to fit the minimum layout (less than `termIndent + 4`), or if
272
+ * `showChoices.maxItems` is less than `1`.
271
273
  *
272
274
  * @example
273
275
  * ```typescript
package/dist/doc.js CHANGED
@@ -51,7 +51,8 @@ function defaultSectionOrder(a, b) {
51
51
  * any non-empty section's title is empty, whitespace-only, or contains a CR
52
52
  * or LF character, or if `maxWidth` is not a finite integer.
53
53
  * @throws {RangeError} If any entry needs a description column and `maxWidth`
54
- * is too small to fit the minimum layout (less than `termIndent + 4`).
54
+ * is too small to fit the minimum layout (less than `termIndent + 4`), or if
55
+ * `showChoices.maxItems` is less than `1`.
55
56
  *
56
57
  * @example
57
58
  * ```typescript
@@ -87,6 +88,10 @@ function formatDocPage(programName, page, options = {}) {
87
88
  ...page,
88
89
  sections: filteredSections
89
90
  };
91
+ if (typeof options.showChoices === "object" && options.showChoices.maxItems != null) {
92
+ const maxItems = options.showChoices.maxItems;
93
+ if (maxItems < 1) throw new RangeError(`showChoices.maxItems must be at least 1, but got ${maxItems}.`);
94
+ }
90
95
  const hasContent = (msg) => Array.isArray(msg) && msg.length > 0;
91
96
  if (options.maxWidth != null) {
92
97
  const hasEntries = page.sections.some((s) => s.entries.length > 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1313+758f4e24",
3
+ "version": "1.0.0-dev.1323+0653ad71",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",