@optique/core 1.1.0-dev.2065 → 1.1.0-dev.2070

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.
@@ -162,7 +162,7 @@ function _${programName} () {
162
162
 
163
163
  # Pre-expand file candidates. When the glob base came from the
164
164
  # program's pattern and contains wildcard characters (* or ?),
165
- # use it as-is via compgen -G (safe no command substitution).
165
+ # use it as-is via compgen -G (safe—no command substitution).
166
166
  # Otherwise append * to treat it as a prefix.
167
167
  # Note: [ is NOT treated as a glob indicator because it commonly
168
168
  # appears in literal filenames like [draft] or foo[1].txt.
@@ -375,7 +375,7 @@ function _${programName.replace(/[^a-zA-Z0-9]/g, "_")} () {
375
375
  [[ "\$__compare_pattern" == */* ]] && __compare_pattern="\${__compare_pattern%/*}/" || __compare_pattern=""
376
376
  fi
377
377
  if [[ ( -n "\$__compare_pattern" || -n "\$__norm_prefix" ) && \${#__norm_prefix} -ge \${#__compare_pattern} && "\${__norm_prefix[1,\${#__compare_pattern}]}" == "\$__compare_pattern" && "\$PREFIX" != "\$pattern" ]]; then
378
- # User typed an equivalent or extended form keep PREFIX
378
+ # User typed an equivalent or extended form—keep PREFIX
379
379
  true
380
380
  else
381
381
  PREFIX="\$pattern"
@@ -536,7 +536,7 @@ ${escapedArgs ? ` set -l output (${programName} ${escapedArgs} $prev $current
536
536
  end
537
537
  end
538
538
 
539
- # Expand tilde prefix for globbing fish does not expand ~
539
+ # Expand tilde prefix for globbing—fish does not expand ~
540
540
  # inside variable substitutions, so replace it with $HOME
541
541
  if string match -q '~/*' -- "$glob_base"
542
542
  set __tilde_prefix "~"
@@ -1186,7 +1186,7 @@ ${escapedArgs ? ` \$completionArgs += @(${escapedArgs})
1186
1186
  \$prefix = \$prefix + '/'
1187
1187
  }
1188
1188
 
1189
- # Build the glob path when the prefix contains wildcard
1189
+ # Build the glob path—when the prefix contains wildcard
1190
1190
  # characters, use it as-is; otherwise append *
1191
1191
  \$globPath = if (\$prefix -match '[\*\?]') { \$prefix } else { "\${prefix}*" }
1192
1192
 
@@ -162,7 +162,7 @@ function _${programName} () {
162
162
 
163
163
  # Pre-expand file candidates. When the glob base came from the
164
164
  # program's pattern and contains wildcard characters (* or ?),
165
- # use it as-is via compgen -G (safe no command substitution).
165
+ # use it as-is via compgen -G (safe—no command substitution).
166
166
  # Otherwise append * to treat it as a prefix.
167
167
  # Note: [ is NOT treated as a glob indicator because it commonly
168
168
  # appears in literal filenames like [draft] or foo[1].txt.
@@ -375,7 +375,7 @@ function _${programName.replace(/[^a-zA-Z0-9]/g, "_")} () {
375
375
  [[ "\$__compare_pattern" == */* ]] && __compare_pattern="\${__compare_pattern%/*}/" || __compare_pattern=""
376
376
  fi
377
377
  if [[ ( -n "\$__compare_pattern" || -n "\$__norm_prefix" ) && \${#__norm_prefix} -ge \${#__compare_pattern} && "\${__norm_prefix[1,\${#__compare_pattern}]}" == "\$__compare_pattern" && "\$PREFIX" != "\$pattern" ]]; then
378
- # User typed an equivalent or extended form keep PREFIX
378
+ # User typed an equivalent or extended form—keep PREFIX
379
379
  true
380
380
  else
381
381
  PREFIX="\$pattern"
@@ -536,7 +536,7 @@ ${escapedArgs ? ` set -l output (${programName} ${escapedArgs} $prev $current
536
536
  end
537
537
  end
538
538
 
539
- # Expand tilde prefix for globbing fish does not expand ~
539
+ # Expand tilde prefix for globbing—fish does not expand ~
540
540
  # inside variable substitutions, so replace it with $HOME
541
541
  if string match -q '~/*' -- "$glob_base"
542
542
  set __tilde_prefix "~"
@@ -1186,7 +1186,7 @@ ${escapedArgs ? ` \$completionArgs += @(${escapedArgs})
1186
1186
  \$prefix = \$prefix + '/'
1187
1187
  }
1188
1188
 
1189
- # Build the glob path when the prefix contains wildcard
1189
+ # Build the glob path—when the prefix contains wildcard
1190
1190
  # characters, use it as-is; otherwise append *
1191
1191
  \$globPath = if (\$prefix -match '[\*\?]') { \$prefix } else { "\${prefix}*" }
1192
1192
 
@@ -1597,7 +1597,7 @@ function filterExcludedFieldParsers(pairs, excludedFields) {
1597
1597
  /**
1598
1598
  * Pre-completes dependency source fields and registers their values in
1599
1599
  * the given registry. Unlike `completeDependencySourceDefaults()` (used
1600
- * by suggest), this function handles all four Phase 1 cases including
1600
+ * by suggest), this function handles all four Phase 1 cases—including
1601
1601
  * PendingDependencySourceState in arrays and wrappedDependencySourceMarker.
1602
1602
  *
1603
1603
  * The original state is NOT modified; only the registry is populated.
@@ -1597,7 +1597,7 @@ function filterExcludedFieldParsers(pairs, excludedFields) {
1597
1597
  /**
1598
1598
  * Pre-completes dependency source fields and registers their values in
1599
1599
  * the given registry. Unlike `completeDependencySourceDefaults()` (used
1600
- * by suggest), this function handles all four Phase 1 cases including
1600
+ * by suggest), this function handles all four Phase 1 cases—including
1601
1601
  * PendingDependencySourceState in arrays and wrappedDependencySourceMarker.
1602
1602
  *
1603
1603
  * The original state is NOT modified; only the registry is populated.
@@ -20,13 +20,13 @@ interface DependencySourceCapability {
20
20
  * The `state` argument is the current parser state for the source-owning
21
21
  * parser. Each wrapper composes this method to handle its own state shape:
22
22
  * - plain source: reads from `DependencySourceState`
23
- * - `optional()` / `withDefault()`: unwraps `[innerState]` first
23
+ * - `optional()`/`withDefault()`: unwraps `[innerState]` first
24
24
  * - `map()`: reads the pre-transform value from inner state
25
25
  *
26
26
  * Returns the `ValueParserResult` (which may be successful with any
27
27
  * value including `undefined`, or failed), a promise that resolves to the
28
28
  * same shape when extraction needs async work, or `undefined` if the state
29
- * does not contain a source result at all (unpopulated / wrong shape).
29
+ * does not contain a source result at all (unpopulated/wrong shape).
30
30
  * Callers and wrapper authors must handle both direct and promise-wrapped
31
31
  * results when composing `extractSourceValue`.
32
32
  */
@@ -20,13 +20,13 @@ interface DependencySourceCapability {
20
20
  * The `state` argument is the current parser state for the source-owning
21
21
  * parser. Each wrapper composes this method to handle its own state shape:
22
22
  * - plain source: reads from `DependencySourceState`
23
- * - `optional()` / `withDefault()`: unwraps `[innerState]` first
23
+ * - `optional()`/`withDefault()`: unwraps `[innerState]` first
24
24
  * - `map()`: reads the pre-transform value from inner state
25
25
  *
26
26
  * Returns the `ValueParserResult` (which may be successful with any
27
27
  * value including `undefined`, or failed), a promise that resolves to the
28
28
  * same shape when extraction needs async work, or `undefined` if the state
29
- * does not contain a source result at all (unpopulated / wrong shape).
29
+ * does not contain a source result at all (unpopulated/wrong shape).
30
30
  * Callers and wrapper authors must handle both direct and promise-wrapped
31
31
  * results when composing `extractSourceValue`.
32
32
  */
package/dist/index.cjs CHANGED
@@ -106,6 +106,7 @@ exports.runParserSync = require_facade.runParserSync;
106
106
  exports.runWith = require_facade.runWith;
107
107
  exports.runWithAsync = require_facade.runWithAsync;
108
108
  exports.runWithSync = require_facade.runWithSync;
109
+ exports.semVer = require_valueparser.semVer;
109
110
  exports.socketAddress = require_valueparser.socketAddress;
110
111
  exports.string = require_valueparser.string;
111
112
  exports.suggest = require_parser.suggest;
package/dist/index.d.cts CHANGED
@@ -3,7 +3,7 @@ import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonemp
3
3
  import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.cjs";
4
4
  import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.cjs";
5
5
  import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, formatDocPage, isDocEntryHidden } from "./doc.cjs";
6
- import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, fileSize, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.cjs";
6
+ import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, fileSize, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid } from "./valueparser.cjs";
7
7
  import { CombineModes, DocState, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseFrame, Parser, ParserContext, ParserResult, Result, Suggestion, createParserContext, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./internal/parser.cjs";
8
8
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
9
9
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
@@ -12,4 +12,4 @@ import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMod
12
12
  import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
13
13
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
14
14
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, negatableFlag, option, passThrough } from "./primitives.cjs";
15
- export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredMap, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createParserContext, deduplicateDocEntries, deduplicateDocFragments, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
15
+ export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredMap, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createParserContext, deduplicateDocEntries, deduplicateDocFragments, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonemp
3
3
  import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
4
4
  import { HiddenVisibility, OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, cloneUsage, cloneUsageTerm, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, formatUsage, formatUsageTerm, isDocHidden, isSuggestionHidden, isUsageHidden, mergeHidden, normalizeUsage } from "./usage.js";
5
5
  import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, cloneDocEntry, deduplicateDocEntries, deduplicateDocFragments, formatDocPage, isDocEntryHidden } from "./doc.js";
6
- import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, fileSize, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.js";
6
+ import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, fileSize, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid } from "./valueparser.js";
7
7
  import { CombineModes, DocState, ExecutionContext, ExecutionPhase, InferMode, InferValue, Mode, ModeIterable, ModeValue, ParseFrame, Parser, ParserContext, ParserResult, Result, Suggestion, createParserContext, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./internal/parser.js";
8
8
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
9
9
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, GroupOptions, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
@@ -12,4 +12,4 @@ import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMod
12
12
  import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
13
13
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
14
14
  import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, negatableFlag, option, passThrough } from "./primitives.js";
15
- export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredMap, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createParserContext, deduplicateDocEntries, deduplicateDocFragments, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
15
+ export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CommandSubConfig, ConditionalErrorOptions, ConditionalOptions, ContextOptionsParam, DeferredMap, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExecutionContext, ExecutionPhase, ExtractRequiredOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FlagErrorOptions, FlagOptions, FloatOptions, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NegatableFlagErrorOptions, NegatableFlagNameList, NegatableFlagNames, NegatableFlagOptions, NegatableFlagState, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OptionSubConfig, OrErrorOptions, OrOptions, ParseFrame, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, SourceContextRequest, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createParserContext, deduplicateDocEntries, deduplicateDocFragments, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
package/dist/index.js CHANGED
@@ -8,8 +8,8 @@ import { createParserContext, getDocPage, getDocPageAsync, getDocPageSync, parse
8
8
  import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
9
9
  import { WithDefaultError, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
10
10
  import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
11
- import { checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, fileSize, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.js";
11
+ import { checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, fileSize, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid } from "./valueparser.js";
12
12
  import { argument, command, constant, fail, flag, negatableFlag, option, passThrough } from "./primitives.js";
13
13
  import { RunParserError, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
14
14
 
15
- export { DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createParserContext, deduplicateDocEntries, deduplicateDocFragments, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
15
+ export { DuplicateOptionError, RunParserError, WithDefaultError, argument, bash, checkBooleanOption, checkEnumOption, choice, cidr, cloneDocEntry, cloneUsage, cloneUsageTerm, color, command, commandLine, concat, conditional, constant, createParserContext, deduplicateDocEntries, deduplicateDocFragments, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, fish, flag, float, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, lineBreak, link, locale, longestMatch, macAddress, map, merge, mergeHidden, message, metavar, multiple, negatableFlag, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, passThrough, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, semVer, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
@@ -112,7 +112,7 @@ interface Parser<M extends Mode = "sync", TValue = unknown, TState = unknown> {
112
112
  *
113
113
  * Each built-in combinator computes this from its structural semantics.
114
114
  * Custom parser implementations must include every fixed token that
115
- * the parser accepts at `argv[0]` — command names, option names, and
115
+ * the parser accepts at `argv[0]`—command names, option names, and
116
116
  * literal values alike. For example, a parser whose usage declares
117
117
  * `{ type: "literal", value: "serve" }` should include `"serve"` in
118
118
  * this set. Parsers that accept *any* token (like `argument()`) should
@@ -265,8 +265,8 @@ interface Parser<M extends Mode = "sync", TValue = unknown, TState = unknown> {
265
265
  * parser (e.g., regex patterns, numeric bounds, `choice()` values).
266
266
  *
267
267
  * Wrappers like `bindEnv()` and `bindConfig()` call this on fallback
268
- * values environment variables parsed by a looser env parser,
269
- * configured defaults, and values loaded from config files so that
268
+ * values—environment variables parsed by a looser env parser,
269
+ * configured defaults, and values loaded from config files—so that
270
270
  * those values obey the same validation semantics as CLI input.
271
271
  * Without it, parser constraints can be silently bypassed through
272
272
  * fallback paths.
@@ -292,7 +292,7 @@ interface Parser<M extends Mode = "sync", TValue = unknown, TState = unknown> {
292
292
  * current dependency value, and custom value parsers whose `format()`
293
293
  * intentionally throws for unsupported inputs. Values that
294
294
  * `format()` successfully serializes to a string are always re-parsed,
295
- * and any resulting parse failure is propagated they represent the
295
+ * and any resulting parse failure is propagated—they represent the
296
296
  * bug class this method exists to surface.
297
297
  *
298
298
  * @param value The candidate value to validate.
@@ -413,7 +413,7 @@ interface ExecutionContext {
413
413
  * `preCompleteAndRegisterDependencies` results directly to children
414
414
  * in Phase 3. Children read it in their own Phase 1 to avoid
415
415
  * re-evaluating non-idempotent default thunks, but never write to
416
- * it this prevents sibling completions from leaking into each
416
+ * it—this prevents sibling completions from leaking into each
417
417
  * other.
418
418
  *
419
419
  * Field-name keying naturally handles parser reuse across different
@@ -112,7 +112,7 @@ interface Parser<M extends Mode = "sync", TValue = unknown, TState = unknown> {
112
112
  *
113
113
  * Each built-in combinator computes this from its structural semantics.
114
114
  * Custom parser implementations must include every fixed token that
115
- * the parser accepts at `argv[0]` — command names, option names, and
115
+ * the parser accepts at `argv[0]`—command names, option names, and
116
116
  * literal values alike. For example, a parser whose usage declares
117
117
  * `{ type: "literal", value: "serve" }` should include `"serve"` in
118
118
  * this set. Parsers that accept *any* token (like `argument()`) should
@@ -265,8 +265,8 @@ interface Parser<M extends Mode = "sync", TValue = unknown, TState = unknown> {
265
265
  * parser (e.g., regex patterns, numeric bounds, `choice()` values).
266
266
  *
267
267
  * Wrappers like `bindEnv()` and `bindConfig()` call this on fallback
268
- * values environment variables parsed by a looser env parser,
269
- * configured defaults, and values loaded from config files so that
268
+ * values—environment variables parsed by a looser env parser,
269
+ * configured defaults, and values loaded from config files—so that
270
270
  * those values obey the same validation semantics as CLI input.
271
271
  * Without it, parser constraints can be silently bypassed through
272
272
  * fallback paths.
@@ -292,7 +292,7 @@ interface Parser<M extends Mode = "sync", TValue = unknown, TState = unknown> {
292
292
  * current dependency value, and custom value parsers whose `format()`
293
293
  * intentionally throws for unsupported inputs. Values that
294
294
  * `format()` successfully serializes to a string are always re-parsed,
295
- * and any resulting parse failure is propagated they represent the
295
+ * and any resulting parse failure is propagated—they represent the
296
296
  * bug class this method exists to surface.
297
297
  *
298
298
  * @param value The candidate value to validate.
@@ -413,7 +413,7 @@ interface ExecutionContext {
413
413
  * `preCompleteAndRegisterDependencies` results directly to children
414
414
  * in Phase 3. Children read it in their own Phase 1 to avoid
415
415
  * re-evaluating non-idempotent default thunks, but never write to
416
- * it this prevents sibling completions from leaking into each
416
+ * it—this prevents sibling completions from leaking into each
417
417
  * other.
418
418
  *
419
419
  * Field-name keying naturally handles parser reuse across different
@@ -142,14 +142,14 @@ function extractOptionalLikePhase2Seed(parser, state, exec) {
142
142
  }
143
143
  /**
144
144
  * Computes the inner state to pass through to the wrapped parser inside
145
- * {@link optional} / {@link withDefault}. When the outer state is an
145
+ * {@link optional}/{@link withDefault}. When the outer state is an
146
146
  * array, the inner state is `state[0]`. Otherwise, including the
147
147
  * common case where `optional()` sits at top level and the outer state
148
- * is either `undefined` or an annotation wrapper from `parseOptionalLike`
149
- * / `parse({ annotations })`, we use the wrapped parser's
148
+ * is either `undefined` or an annotation wrapper from `parseOptionalLike`/
149
+ * `parse({ annotations })`, we use the wrapped parser's
150
150
  * `initialState`, propagating annotations from the outer state so that
151
- * source-binding wrappers under `optional()` / `withDefault()` (e.g.,
152
- * `bindEnv()` / `bindConfig()`) can resolve their fallbacks.
151
+ * source-binding wrappers under `optional()`/`withDefault()` (e.g.,
152
+ * `bindEnv()`/`bindConfig()`) can resolve their fallbacks.
153
153
  *
154
154
  * @internal
155
155
  */
@@ -677,7 +677,7 @@ function withDefault(parser, defaultValue, options) {
677
677
  *
678
678
  * Because the `deferred` flag is propagated conservatively, mapped scalar
679
679
  * results are treated as missing (`undefined`) during phase-two context
680
- * collection even when `transform` only used non-deferred fields.
680
+ * collection—even when `transform` only used non-deferred fields.
681
681
  * For example, `map(object({ apiKey: prompt(...), mode: option(...) }),
682
682
  * v => v.mode)` makes phase-two contexts see `undefined` instead of the
683
683
  * real `mode` value. This is the intentional trade-off: the alternative
@@ -138,7 +138,7 @@ declare function withDefault<M extends Mode, TValue, TState, const TDefault = TV
138
138
  *
139
139
  * Because the `deferred` flag is propagated conservatively, mapped scalar
140
140
  * results are treated as missing (`undefined`) during phase-two context
141
- * collection even when `transform` only used non-deferred fields.
141
+ * collection—even when `transform` only used non-deferred fields.
142
142
  * For example, `map(object({ apiKey: prompt(...), mode: option(...) }),
143
143
  * v => v.mode)` makes phase-two contexts see `undefined` instead of the
144
144
  * real `mode` value. This is the intentional trade-off: the alternative
@@ -138,7 +138,7 @@ declare function withDefault<M extends Mode, TValue, TState, const TDefault = TV
138
138
  *
139
139
  * Because the `deferred` flag is propagated conservatively, mapped scalar
140
140
  * results are treated as missing (`undefined`) during phase-two context
141
- * collection even when `transform` only used non-deferred fields.
141
+ * collection—even when `transform` only used non-deferred fields.
142
142
  * For example, `map(object({ apiKey: prompt(...), mode: option(...) }),
143
143
  * v => v.mode)` makes phase-two contexts see `undefined` instead of the
144
144
  * real `mode` value. This is the intentional trade-off: the alternative
package/dist/modifiers.js CHANGED
@@ -142,14 +142,14 @@ function extractOptionalLikePhase2Seed(parser, state, exec) {
142
142
  }
143
143
  /**
144
144
  * Computes the inner state to pass through to the wrapped parser inside
145
- * {@link optional} / {@link withDefault}. When the outer state is an
145
+ * {@link optional}/{@link withDefault}. When the outer state is an
146
146
  * array, the inner state is `state[0]`. Otherwise, including the
147
147
  * common case where `optional()` sits at top level and the outer state
148
- * is either `undefined` or an annotation wrapper from `parseOptionalLike`
149
- * / `parse({ annotations })`, we use the wrapped parser's
148
+ * is either `undefined` or an annotation wrapper from `parseOptionalLike`/
149
+ * `parse({ annotations })`, we use the wrapped parser's
150
150
  * `initialState`, propagating annotations from the outer state so that
151
- * source-binding wrappers under `optional()` / `withDefault()` (e.g.,
152
- * `bindEnv()` / `bindConfig()`) can resolve their fallbacks.
151
+ * source-binding wrappers under `optional()`/`withDefault()` (e.g.,
152
+ * `bindEnv()`/`bindConfig()`) can resolve their fallbacks.
153
153
  *
154
154
  * @internal
155
155
  */
@@ -677,7 +677,7 @@ function withDefault(parser, defaultValue, options) {
677
677
  *
678
678
  * Because the `deferred` flag is propagated conservatively, mapped scalar
679
679
  * results are treated as missing (`undefined`) during phase-two context
680
- * collection even when `transform` only used non-deferred fields.
680
+ * collection—even when `transform` only used non-deferred fields.
681
681
  * For example, `map(object({ apiKey: prompt(...), mode: option(...) }),
682
682
  * v => v.mode)` makes phase-two contexts see `undefined` instead of the
683
683
  * real `mode` value. This is the intentional trade-off: the alternative
@@ -55,7 +55,7 @@ function collectLeadingCandidates(terms, optionNames, commandNames) {
55
55
  *
56
56
  * This is the command-only projection of {@link collectLeadingCandidates}
57
57
  * and is used to generate accurate "Did you mean?" suggestions in
58
- * `command()` error messages suggestions are scoped to commands actually
58
+ * `command()` error messages—suggestions are scoped to commands actually
59
59
  * reachable at the current parse position rather than all commands anywhere
60
60
  * in the usage tree.
61
61
  *
@@ -55,7 +55,7 @@ function collectLeadingCandidates(terms, optionNames, commandNames) {
55
55
  *
56
56
  * This is the command-only projection of {@link collectLeadingCandidates}
57
57
  * and is used to generate accurate "Did you mean?" suggestions in
58
- * `command()` error messages suggestions are scoped to commands actually
58
+ * `command()` error messages—suggestions are scoped to commands actually
59
59
  * reachable at the current parse position rather than all commands anywhere
60
60
  * in the usage tree.
61
61
  *
@@ -5144,6 +5144,97 @@ function cidr(options) {
5144
5144
  });
5145
5145
  return cidrParserObj;
5146
5146
  }
5147
+ const SEMVER_REGEX = /^(?<prefix>v)?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<pre>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<meta>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
5148
+ const SEMVER_SUGGESTIONS = Object.freeze([
5149
+ "0.0.0",
5150
+ "1.0.0",
5151
+ "1.0.0-alpha",
5152
+ "1.0.0-alpha.1",
5153
+ "1.0.0+build.1",
5154
+ "1.0.0-alpha.1+build.1"
5155
+ ]);
5156
+ const SEMVER_SUGGESTIONS_WITH_PREFIX = Object.freeze([...SEMVER_SUGGESTIONS, ...SEMVER_SUGGESTIONS.map((s) => `v${s}`)]);
5157
+ function semVer(options = {}) {
5158
+ const metavar = options.metavar ?? "SEMVER";
5159
+ require_nonempty.ensureNonEmptyString(metavar);
5160
+ checkEnumOption(options, "type", ["string", "object"]);
5161
+ checkBooleanOption(options, "allowPrefix");
5162
+ const allowPrefix = options.allowPrefix ?? false;
5163
+ const objectMode = options.type === "object";
5164
+ const errorOption = options.errors?.invalidSemVer;
5165
+ const suggestions = allowPrefix ? SEMVER_SUGGESTIONS_WITH_PREFIX : SEMVER_SUGGESTIONS;
5166
+ function makeError(input) {
5167
+ return {
5168
+ success: false,
5169
+ error: errorOption ? typeof errorOption === "function" ? errorOption(input) : errorOption : require_message.message`Expected a valid Semantic Versioning 2.0.0 string (e.g. ${"1.0.0"}), but got ${input}.`
5170
+ };
5171
+ }
5172
+ if (objectMode) return {
5173
+ mode: "sync",
5174
+ metavar,
5175
+ placeholder: {
5176
+ major: 0,
5177
+ minor: 0,
5178
+ patch: 0
5179
+ },
5180
+ parse(input) {
5181
+ const m = SEMVER_REGEX.exec(input);
5182
+ if (m == null) return makeError(input);
5183
+ if (!allowPrefix && m.groups.prefix != null) return makeError(input);
5184
+ const major = parseInt(m.groups.major, 10);
5185
+ const minor = parseInt(m.groups.minor, 10);
5186
+ const patch = parseInt(m.groups.patch, 10);
5187
+ if (!Number.isSafeInteger(major) || !Number.isSafeInteger(minor) || !Number.isSafeInteger(patch)) return makeError(input);
5188
+ const result = {
5189
+ major,
5190
+ minor,
5191
+ patch,
5192
+ ...m.groups.pre != null ? { preRelease: m.groups.pre } : {},
5193
+ ...m.groups.meta != null ? { metadata: m.groups.meta } : {}
5194
+ };
5195
+ return {
5196
+ success: true,
5197
+ value: result
5198
+ };
5199
+ },
5200
+ format(value) {
5201
+ let s = `${value.major}.${value.minor}.${value.patch}`;
5202
+ if (value.preRelease != null) s += `-${value.preRelease}`;
5203
+ if (value.metadata != null) s += `+${value.metadata}`;
5204
+ return s;
5205
+ },
5206
+ *suggest(prefix) {
5207
+ for (const s of suggestions) if (s.startsWith(prefix)) yield {
5208
+ kind: "literal",
5209
+ text: s
5210
+ };
5211
+ }
5212
+ };
5213
+ return {
5214
+ mode: "sync",
5215
+ metavar,
5216
+ placeholder: "0.0.0",
5217
+ parse(input) {
5218
+ const m = SEMVER_REGEX.exec(input);
5219
+ if (m == null) return makeError(input);
5220
+ if (!allowPrefix && m.groups.prefix != null) return makeError(input);
5221
+ const canonical = `${m.groups.major}.${m.groups.minor}.${m.groups.patch}` + (m.groups.pre != null ? `-${m.groups.pre}` : "") + (m.groups.meta != null ? `+${m.groups.meta}` : "");
5222
+ return {
5223
+ success: true,
5224
+ value: canonical
5225
+ };
5226
+ },
5227
+ format(value) {
5228
+ return value;
5229
+ },
5230
+ *suggest(prefix) {
5231
+ for (const s of suggestions) if (s.startsWith(prefix)) yield {
5232
+ kind: "literal",
5233
+ text: s
5234
+ };
5235
+ }
5236
+ };
5237
+ }
5147
5238
 
5148
5239
  //#endregion
5149
5240
  exports.checkBooleanOption = checkBooleanOption;
@@ -5167,6 +5258,7 @@ exports.locale = locale;
5167
5258
  exports.macAddress = macAddress;
5168
5259
  exports.port = port;
5169
5260
  exports.portRange = portRange;
5261
+ exports.semVer = semVer;
5170
5262
  exports.socketAddress = socketAddress;
5171
5263
  exports.string = string;
5172
5264
  exports.url = url;
@@ -161,7 +161,7 @@ type ValueParserResult<T> = {
161
161
  * A recursive map that tracks which fields in a parsed object hold deferred
162
162
  * placeholder values. Each entry maps a property key to either `null`
163
163
  * (the field is fully deferred and should be replaced with `undefined`)
164
- * or another `DeferredMap` (the field is partially deferred recurse into
164
+ * or another `DeferredMap` (the field is partially deferred—recurse into
165
165
  * its sub-fields).
166
166
  *
167
167
  * @since 1.0.0
@@ -2405,5 +2405,159 @@ interface CidrOptions {
2405
2405
  * @since 0.10.0
2406
2406
  */
2407
2407
  declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
2408
+ /**
2409
+ * A normalized Semantic Versioning 2.0.0 string.
2410
+ *
2411
+ * Covers all four valid forms:
2412
+ * - `MAJOR.MINOR.PATCH`
2413
+ * - `MAJOR.MINOR.PATCH-preRelease`
2414
+ * - `MAJOR.MINOR.PATCH+metadata`
2415
+ * - `MAJOR.MINOR.PATCH-preRelease+metadata`
2416
+ *
2417
+ * Note: this type uses TypeScript template literals as a coarse structural
2418
+ * hint. The `${number}` slots accept any JavaScript number serialization
2419
+ * (including negative numbers, decimals, and `Infinity`), so the type alone
2420
+ * does not guarantee full SemVer 2.0.0 validity. Full validation is
2421
+ * enforced at parse time by {@link semVer}. Only values returned by
2422
+ * `semVer().parse()` are guaranteed to conform to the specification.
2423
+ *
2424
+ * @since 1.1.0
2425
+ */
2426
+ type SemVerString = `${number}.${number}.${number}` | `${number}.${number}.${number}-${string}` | `${number}.${number}.${number}+${string}` | `${number}.${number}.${number}-${string}+${string}`;
2427
+ /**
2428
+ * A parsed Semantic Versioning 2.0.0 value as a structured object.
2429
+ *
2430
+ * @since 1.1.0
2431
+ */
2432
+ interface SemVer {
2433
+ /**
2434
+ * The major version number.
2435
+ *
2436
+ * This field is a JavaScript `number`, so it is limited to
2437
+ * {@link Number.MAX_SAFE_INTEGER} (2⁵³ − 1). Inputs whose major
2438
+ * component exceeds this value are rejected by {@link semVer} in object
2439
+ * mode; use string mode to handle arbitrarily large version numbers.
2440
+ */
2441
+ readonly major: number;
2442
+ /**
2443
+ * The minor version number.
2444
+ *
2445
+ * Same safe-integer constraint as {@link major}.
2446
+ */
2447
+ readonly minor: number;
2448
+ /**
2449
+ * The patch version number.
2450
+ *
2451
+ * Same safe-integer constraint as {@link major}.
2452
+ */
2453
+ readonly patch: number;
2454
+ /**
2455
+ * The pre-release identifier (the part after `-`, before `+`), if present.
2456
+ * Example: `"alpha.1"` for `1.0.0-alpha.1`.
2457
+ */
2458
+ readonly preRelease?: string;
2459
+ /**
2460
+ * The build metadata (the part after `+`), if present.
2461
+ * Example: `"build.42"` for `1.0.0+build.42`.
2462
+ */
2463
+ readonly metadata?: string;
2464
+ }
2465
+ /** @internal */
2466
+ interface SemVerOptionsBase {
2467
+ /**
2468
+ * The metavariable name for this parser. Used in help messages.
2469
+ * @default `"SEMVER"`
2470
+ */
2471
+ readonly metavar?: NonEmptyString;
2472
+ /**
2473
+ * Whether to accept an optional leading `v` character (e.g. `v1.2.3`).
2474
+ * The `v` prefix is stripped; output is always the canonical unprefixed form.
2475
+ * @default false
2476
+ */
2477
+ readonly allowPrefix?: boolean;
2478
+ /**
2479
+ * Custom error messages for parse failures.
2480
+ * @since 1.1.0
2481
+ */
2482
+ readonly errors?: {
2483
+ /**
2484
+ * Message when input is not a valid SemVer string.
2485
+ * Can be a static message or a function receiving the rejected input.
2486
+ */
2487
+ readonly invalidSemVer?: Message | ((input: string) => Message);
2488
+ };
2489
+ }
2490
+ /**
2491
+ * Options for {@link semVer} in string mode (the default).
2492
+ *
2493
+ * @since 1.1.0
2494
+ */
2495
+ interface SemVerOptionsString extends SemVerOptionsBase {
2496
+ /** Return a {@link SemVerString} template-literal type. */
2497
+ readonly type?: "string";
2498
+ }
2499
+ /**
2500
+ * Options for {@link semVer} in object mode.
2501
+ *
2502
+ * In object mode, version components are stored as JavaScript `number`
2503
+ * values. Components exceeding {@link Number.MAX_SAFE_INTEGER} (2⁵³ − 1)
2504
+ * cannot be represented exactly and are therefore rejected with a parse
2505
+ * error. Use string mode (the default) if you need to handle version
2506
+ * numbers of arbitrary magnitude.
2507
+ *
2508
+ * @since 1.1.0
2509
+ */
2510
+ interface SemVerOptionsObject extends SemVerOptionsBase {
2511
+ /** Return a structured {@link SemVer} object. */
2512
+ readonly type: "object";
2513
+ }
2514
+ /**
2515
+ * Creates a {@link ValueParser} for [Semantic Versioning 2.0.0] strings.
2516
+ *
2517
+ * In string mode (the default), the parser returns a {@link SemVerString}
2518
+ * template-literal type. String mode accepts any spec-valid SemVer input,
2519
+ * including version components of arbitrary magnitude.
2520
+ *
2521
+ * In object mode (`type: "object"`), the parser returns a structured
2522
+ * {@link SemVer} value with `major`, `minor`, `patch`, and optional
2523
+ * `preRelease` and `metadata` fields. Because the numeric components are
2524
+ * stored as JavaScript `number`, object mode additionally rejects inputs
2525
+ * whose major, minor, or patch value exceeds
2526
+ * {@link Number.MAX_SAFE_INTEGER} (2⁵³ − 1). Use string mode if you need
2527
+ * to handle arbitrarily large version numbers.
2528
+ *
2529
+ * Both modes strictly enforce the SemVer 2.0.0 specification: no leading
2530
+ * zeros in numeric components, no empty pre-release or build identifiers,
2531
+ * and no invalid characters.
2532
+ *
2533
+ * [Semantic Versioning 2.0.0]: https://semver.org/
2534
+ *
2535
+ * @param options Configuration options.
2536
+ * @returns A {@link ValueParser} that validates SemVer strings.
2537
+ * @throws {TypeError} If {@link SemVerOptionsBase.metavar} is an empty string.
2538
+ * @throws {TypeError} If {@link SemVerOptionsBase.allowPrefix} is not a
2539
+ * boolean.
2540
+ * @throws {TypeError} If {@link SemVerOptionsString.type} is not `"string"`,
2541
+ * `"object"`, or `undefined`.
2542
+ * @since 1.1.0
2543
+ */
2544
+ declare function semVer(options?: SemVerOptionsString): ValueParser<"sync", SemVerString>;
2545
+ /**
2546
+ * Creates a {@link ValueParser} for [Semantic Versioning 2.0.0] strings,
2547
+ * returning a structured {@link SemVer} object.
2548
+ *
2549
+ * [Semantic Versioning 2.0.0]: https://semver.org/
2550
+ *
2551
+ * @param options Configuration options with `type: "object"`.
2552
+ * @returns A {@link ValueParser} that converts SemVer strings to {@link SemVer}
2553
+ * objects.
2554
+ * @throws {TypeError} If {@link SemVerOptionsBase.metavar} is an empty string.
2555
+ * @throws {TypeError} If {@link SemVerOptionsBase.allowPrefix} is not a
2556
+ * boolean.
2557
+ * @throws {TypeError} If {@link SemVerOptionsObject.type} is not `"string"`,
2558
+ * `"object"`, or `undefined`.
2559
+ * @since 1.1.0
2560
+ */
2561
+ declare function semVer(options: SemVerOptionsObject): ValueParser<"sync", SemVer>;
2408
2562
  //#endregion
2409
- export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
2563
+ export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
@@ -161,7 +161,7 @@ type ValueParserResult<T> = {
161
161
  * A recursive map that tracks which fields in a parsed object hold deferred
162
162
  * placeholder values. Each entry maps a property key to either `null`
163
163
  * (the field is fully deferred and should be replaced with `undefined`)
164
- * or another `DeferredMap` (the field is partially deferred recurse into
164
+ * or another `DeferredMap` (the field is partially deferred—recurse into
165
165
  * its sub-fields).
166
166
  *
167
167
  * @since 1.0.0
@@ -2405,5 +2405,159 @@ interface CidrOptions {
2405
2405
  * @since 0.10.0
2406
2406
  */
2407
2407
  declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
2408
+ /**
2409
+ * A normalized Semantic Versioning 2.0.0 string.
2410
+ *
2411
+ * Covers all four valid forms:
2412
+ * - `MAJOR.MINOR.PATCH`
2413
+ * - `MAJOR.MINOR.PATCH-preRelease`
2414
+ * - `MAJOR.MINOR.PATCH+metadata`
2415
+ * - `MAJOR.MINOR.PATCH-preRelease+metadata`
2416
+ *
2417
+ * Note: this type uses TypeScript template literals as a coarse structural
2418
+ * hint. The `${number}` slots accept any JavaScript number serialization
2419
+ * (including negative numbers, decimals, and `Infinity`), so the type alone
2420
+ * does not guarantee full SemVer 2.0.0 validity. Full validation is
2421
+ * enforced at parse time by {@link semVer}. Only values returned by
2422
+ * `semVer().parse()` are guaranteed to conform to the specification.
2423
+ *
2424
+ * @since 1.1.0
2425
+ */
2426
+ type SemVerString = `${number}.${number}.${number}` | `${number}.${number}.${number}-${string}` | `${number}.${number}.${number}+${string}` | `${number}.${number}.${number}-${string}+${string}`;
2427
+ /**
2428
+ * A parsed Semantic Versioning 2.0.0 value as a structured object.
2429
+ *
2430
+ * @since 1.1.0
2431
+ */
2432
+ interface SemVer {
2433
+ /**
2434
+ * The major version number.
2435
+ *
2436
+ * This field is a JavaScript `number`, so it is limited to
2437
+ * {@link Number.MAX_SAFE_INTEGER} (2⁵³ − 1). Inputs whose major
2438
+ * component exceeds this value are rejected by {@link semVer} in object
2439
+ * mode; use string mode to handle arbitrarily large version numbers.
2440
+ */
2441
+ readonly major: number;
2442
+ /**
2443
+ * The minor version number.
2444
+ *
2445
+ * Same safe-integer constraint as {@link major}.
2446
+ */
2447
+ readonly minor: number;
2448
+ /**
2449
+ * The patch version number.
2450
+ *
2451
+ * Same safe-integer constraint as {@link major}.
2452
+ */
2453
+ readonly patch: number;
2454
+ /**
2455
+ * The pre-release identifier (the part after `-`, before `+`), if present.
2456
+ * Example: `"alpha.1"` for `1.0.0-alpha.1`.
2457
+ */
2458
+ readonly preRelease?: string;
2459
+ /**
2460
+ * The build metadata (the part after `+`), if present.
2461
+ * Example: `"build.42"` for `1.0.0+build.42`.
2462
+ */
2463
+ readonly metadata?: string;
2464
+ }
2465
+ /** @internal */
2466
+ interface SemVerOptionsBase {
2467
+ /**
2468
+ * The metavariable name for this parser. Used in help messages.
2469
+ * @default `"SEMVER"`
2470
+ */
2471
+ readonly metavar?: NonEmptyString;
2472
+ /**
2473
+ * Whether to accept an optional leading `v` character (e.g. `v1.2.3`).
2474
+ * The `v` prefix is stripped; output is always the canonical unprefixed form.
2475
+ * @default false
2476
+ */
2477
+ readonly allowPrefix?: boolean;
2478
+ /**
2479
+ * Custom error messages for parse failures.
2480
+ * @since 1.1.0
2481
+ */
2482
+ readonly errors?: {
2483
+ /**
2484
+ * Message when input is not a valid SemVer string.
2485
+ * Can be a static message or a function receiving the rejected input.
2486
+ */
2487
+ readonly invalidSemVer?: Message | ((input: string) => Message);
2488
+ };
2489
+ }
2490
+ /**
2491
+ * Options for {@link semVer} in string mode (the default).
2492
+ *
2493
+ * @since 1.1.0
2494
+ */
2495
+ interface SemVerOptionsString extends SemVerOptionsBase {
2496
+ /** Return a {@link SemVerString} template-literal type. */
2497
+ readonly type?: "string";
2498
+ }
2499
+ /**
2500
+ * Options for {@link semVer} in object mode.
2501
+ *
2502
+ * In object mode, version components are stored as JavaScript `number`
2503
+ * values. Components exceeding {@link Number.MAX_SAFE_INTEGER} (2⁵³ − 1)
2504
+ * cannot be represented exactly and are therefore rejected with a parse
2505
+ * error. Use string mode (the default) if you need to handle version
2506
+ * numbers of arbitrary magnitude.
2507
+ *
2508
+ * @since 1.1.0
2509
+ */
2510
+ interface SemVerOptionsObject extends SemVerOptionsBase {
2511
+ /** Return a structured {@link SemVer} object. */
2512
+ readonly type: "object";
2513
+ }
2514
+ /**
2515
+ * Creates a {@link ValueParser} for [Semantic Versioning 2.0.0] strings.
2516
+ *
2517
+ * In string mode (the default), the parser returns a {@link SemVerString}
2518
+ * template-literal type. String mode accepts any spec-valid SemVer input,
2519
+ * including version components of arbitrary magnitude.
2520
+ *
2521
+ * In object mode (`type: "object"`), the parser returns a structured
2522
+ * {@link SemVer} value with `major`, `minor`, `patch`, and optional
2523
+ * `preRelease` and `metadata` fields. Because the numeric components are
2524
+ * stored as JavaScript `number`, object mode additionally rejects inputs
2525
+ * whose major, minor, or patch value exceeds
2526
+ * {@link Number.MAX_SAFE_INTEGER} (2⁵³ − 1). Use string mode if you need
2527
+ * to handle arbitrarily large version numbers.
2528
+ *
2529
+ * Both modes strictly enforce the SemVer 2.0.0 specification: no leading
2530
+ * zeros in numeric components, no empty pre-release or build identifiers,
2531
+ * and no invalid characters.
2532
+ *
2533
+ * [Semantic Versioning 2.0.0]: https://semver.org/
2534
+ *
2535
+ * @param options Configuration options.
2536
+ * @returns A {@link ValueParser} that validates SemVer strings.
2537
+ * @throws {TypeError} If {@link SemVerOptionsBase.metavar} is an empty string.
2538
+ * @throws {TypeError} If {@link SemVerOptionsBase.allowPrefix} is not a
2539
+ * boolean.
2540
+ * @throws {TypeError} If {@link SemVerOptionsString.type} is not `"string"`,
2541
+ * `"object"`, or `undefined`.
2542
+ * @since 1.1.0
2543
+ */
2544
+ declare function semVer(options?: SemVerOptionsString): ValueParser<"sync", SemVerString>;
2545
+ /**
2546
+ * Creates a {@link ValueParser} for [Semantic Versioning 2.0.0] strings,
2547
+ * returning a structured {@link SemVer} object.
2548
+ *
2549
+ * [Semantic Versioning 2.0.0]: https://semver.org/
2550
+ *
2551
+ * @param options Configuration options with `type: "object"`.
2552
+ * @returns A {@link ValueParser} that converts SemVer strings to {@link SemVer}
2553
+ * objects.
2554
+ * @throws {TypeError} If {@link SemVerOptionsBase.metavar} is an empty string.
2555
+ * @throws {TypeError} If {@link SemVerOptionsBase.allowPrefix} is not a
2556
+ * boolean.
2557
+ * @throws {TypeError} If {@link SemVerOptionsObject.type} is not `"string"`,
2558
+ * `"object"`, or `undefined`.
2559
+ * @since 1.1.0
2560
+ */
2561
+ declare function semVer(options: SemVerOptionsObject): ValueParser<"sync", SemVer>;
2408
2562
  //#endregion
2409
- export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
2563
+ export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
@@ -5144,6 +5144,97 @@ function cidr(options) {
5144
5144
  });
5145
5145
  return cidrParserObj;
5146
5146
  }
5147
+ const SEMVER_REGEX = /^(?<prefix>v)?(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<pre>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<meta>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
5148
+ const SEMVER_SUGGESTIONS = Object.freeze([
5149
+ "0.0.0",
5150
+ "1.0.0",
5151
+ "1.0.0-alpha",
5152
+ "1.0.0-alpha.1",
5153
+ "1.0.0+build.1",
5154
+ "1.0.0-alpha.1+build.1"
5155
+ ]);
5156
+ const SEMVER_SUGGESTIONS_WITH_PREFIX = Object.freeze([...SEMVER_SUGGESTIONS, ...SEMVER_SUGGESTIONS.map((s) => `v${s}`)]);
5157
+ function semVer(options = {}) {
5158
+ const metavar = options.metavar ?? "SEMVER";
5159
+ ensureNonEmptyString(metavar);
5160
+ checkEnumOption(options, "type", ["string", "object"]);
5161
+ checkBooleanOption(options, "allowPrefix");
5162
+ const allowPrefix = options.allowPrefix ?? false;
5163
+ const objectMode = options.type === "object";
5164
+ const errorOption = options.errors?.invalidSemVer;
5165
+ const suggestions = allowPrefix ? SEMVER_SUGGESTIONS_WITH_PREFIX : SEMVER_SUGGESTIONS;
5166
+ function makeError(input) {
5167
+ return {
5168
+ success: false,
5169
+ error: errorOption ? typeof errorOption === "function" ? errorOption(input) : errorOption : message`Expected a valid Semantic Versioning 2.0.0 string (e.g. ${"1.0.0"}), but got ${input}.`
5170
+ };
5171
+ }
5172
+ if (objectMode) return {
5173
+ mode: "sync",
5174
+ metavar,
5175
+ placeholder: {
5176
+ major: 0,
5177
+ minor: 0,
5178
+ patch: 0
5179
+ },
5180
+ parse(input) {
5181
+ const m = SEMVER_REGEX.exec(input);
5182
+ if (m == null) return makeError(input);
5183
+ if (!allowPrefix && m.groups.prefix != null) return makeError(input);
5184
+ const major = parseInt(m.groups.major, 10);
5185
+ const minor = parseInt(m.groups.minor, 10);
5186
+ const patch = parseInt(m.groups.patch, 10);
5187
+ if (!Number.isSafeInteger(major) || !Number.isSafeInteger(minor) || !Number.isSafeInteger(patch)) return makeError(input);
5188
+ const result = {
5189
+ major,
5190
+ minor,
5191
+ patch,
5192
+ ...m.groups.pre != null ? { preRelease: m.groups.pre } : {},
5193
+ ...m.groups.meta != null ? { metadata: m.groups.meta } : {}
5194
+ };
5195
+ return {
5196
+ success: true,
5197
+ value: result
5198
+ };
5199
+ },
5200
+ format(value) {
5201
+ let s = `${value.major}.${value.minor}.${value.patch}`;
5202
+ if (value.preRelease != null) s += `-${value.preRelease}`;
5203
+ if (value.metadata != null) s += `+${value.metadata}`;
5204
+ return s;
5205
+ },
5206
+ *suggest(prefix) {
5207
+ for (const s of suggestions) if (s.startsWith(prefix)) yield {
5208
+ kind: "literal",
5209
+ text: s
5210
+ };
5211
+ }
5212
+ };
5213
+ return {
5214
+ mode: "sync",
5215
+ metavar,
5216
+ placeholder: "0.0.0",
5217
+ parse(input) {
5218
+ const m = SEMVER_REGEX.exec(input);
5219
+ if (m == null) return makeError(input);
5220
+ if (!allowPrefix && m.groups.prefix != null) return makeError(input);
5221
+ const canonical = `${m.groups.major}.${m.groups.minor}.${m.groups.patch}` + (m.groups.pre != null ? `-${m.groups.pre}` : "") + (m.groups.meta != null ? `+${m.groups.meta}` : "");
5222
+ return {
5223
+ success: true,
5224
+ value: canonical
5225
+ };
5226
+ },
5227
+ format(value) {
5228
+ return value;
5229
+ },
5230
+ *suggest(prefix) {
5231
+ for (const s of suggestions) if (s.startsWith(prefix)) yield {
5232
+ kind: "literal",
5233
+ text: s
5234
+ };
5235
+ }
5236
+ };
5237
+ }
5147
5238
 
5148
5239
  //#endregion
5149
- export { checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
5240
+ export { checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.1.0-dev.2065",
3
+ "version": "1.1.0-dev.2070",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",