@optique/core 1.1.0-dev.2065 → 1.1.0-dev.2069
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 +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/valueparser.cjs +92 -0
- package/dist/valueparser.d.cts +155 -1
- package/dist/valueparser.d.ts +155 -1
- package/dist/valueparser.js +92 -1
- package/package.json +1 -1
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 };
|
package/dist/valueparser.cjs
CHANGED
|
@@ -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;
|
package/dist/valueparser.d.cts
CHANGED
|
@@ -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 };
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -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 };
|
package/dist/valueparser.js
CHANGED
|
@@ -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 };
|