@optique/core 0.9.0-dev.217 → 0.9.0-dev.225

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/index.cjs CHANGED
@@ -74,6 +74,7 @@ exports.tuple = require_constructs.tuple;
74
74
  exports.url = require_valueparser.url;
75
75
  exports.uuid = require_valueparser.uuid;
76
76
  exports.value = require_message.value;
77
+ exports.valueSet = require_message.valueSet;
77
78
  exports.values = require_message.values;
78
79
  exports.withDefault = require_modifiers.withDefault;
79
80
  exports.zsh = require_completion.zsh;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.cjs";
2
- import { Message, MessageFormatOptions, MessageTerm, commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, values } from "./message.cjs";
2
+ import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.cjs";
3
3
  import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.cjs";
4
4
  import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage } from "./doc.cjs";
5
5
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.cjs";
@@ -9,4 +9,4 @@ import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, Mode
9
9
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
10
10
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
11
11
  import { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.cjs";
12
- export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, values, withDefault, zsh };
12
+ export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
2
- import { Message, MessageFormatOptions, MessageTerm, commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, values } from "./message.js";
2
+ import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
3
3
  import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
4
4
  import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage } from "./doc.js";
5
5
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, float, integer, isValueParser, locale, string, url, uuid } from "./valueparser.js";
@@ -9,4 +9,4 @@ import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, Mode
9
9
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
10
10
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
11
11
  import { RunError, RunOptions, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.js";
12
- export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, values, withDefault, zsh };
12
+ export { ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, FloatOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Message, MessageFormatOptions, MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OrErrorOptions, OrOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, RunError, RunOptions, RunParserError, ShellCompletion, ShowDefaultOptions, StringOptions, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, choice, command, commandLine, concat, conditional, constant, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, values } from "./message.js";
1
+ import { commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
2
2
  import { extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
3
3
  import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
4
4
  import { formatDocPage } from "./doc.js";
@@ -10,4 +10,4 @@ import { argument, command, constant, flag, option, passThrough } from "./primit
10
10
  import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
11
11
  import { RunError, RunParserError, run, runParser, runParserAsync, runParserSync } from "./facade.js";
12
12
 
13
- export { DuplicateOptionError, RunError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, values, withDefault, zsh };
13
+ export { DuplicateOptionError, RunError, RunParserError, WithDefaultError, argument, bash, choice, command, commandLine, concat, conditional, constant, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getDocPage, getDocPageAsync, getDocPageSync, group, integer, isNonEmptyString, isValueParser, locale, longestMatch, map, merge, message, metavar, multiple, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, pwsh, run, runParser, runParserAsync, runParserSync, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
package/dist/message.cjs CHANGED
@@ -140,6 +140,55 @@ function commandLine(commandLine$1) {
140
140
  };
141
141
  }
142
142
  /**
143
+ * Creates a {@link Message} for a formatted list of values using the
144
+ * `Intl.ListFormat` API. This is useful for displaying choice lists
145
+ * in error messages with proper locale-aware formatting.
146
+ *
147
+ * Each value in the list becomes a separate value term, and the separators
148
+ * (commas, "and", "or", etc.) become text terms. This allows each value
149
+ * to be styled independently while respecting the locale's list formatting
150
+ * conventions.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * // English conjunction (default): "error", "warn", and "info"
155
+ * const msg1 = message`Expected one of ${valueSet(["error", "warn", "info"])}.`;
156
+ *
157
+ * // English disjunction: "error", "warn", or "info"
158
+ * const msg2 = message`Expected ${
159
+ * valueSet(["error", "warn", "info"], { type: "disjunction" })
160
+ * }.`;
161
+ *
162
+ * // Korean disjunction: "error", "warn" 또는 "info"
163
+ * const msg3 = message`${
164
+ * valueSet(["error", "warn", "info"], { locale: "ko", type: "disjunction" })
165
+ * } 중 하나여야 합니다.`;
166
+ * ```
167
+ *
168
+ * @param values The list of values to format.
169
+ * @param options Optional formatting options including locale and list type.
170
+ * @returns A {@link Message} with alternating value and text terms.
171
+ * @since 0.9.0
172
+ */
173
+ function valueSet(values$1, options) {
174
+ if (values$1.length === 0) return [];
175
+ const formatter = new Intl.ListFormat(options?.locale, {
176
+ type: options?.type,
177
+ style: options?.style
178
+ });
179
+ const parts = formatter.formatToParts(values$1);
180
+ const result = [];
181
+ for (const part of parts) if (part.type === "element") result.push({
182
+ type: "value",
183
+ value: part.value
184
+ });
185
+ else result.push({
186
+ type: "text",
187
+ text: part.value
188
+ });
189
+ return result;
190
+ }
191
+ /**
143
192
  * Formats a {@link Message} into a human-readable string for
144
193
  * the terminal.
145
194
  * @param msg The message to format, which is an array of
@@ -276,4 +325,5 @@ exports.optionName = optionName;
276
325
  exports.optionNames = optionNames;
277
326
  exports.text = text;
278
327
  exports.value = value;
328
+ exports.valueSet = valueSet;
279
329
  exports.values = values;
@@ -210,6 +210,71 @@ declare function envVar(envVar: string): MessageTerm;
210
210
  * @since 0.6.0
211
211
  */
212
212
  declare function commandLine(commandLine: string): MessageTerm;
213
+ /**
214
+ * Options for the {@link valueSet} function.
215
+ * @since 0.9.0
216
+ */
217
+ interface ValueSetOptions {
218
+ /**
219
+ * The locale(s) to use for list formatting. Can be a BCP 47 language tag
220
+ * string, an array of language tags, an `Intl.Locale` object, or an array
221
+ * of `Intl.Locale` objects. If not specified, the system default locale
222
+ * is used.
223
+ */
224
+ readonly locale?: string | readonly string[] | Intl.Locale | readonly Intl.Locale[];
225
+ /**
226
+ * The type of list to format:
227
+ *
228
+ * - `"conjunction"`: "A, B, and C" (default)
229
+ * - `"disjunction"`: "A, B, or C"
230
+ * - `"unit"`: "A, B, C"
231
+ *
232
+ * @default `"conjunction"`
233
+ */
234
+ readonly type?: "conjunction" | "disjunction" | "unit";
235
+ /**
236
+ * The style of the list formatting:
237
+ *
238
+ * - `"long"`: "A, B, and C" (default)
239
+ * - `"short"`: "A, B, & C"
240
+ * - `"narrow"`: "A, B, C"
241
+ *
242
+ * @default `"long"`
243
+ */
244
+ readonly style?: "long" | "short" | "narrow";
245
+ }
246
+ /**
247
+ * Creates a {@link Message} for a formatted list of values using the
248
+ * `Intl.ListFormat` API. This is useful for displaying choice lists
249
+ * in error messages with proper locale-aware formatting.
250
+ *
251
+ * Each value in the list becomes a separate value term, and the separators
252
+ * (commas, "and", "or", etc.) become text terms. This allows each value
253
+ * to be styled independently while respecting the locale's list formatting
254
+ * conventions.
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * // English conjunction (default): "error", "warn", and "info"
259
+ * const msg1 = message`Expected one of ${valueSet(["error", "warn", "info"])}.`;
260
+ *
261
+ * // English disjunction: "error", "warn", or "info"
262
+ * const msg2 = message`Expected ${
263
+ * valueSet(["error", "warn", "info"], { type: "disjunction" })
264
+ * }.`;
265
+ *
266
+ * // Korean disjunction: "error", "warn" 또는 "info"
267
+ * const msg3 = message`${
268
+ * valueSet(["error", "warn", "info"], { locale: "ko", type: "disjunction" })
269
+ * } 중 하나여야 합니다.`;
270
+ * ```
271
+ *
272
+ * @param values The list of values to format.
273
+ * @param options Optional formatting options including locale and list type.
274
+ * @returns A {@link Message} with alternating value and text terms.
275
+ * @since 0.9.0
276
+ */
277
+ declare function valueSet(values: readonly string[], options?: ValueSetOptions): Message;
213
278
  /**
214
279
  * Options for the {@link formatMessage} function.
215
280
  */
@@ -258,4 +323,4 @@ interface MessageFormatOptions {
258
323
  */
259
324
  declare function formatMessage(msg: Message, options?: MessageFormatOptions): string;
260
325
  //#endregion
261
- export { Message, MessageFormatOptions, MessageTerm, commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, values };
326
+ export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values };
package/dist/message.d.ts CHANGED
@@ -210,6 +210,71 @@ declare function envVar(envVar: string): MessageTerm;
210
210
  * @since 0.6.0
211
211
  */
212
212
  declare function commandLine(commandLine: string): MessageTerm;
213
+ /**
214
+ * Options for the {@link valueSet} function.
215
+ * @since 0.9.0
216
+ */
217
+ interface ValueSetOptions {
218
+ /**
219
+ * The locale(s) to use for list formatting. Can be a BCP 47 language tag
220
+ * string, an array of language tags, an `Intl.Locale` object, or an array
221
+ * of `Intl.Locale` objects. If not specified, the system default locale
222
+ * is used.
223
+ */
224
+ readonly locale?: string | readonly string[] | Intl.Locale | readonly Intl.Locale[];
225
+ /**
226
+ * The type of list to format:
227
+ *
228
+ * - `"conjunction"`: "A, B, and C" (default)
229
+ * - `"disjunction"`: "A, B, or C"
230
+ * - `"unit"`: "A, B, C"
231
+ *
232
+ * @default `"conjunction"`
233
+ */
234
+ readonly type?: "conjunction" | "disjunction" | "unit";
235
+ /**
236
+ * The style of the list formatting:
237
+ *
238
+ * - `"long"`: "A, B, and C" (default)
239
+ * - `"short"`: "A, B, & C"
240
+ * - `"narrow"`: "A, B, C"
241
+ *
242
+ * @default `"long"`
243
+ */
244
+ readonly style?: "long" | "short" | "narrow";
245
+ }
246
+ /**
247
+ * Creates a {@link Message} for a formatted list of values using the
248
+ * `Intl.ListFormat` API. This is useful for displaying choice lists
249
+ * in error messages with proper locale-aware formatting.
250
+ *
251
+ * Each value in the list becomes a separate value term, and the separators
252
+ * (commas, "and", "or", etc.) become text terms. This allows each value
253
+ * to be styled independently while respecting the locale's list formatting
254
+ * conventions.
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * // English conjunction (default): "error", "warn", and "info"
259
+ * const msg1 = message`Expected one of ${valueSet(["error", "warn", "info"])}.`;
260
+ *
261
+ * // English disjunction: "error", "warn", or "info"
262
+ * const msg2 = message`Expected ${
263
+ * valueSet(["error", "warn", "info"], { type: "disjunction" })
264
+ * }.`;
265
+ *
266
+ * // Korean disjunction: "error", "warn" 또는 "info"
267
+ * const msg3 = message`${
268
+ * valueSet(["error", "warn", "info"], { locale: "ko", type: "disjunction" })
269
+ * } 중 하나여야 합니다.`;
270
+ * ```
271
+ *
272
+ * @param values The list of values to format.
273
+ * @param options Optional formatting options including locale and list type.
274
+ * @returns A {@link Message} with alternating value and text terms.
275
+ * @since 0.9.0
276
+ */
277
+ declare function valueSet(values: readonly string[], options?: ValueSetOptions): Message;
213
278
  /**
214
279
  * Options for the {@link formatMessage} function.
215
280
  */
@@ -258,4 +323,4 @@ interface MessageFormatOptions {
258
323
  */
259
324
  declare function formatMessage(msg: Message, options?: MessageFormatOptions): string;
260
325
  //#endregion
261
- export { Message, MessageFormatOptions, MessageTerm, commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, values };
326
+ export { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values };
package/dist/message.js CHANGED
@@ -139,6 +139,55 @@ function commandLine(commandLine$1) {
139
139
  };
140
140
  }
141
141
  /**
142
+ * Creates a {@link Message} for a formatted list of values using the
143
+ * `Intl.ListFormat` API. This is useful for displaying choice lists
144
+ * in error messages with proper locale-aware formatting.
145
+ *
146
+ * Each value in the list becomes a separate value term, and the separators
147
+ * (commas, "and", "or", etc.) become text terms. This allows each value
148
+ * to be styled independently while respecting the locale's list formatting
149
+ * conventions.
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * // English conjunction (default): "error", "warn", and "info"
154
+ * const msg1 = message`Expected one of ${valueSet(["error", "warn", "info"])}.`;
155
+ *
156
+ * // English disjunction: "error", "warn", or "info"
157
+ * const msg2 = message`Expected ${
158
+ * valueSet(["error", "warn", "info"], { type: "disjunction" })
159
+ * }.`;
160
+ *
161
+ * // Korean disjunction: "error", "warn" 또는 "info"
162
+ * const msg3 = message`${
163
+ * valueSet(["error", "warn", "info"], { locale: "ko", type: "disjunction" })
164
+ * } 중 하나여야 합니다.`;
165
+ * ```
166
+ *
167
+ * @param values The list of values to format.
168
+ * @param options Optional formatting options including locale and list type.
169
+ * @returns A {@link Message} with alternating value and text terms.
170
+ * @since 0.9.0
171
+ */
172
+ function valueSet(values$1, options) {
173
+ if (values$1.length === 0) return [];
174
+ const formatter = new Intl.ListFormat(options?.locale, {
175
+ type: options?.type,
176
+ style: options?.style
177
+ });
178
+ const parts = formatter.formatToParts(values$1);
179
+ const result = [];
180
+ for (const part of parts) if (part.type === "element") result.push({
181
+ type: "value",
182
+ value: part.value
183
+ });
184
+ else result.push({
185
+ type: "text",
186
+ text: part.value
187
+ });
188
+ return result;
189
+ }
190
+ /**
142
191
  * Formats a {@link Message} into a human-readable string for
143
192
  * the terminal.
144
193
  * @param msg The message to format, which is an array of
@@ -266,4 +315,4 @@ function formatMessage(msg, options = {}) {
266
315
  }
267
316
 
268
317
  //#endregion
269
- export { commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, values };
318
+ export { commandLine, envVar, formatMessage, message, metavar, optionName, optionNames, text, value, valueSet, values };
@@ -101,12 +101,8 @@ function formatNumberChoiceError(input, choices, options) {
101
101
  * Formats default error message for choice parser.
102
102
  */
103
103
  function formatDefaultChoiceError(input, choices) {
104
- let choicesList = [];
105
- for (let i = 0; i < choices.length; i++) {
106
- if (i > 0) choicesList = [...choicesList, ...require_message.message`, `];
107
- choicesList = [...choicesList, ...require_message.message`${String(choices[i])}`];
108
- }
109
- return require_message.message`Expected one of ${choicesList}, but got ${input}.`;
104
+ const choiceStrings = choices.map((c) => String(c));
105
+ return require_message.message`Expected one of ${require_message.valueSet(choiceStrings, { locale: "en-US" })}, but got ${input}.`;
110
106
  }
111
107
  /**
112
108
  * Creates a {@link ValueParser} for strings.
@@ -1,4 +1,4 @@
1
- import { message, text } from "./message.js";
1
+ import { message, text, valueSet } from "./message.js";
2
2
  import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
3
3
 
4
4
  //#region src/valueparser.ts
@@ -101,12 +101,8 @@ function formatNumberChoiceError(input, choices, options) {
101
101
  * Formats default error message for choice parser.
102
102
  */
103
103
  function formatDefaultChoiceError(input, choices) {
104
- let choicesList = [];
105
- for (let i = 0; i < choices.length; i++) {
106
- if (i > 0) choicesList = [...choicesList, ...message`, `];
107
- choicesList = [...choicesList, ...message`${String(choices[i])}`];
108
- }
109
- return message`Expected one of ${choicesList}, but got ${input}.`;
104
+ const choiceStrings = choices.map((c) => String(c));
105
+ return message`Expected one of ${valueSet(choiceStrings, { locale: "en-US" })}, but got ${input}.`;
110
106
  }
111
107
  /**
112
108
  * Creates a {@link ValueParser} for strings.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.9.0-dev.217+7fc9df46",
3
+ "version": "0.9.0-dev.225+82a6f132",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",