@optique/core 1.2.0-dev.2187 → 1.2.0-dev.2188
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 +213 -0
- package/dist/valueparser.d.cts +109 -1
- package/dist/valueparser.d.ts +109 -1
- package/dist/valueparser.js +213 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ exports.concat = require_constructs.concat;
|
|
|
31
31
|
exports.conditional = require_constructs.conditional;
|
|
32
32
|
exports.constant = require_primitives.constant;
|
|
33
33
|
exports.createParserContext = require_internal_parser.createParserContext;
|
|
34
|
+
exports.cron = require_valueparser.cron;
|
|
34
35
|
exports.deduplicateDocEntries = require_doc.deduplicateDocEntries;
|
|
35
36
|
exports.deduplicateDocFragments = require_doc.deduplicateDocFragments;
|
|
36
37
|
exports.dependency = require_internal_dependency.dependency;
|
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, FirstOfOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, 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, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid } from "./valueparser.cjs";
|
|
6
|
+
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, 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, cron, domain, email, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, 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 { FluentParser, MultipleErrorOptions, MultipleOptions, ParserModifiers, WithDefaultError, WithDefaultOptions, fluent, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
|
|
@@ -12,4 +12,4 @@ import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./c
|
|
|
12
12
|
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, isDependencySource, isDerivedValueParser } from "./internal/dependency.cjs";
|
|
13
13
|
import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.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, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, 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, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, 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, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, 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, seq, 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, CronExpression, CronExpressionForOptions, CronOptions, 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, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, 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, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, 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, cron, deduplicateDocEntries, deduplicateDocFragments, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, 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, seq, 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, FirstOfOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, 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, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid } from "./valueparser.js";
|
|
6
|
+
import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, 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, cron, domain, email, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, 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 { FluentParser, MultipleErrorOptions, MultipleOptions, ParserModifiers, WithDefaultError, WithDefaultOptions, fluent, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
|
|
@@ -12,4 +12,4 @@ import { ParserValuePlaceholder, SourceContext, SourceContextRequest } from "./c
|
|
|
12
12
|
import { AnyDependencySource, CombineMode, CombinedDependencyMode, DependencyMode, DependencySource, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, dependency, deriveFrom, deriveFromAsync, deriveFromSync, isDependencySource, isDerivedValueParser } from "./internal/dependency.js";
|
|
13
13
|
import { CommandSubConfig, ContextOptionsParam, ExtractRequiredOptions, OptionSubConfig, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.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, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, 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, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, 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, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, 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, seq, 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, CronExpression, CronExpressionForOptions, CronOptions, 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, FirstOfOptions, FlagErrorOptions, FlagOptions, FloatOptions, FluentParser, GroupOptions, HiddenVisibility, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, 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, ParserModifiers, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, Result, RunOptions, RunParserError, RunWithOptions, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SeqOptions, 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, cron, deduplicateDocEntries, deduplicateDocFragments, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, 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, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,8 @@ import { bash, fish, nu, pwsh, zsh } from "./completion.js";
|
|
|
8
8
|
import { WithDefaultError, fluent, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
|
|
9
9
|
import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, seq, tuple } from "./constructs.js";
|
|
10
10
|
import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
|
|
11
|
-
import { checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid } from "./valueparser.js";
|
|
11
|
+
import { checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isValueParser, json, keyValue, 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, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, 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, seq, 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, cron, deduplicateDocEntries, deduplicateDocFragments, dependency, deriveFrom, deriveFromAsync, deriveFromSync, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractLiteralValues, extractOptionNames, fail, fileSize, firstOf, fish, flag, float, fluent, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDependencySource, isDerivedValueParser, isDocEntryHidden, isDocHidden, isNonEmptyString, isSuggestionHidden, isUsageHidden, isValueParser, json, keyValue, 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, seq, socketAddress, string, suggest, suggestAsync, suggestSync, text, tuple, url, uuid, value, valueSet, values, withDefault, zsh };
|
package/dist/valueparser.cjs
CHANGED
|
@@ -5844,6 +5844,218 @@ function findNonFiniteNumber(root) {
|
|
|
5844
5844
|
}
|
|
5845
5845
|
return void 0;
|
|
5846
5846
|
}
|
|
5847
|
+
const CRON_MONTH_NAMES = new Map([
|
|
5848
|
+
["JAN", 1],
|
|
5849
|
+
["FEB", 2],
|
|
5850
|
+
["MAR", 3],
|
|
5851
|
+
["APR", 4],
|
|
5852
|
+
["MAY", 5],
|
|
5853
|
+
["JUN", 6],
|
|
5854
|
+
["JUL", 7],
|
|
5855
|
+
["AUG", 8],
|
|
5856
|
+
["SEP", 9],
|
|
5857
|
+
["OCT", 10],
|
|
5858
|
+
["NOV", 11],
|
|
5859
|
+
["DEC", 12]
|
|
5860
|
+
]);
|
|
5861
|
+
const CRON_DAY_NAMES = new Map([
|
|
5862
|
+
["SUN", 0],
|
|
5863
|
+
["MON", 1],
|
|
5864
|
+
["TUE", 2],
|
|
5865
|
+
["WED", 3],
|
|
5866
|
+
["THU", 4],
|
|
5867
|
+
["FRI", 5],
|
|
5868
|
+
["SAT", 6]
|
|
5869
|
+
]);
|
|
5870
|
+
const CRON_FIELD_SPECS = {
|
|
5871
|
+
second: {
|
|
5872
|
+
kind: "second",
|
|
5873
|
+
min: 0,
|
|
5874
|
+
max: 59
|
|
5875
|
+
},
|
|
5876
|
+
minute: {
|
|
5877
|
+
kind: "minute",
|
|
5878
|
+
min: 0,
|
|
5879
|
+
max: 59
|
|
5880
|
+
},
|
|
5881
|
+
hour: {
|
|
5882
|
+
kind: "hour",
|
|
5883
|
+
min: 0,
|
|
5884
|
+
max: 23
|
|
5885
|
+
},
|
|
5886
|
+
dayOfMonth: {
|
|
5887
|
+
kind: "dayOfMonth",
|
|
5888
|
+
min: 1,
|
|
5889
|
+
max: 31
|
|
5890
|
+
},
|
|
5891
|
+
month: {
|
|
5892
|
+
kind: "month",
|
|
5893
|
+
min: 1,
|
|
5894
|
+
max: 12,
|
|
5895
|
+
names: CRON_MONTH_NAMES
|
|
5896
|
+
},
|
|
5897
|
+
dayOfWeek: {
|
|
5898
|
+
kind: "dayOfWeek",
|
|
5899
|
+
min: 0,
|
|
5900
|
+
max: 7,
|
|
5901
|
+
names: CRON_DAY_NAMES
|
|
5902
|
+
},
|
|
5903
|
+
year: {
|
|
5904
|
+
kind: "year",
|
|
5905
|
+
min: 1970,
|
|
5906
|
+
max: 2099
|
|
5907
|
+
}
|
|
5908
|
+
};
|
|
5909
|
+
function cron(options = {}) {
|
|
5910
|
+
const metavar$1 = options.metavar ?? "CRON";
|
|
5911
|
+
require_nonempty.ensureNonEmptyString(metavar$1);
|
|
5912
|
+
checkBooleanOption(options, "seconds");
|
|
5913
|
+
checkBooleanOption(options, "years");
|
|
5914
|
+
checkBooleanOption(options, "quartz");
|
|
5915
|
+
const seconds = options.seconds ?? false;
|
|
5916
|
+
const years = options.years ?? false;
|
|
5917
|
+
const quartz = options.quartz ?? false;
|
|
5918
|
+
const invalidCronError = options.errors?.invalidCron;
|
|
5919
|
+
const expectedFieldCount = 5 + (seconds ? 1 : 0) + (years ? 1 : 0);
|
|
5920
|
+
function makeError(input) {
|
|
5921
|
+
const error = invalidCronError instanceof Function ? invalidCronError(input) : invalidCronError ?? require_message.message`Expected a valid cron expression, but got ${input}.`;
|
|
5922
|
+
return {
|
|
5923
|
+
success: false,
|
|
5924
|
+
error
|
|
5925
|
+
};
|
|
5926
|
+
}
|
|
5927
|
+
function parseCron(input) {
|
|
5928
|
+
const fields = input.trim() === "" ? [] : input.trim().split(/\s+/u);
|
|
5929
|
+
if (fields.length !== expectedFieldCount) return makeError(input);
|
|
5930
|
+
let index = 0;
|
|
5931
|
+
const second = seconds ? fields[index++] : void 0;
|
|
5932
|
+
const minute = fields[index++];
|
|
5933
|
+
const hour = fields[index++];
|
|
5934
|
+
const dayOfMonth = fields[index++];
|
|
5935
|
+
const month = fields[index++];
|
|
5936
|
+
const dayOfWeek = fields[index++];
|
|
5937
|
+
const year = years ? fields[index++] : void 0;
|
|
5938
|
+
const fieldChecks = [
|
|
5939
|
+
[second, CRON_FIELD_SPECS.second],
|
|
5940
|
+
[minute, CRON_FIELD_SPECS.minute],
|
|
5941
|
+
[hour, CRON_FIELD_SPECS.hour],
|
|
5942
|
+
[dayOfMonth, CRON_FIELD_SPECS.dayOfMonth],
|
|
5943
|
+
[month, CRON_FIELD_SPECS.month],
|
|
5944
|
+
[dayOfWeek, CRON_FIELD_SPECS.dayOfWeek],
|
|
5945
|
+
[year, CRON_FIELD_SPECS.year]
|
|
5946
|
+
];
|
|
5947
|
+
for (const [field, spec] of fieldChecks) if (field !== void 0 && !isValidCronField(field, spec, { quartz })) return makeError(input);
|
|
5948
|
+
if (quartz && dayOfMonth === "?" && dayOfWeek === "?") return makeError(input);
|
|
5949
|
+
return {
|
|
5950
|
+
success: true,
|
|
5951
|
+
value: {
|
|
5952
|
+
...second !== void 0 ? { second } : {},
|
|
5953
|
+
minute,
|
|
5954
|
+
hour,
|
|
5955
|
+
dayOfMonth,
|
|
5956
|
+
month,
|
|
5957
|
+
dayOfWeek,
|
|
5958
|
+
...year !== void 0 ? { year } : {}
|
|
5959
|
+
}
|
|
5960
|
+
};
|
|
5961
|
+
}
|
|
5962
|
+
return {
|
|
5963
|
+
mode: "sync",
|
|
5964
|
+
metavar: metavar$1,
|
|
5965
|
+
placeholder: {
|
|
5966
|
+
...seconds ? { second: "0" } : {},
|
|
5967
|
+
minute: "0",
|
|
5968
|
+
hour: "0",
|
|
5969
|
+
dayOfMonth: "*",
|
|
5970
|
+
month: "*",
|
|
5971
|
+
dayOfWeek: "*",
|
|
5972
|
+
...years ? { year: "1970" } : {}
|
|
5973
|
+
},
|
|
5974
|
+
parse: parseCron,
|
|
5975
|
+
format(value) {
|
|
5976
|
+
return [
|
|
5977
|
+
...seconds ? [value.second ?? "0"] : [],
|
|
5978
|
+
value.minute,
|
|
5979
|
+
value.hour,
|
|
5980
|
+
value.dayOfMonth,
|
|
5981
|
+
value.month,
|
|
5982
|
+
value.dayOfWeek,
|
|
5983
|
+
...years ? [value.year ?? "1970"] : []
|
|
5984
|
+
].join(" ");
|
|
5985
|
+
},
|
|
5986
|
+
validate(value) {
|
|
5987
|
+
if (seconds && value.second == null || years && value.year == null) return makeError(this.format(value));
|
|
5988
|
+
if (!seconds && value.second != null || !years && value.year != null) return makeError(this.format(value));
|
|
5989
|
+
const result = parseCron(this.format(value));
|
|
5990
|
+
return result.success ? {
|
|
5991
|
+
success: true,
|
|
5992
|
+
value: result.value
|
|
5993
|
+
} : result;
|
|
5994
|
+
}
|
|
5995
|
+
};
|
|
5996
|
+
}
|
|
5997
|
+
function isValidCronField(field, spec, options) {
|
|
5998
|
+
if (field === "") return false;
|
|
5999
|
+
const parts = field.split(",");
|
|
6000
|
+
const standard = !parts.some((part) => part === "") && parts.every((part) => isValidCronFieldPart(part, spec));
|
|
6001
|
+
return standard || isQuartzCronField(field, spec, options.quartz);
|
|
6002
|
+
}
|
|
6003
|
+
function isQuartzCronField(field, spec, quartz) {
|
|
6004
|
+
if (!quartz) return false;
|
|
6005
|
+
const upper = field.toUpperCase();
|
|
6006
|
+
if (upper === "?") return spec.kind === "dayOfMonth" || spec.kind === "dayOfWeek";
|
|
6007
|
+
if (spec.kind === "dayOfMonth") {
|
|
6008
|
+
if (upper === "L" || upper === "LW") return true;
|
|
6009
|
+
const match = /^(?<day>\d{1,2})W$/u.exec(upper);
|
|
6010
|
+
return match != null && isCronValueInRange(match.groups.day, spec);
|
|
6011
|
+
}
|
|
6012
|
+
if (spec.kind === "dayOfWeek") {
|
|
6013
|
+
if (upper === "L") return true;
|
|
6014
|
+
const lastMatch = /^(?<day>[A-Z]{3}|\d)L$/u.exec(upper);
|
|
6015
|
+
if (lastMatch != null) return parseQuartzDayOfWeekSuffixValue(lastMatch.groups.day);
|
|
6016
|
+
const nthMatch = /^(?<day>[A-Z]{3}|\d)#(?<nth>[1-5])$/u.exec(upper);
|
|
6017
|
+
if (nthMatch != null) return parseQuartzDayOfWeekSuffixValue(nthMatch.groups.day);
|
|
6018
|
+
}
|
|
6019
|
+
return false;
|
|
6020
|
+
}
|
|
6021
|
+
function parseQuartzDayOfWeekSuffixValue(value) {
|
|
6022
|
+
if (/^[1-7]$/u.test(value)) return true;
|
|
6023
|
+
if (!/^[A-Z]{3}$/u.test(value)) return false;
|
|
6024
|
+
return CRON_DAY_NAMES.has(value);
|
|
6025
|
+
}
|
|
6026
|
+
function isValidCronFieldPart(part, spec) {
|
|
6027
|
+
const stepParts = part.split("/");
|
|
6028
|
+
if (stepParts.length > 2) return false;
|
|
6029
|
+
const [base, step] = stepParts;
|
|
6030
|
+
if (base === "") return false;
|
|
6031
|
+
if (step !== void 0 && !isPositiveCronStep(step)) return false;
|
|
6032
|
+
if (base === "*") return true;
|
|
6033
|
+
const rangeParts = base.split("-");
|
|
6034
|
+
if (rangeParts.length === 1) return parseCronValue(base, spec) !== void 0;
|
|
6035
|
+
if (rangeParts.length !== 2) return false;
|
|
6036
|
+
const [rawStart, rawEnd] = rangeParts;
|
|
6037
|
+
if (rawStart === "" || rawEnd === "") return false;
|
|
6038
|
+
const start = parseCronValue(rawStart, spec);
|
|
6039
|
+
const end = parseCronRangeEnd(rawStart, rawEnd, spec);
|
|
6040
|
+
return start !== void 0 && end !== void 0 && start <= end;
|
|
6041
|
+
}
|
|
6042
|
+
function isPositiveCronStep(step) {
|
|
6043
|
+
return /^\d+$/u.test(step) && Number.parseInt(step, 10) > 0;
|
|
6044
|
+
}
|
|
6045
|
+
function isCronValueInRange(value, spec) {
|
|
6046
|
+
return parseCronValue(value, spec) !== void 0;
|
|
6047
|
+
}
|
|
6048
|
+
function parseCronRangeEnd(start, end, spec) {
|
|
6049
|
+
if (spec.kind === "dayOfWeek" && start.toUpperCase() !== "SUN" && (end.toUpperCase() === "SUN" || end === "0")) return 7;
|
|
6050
|
+
return parseCronValue(end, spec);
|
|
6051
|
+
}
|
|
6052
|
+
function parseCronValue(value, spec) {
|
|
6053
|
+
const named = spec.names?.get(value.toUpperCase());
|
|
6054
|
+
if (named !== void 0) return named;
|
|
6055
|
+
if (!/^\d+$/u.test(value)) return void 0;
|
|
6056
|
+
const number = Number.parseInt(value, 10);
|
|
6057
|
+
return number >= spec.min && number <= spec.max ? number : void 0;
|
|
6058
|
+
}
|
|
5847
6059
|
/**
|
|
5848
6060
|
* Implementation of the {@link firstOf} combinator.
|
|
5849
6061
|
*/
|
|
@@ -6102,6 +6314,7 @@ exports.checkEnumOption = checkEnumOption;
|
|
|
6102
6314
|
exports.choice = choice;
|
|
6103
6315
|
exports.cidr = cidr;
|
|
6104
6316
|
exports.color = color;
|
|
6317
|
+
exports.cron = cron;
|
|
6105
6318
|
exports.domain = domain;
|
|
6106
6319
|
exports.email = email;
|
|
6107
6320
|
exports.ensureNonEmptyString = require_nonempty.ensureNonEmptyString;
|
package/dist/valueparser.d.cts
CHANGED
|
@@ -2882,6 +2882,114 @@ declare function json(options: JsonOptions & {
|
|
|
2882
2882
|
* @since 1.1.0
|
|
2883
2883
|
*/
|
|
2884
2884
|
declare function json(options?: JsonOptions): ValueParser<"sync", Json>;
|
|
2885
|
+
/**
|
|
2886
|
+
* A validated cron schedule expression split into cron fields.
|
|
2887
|
+
*
|
|
2888
|
+
* The `second` field is present when {@link cron} is configured with
|
|
2889
|
+
* `seconds: true`, and the `year` field is present when it is configured
|
|
2890
|
+
* with `years: true`.
|
|
2891
|
+
*
|
|
2892
|
+
* @since 1.2.0
|
|
2893
|
+
*/
|
|
2894
|
+
interface CronExpression {
|
|
2895
|
+
/** Seconds field, when enabled via `seconds: true`. */
|
|
2896
|
+
readonly second?: string;
|
|
2897
|
+
/** Minutes field. */
|
|
2898
|
+
readonly minute: string;
|
|
2899
|
+
/** Hours field. */
|
|
2900
|
+
readonly hour: string;
|
|
2901
|
+
/** Day-of-month field. */
|
|
2902
|
+
readonly dayOfMonth: string;
|
|
2903
|
+
/** Month field. */
|
|
2904
|
+
readonly month: string;
|
|
2905
|
+
/** Day-of-week field. */
|
|
2906
|
+
readonly dayOfWeek: string;
|
|
2907
|
+
/** Year field, when enabled via `years: true`. */
|
|
2908
|
+
readonly year?: string;
|
|
2909
|
+
}
|
|
2910
|
+
/**
|
|
2911
|
+
* Options for creating a {@link cron} value parser.
|
|
2912
|
+
*
|
|
2913
|
+
* @since 1.2.0
|
|
2914
|
+
*/
|
|
2915
|
+
interface CronOptions {
|
|
2916
|
+
/**
|
|
2917
|
+
* The metavariable name for this parser.
|
|
2918
|
+
* @default `"CRON"`
|
|
2919
|
+
*/
|
|
2920
|
+
readonly metavar?: NonEmptyString;
|
|
2921
|
+
/**
|
|
2922
|
+
* Whether to require a leading seconds field.
|
|
2923
|
+
* @default `false`
|
|
2924
|
+
*/
|
|
2925
|
+
readonly seconds?: boolean;
|
|
2926
|
+
/**
|
|
2927
|
+
* Whether to require a trailing year field.
|
|
2928
|
+
* @default `false`
|
|
2929
|
+
*/
|
|
2930
|
+
readonly years?: boolean;
|
|
2931
|
+
/**
|
|
2932
|
+
* Whether to allow common Quartz day-field extensions such as `?`, `L`,
|
|
2933
|
+
* `W`, and `#`.
|
|
2934
|
+
* @default `false`
|
|
2935
|
+
*/
|
|
2936
|
+
readonly quartz?: boolean;
|
|
2937
|
+
/**
|
|
2938
|
+
* Custom error messages for cron parsing failures.
|
|
2939
|
+
*
|
|
2940
|
+
* @since 1.2.0
|
|
2941
|
+
*/
|
|
2942
|
+
readonly errors?: {
|
|
2943
|
+
/**
|
|
2944
|
+
* Custom error message when the input is not a valid cron expression.
|
|
2945
|
+
* Can be a static message or a function that receives the raw input.
|
|
2946
|
+
*/
|
|
2947
|
+
readonly invalidCron?: Message | ((input: string) => Message);
|
|
2948
|
+
};
|
|
2949
|
+
}
|
|
2950
|
+
/**
|
|
2951
|
+
* Cron expression result type for a specific {@link cron} option set.
|
|
2952
|
+
*
|
|
2953
|
+
* When `seconds: true` is configured, the `second` field is required in the
|
|
2954
|
+
* parser result. When `years: true` is configured, the `year` field is
|
|
2955
|
+
* required in the parser result.
|
|
2956
|
+
*
|
|
2957
|
+
* @since 1.2.0
|
|
2958
|
+
*/
|
|
2959
|
+
type CronExpressionForOptions<O extends CronOptions> = Omit<CronExpression, "second" | "year"> & (O["seconds"] extends true ? {
|
|
2960
|
+
readonly second: string;
|
|
2961
|
+
} : {
|
|
2962
|
+
readonly second?: string;
|
|
2963
|
+
}) & (O["years"] extends true ? {
|
|
2964
|
+
readonly year: string;
|
|
2965
|
+
} : {
|
|
2966
|
+
readonly year?: string;
|
|
2967
|
+
});
|
|
2968
|
+
/**
|
|
2969
|
+
* Creates a {@link ValueParser} for cron schedule expressions.
|
|
2970
|
+
*
|
|
2971
|
+
* By default, the parser accepts standard five-field cron expressions:
|
|
2972
|
+
* minute, hour, day of month, month, and day of week. Enable
|
|
2973
|
+
* {@link CronOptions.seconds} to require a leading seconds field, and
|
|
2974
|
+
* {@link CronOptions.years} to require a trailing year field. Successful
|
|
2975
|
+
* parses return a {@link CronExpression} object whose fields preserve the
|
|
2976
|
+
* validated cron field expressions.
|
|
2977
|
+
*
|
|
2978
|
+
* The standard syntax supports `*`, numeric values, ranges (`1-5`), lists
|
|
2979
|
+
* (`1,2,3`), intervals (for example every five units or `1-10/2`), and
|
|
2980
|
+
* month/day names such as
|
|
2981
|
+
* `JAN` and `MON`. Enable {@link CronOptions.quartz} to allow common Quartz
|
|
2982
|
+
* day-field tokens: `?`, `L`, `LW`, `nW`, `nL`, and `n#k`.
|
|
2983
|
+
*
|
|
2984
|
+
* @param options Configuration options.
|
|
2985
|
+
* @returns A sync value parser producing {@link CronExpressionForOptions}
|
|
2986
|
+
* objects for the configured options.
|
|
2987
|
+
* @throws {TypeError} If `options.metavar` is an empty string.
|
|
2988
|
+
* @throws {TypeError} If `seconds`, `years`, or `quartz` is not a boolean.
|
|
2989
|
+
* @since 1.2.0
|
|
2990
|
+
*/
|
|
2991
|
+
declare function cron(): ValueParser<"sync", CronExpression>;
|
|
2992
|
+
declare function cron<const O extends CronOptions>(options: O): ValueParser<"sync", CronExpressionForOptions<O>>;
|
|
2885
2993
|
/**
|
|
2886
2994
|
* Options for the {@link firstOf} combinator.
|
|
2887
2995
|
* @since 1.1.0
|
|
@@ -3058,4 +3166,4 @@ declare function firstOf<const TParsers extends readonly [ValueParser<"sync", un
|
|
|
3058
3166
|
*/
|
|
3059
3167
|
declare function firstOf<const TParsers extends readonly ValueParser<"sync", unknown>[]>(parsers: TParsers, options?: FirstOfOptions): ValueParser<"sync", ValueParserValue<TParsers[number]>>;
|
|
3060
3168
|
//#endregion
|
|
3061
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, 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, firstOf, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
|
|
3169
|
+
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, 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, cron, domain, email, ensureNonEmptyString, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -2882,6 +2882,114 @@ declare function json(options: JsonOptions & {
|
|
|
2882
2882
|
* @since 1.1.0
|
|
2883
2883
|
*/
|
|
2884
2884
|
declare function json(options?: JsonOptions): ValueParser<"sync", Json>;
|
|
2885
|
+
/**
|
|
2886
|
+
* A validated cron schedule expression split into cron fields.
|
|
2887
|
+
*
|
|
2888
|
+
* The `second` field is present when {@link cron} is configured with
|
|
2889
|
+
* `seconds: true`, and the `year` field is present when it is configured
|
|
2890
|
+
* with `years: true`.
|
|
2891
|
+
*
|
|
2892
|
+
* @since 1.2.0
|
|
2893
|
+
*/
|
|
2894
|
+
interface CronExpression {
|
|
2895
|
+
/** Seconds field, when enabled via `seconds: true`. */
|
|
2896
|
+
readonly second?: string;
|
|
2897
|
+
/** Minutes field. */
|
|
2898
|
+
readonly minute: string;
|
|
2899
|
+
/** Hours field. */
|
|
2900
|
+
readonly hour: string;
|
|
2901
|
+
/** Day-of-month field. */
|
|
2902
|
+
readonly dayOfMonth: string;
|
|
2903
|
+
/** Month field. */
|
|
2904
|
+
readonly month: string;
|
|
2905
|
+
/** Day-of-week field. */
|
|
2906
|
+
readonly dayOfWeek: string;
|
|
2907
|
+
/** Year field, when enabled via `years: true`. */
|
|
2908
|
+
readonly year?: string;
|
|
2909
|
+
}
|
|
2910
|
+
/**
|
|
2911
|
+
* Options for creating a {@link cron} value parser.
|
|
2912
|
+
*
|
|
2913
|
+
* @since 1.2.0
|
|
2914
|
+
*/
|
|
2915
|
+
interface CronOptions {
|
|
2916
|
+
/**
|
|
2917
|
+
* The metavariable name for this parser.
|
|
2918
|
+
* @default `"CRON"`
|
|
2919
|
+
*/
|
|
2920
|
+
readonly metavar?: NonEmptyString;
|
|
2921
|
+
/**
|
|
2922
|
+
* Whether to require a leading seconds field.
|
|
2923
|
+
* @default `false`
|
|
2924
|
+
*/
|
|
2925
|
+
readonly seconds?: boolean;
|
|
2926
|
+
/**
|
|
2927
|
+
* Whether to require a trailing year field.
|
|
2928
|
+
* @default `false`
|
|
2929
|
+
*/
|
|
2930
|
+
readonly years?: boolean;
|
|
2931
|
+
/**
|
|
2932
|
+
* Whether to allow common Quartz day-field extensions such as `?`, `L`,
|
|
2933
|
+
* `W`, and `#`.
|
|
2934
|
+
* @default `false`
|
|
2935
|
+
*/
|
|
2936
|
+
readonly quartz?: boolean;
|
|
2937
|
+
/**
|
|
2938
|
+
* Custom error messages for cron parsing failures.
|
|
2939
|
+
*
|
|
2940
|
+
* @since 1.2.0
|
|
2941
|
+
*/
|
|
2942
|
+
readonly errors?: {
|
|
2943
|
+
/**
|
|
2944
|
+
* Custom error message when the input is not a valid cron expression.
|
|
2945
|
+
* Can be a static message or a function that receives the raw input.
|
|
2946
|
+
*/
|
|
2947
|
+
readonly invalidCron?: Message | ((input: string) => Message);
|
|
2948
|
+
};
|
|
2949
|
+
}
|
|
2950
|
+
/**
|
|
2951
|
+
* Cron expression result type for a specific {@link cron} option set.
|
|
2952
|
+
*
|
|
2953
|
+
* When `seconds: true` is configured, the `second` field is required in the
|
|
2954
|
+
* parser result. When `years: true` is configured, the `year` field is
|
|
2955
|
+
* required in the parser result.
|
|
2956
|
+
*
|
|
2957
|
+
* @since 1.2.0
|
|
2958
|
+
*/
|
|
2959
|
+
type CronExpressionForOptions<O extends CronOptions> = Omit<CronExpression, "second" | "year"> & (O["seconds"] extends true ? {
|
|
2960
|
+
readonly second: string;
|
|
2961
|
+
} : {
|
|
2962
|
+
readonly second?: string;
|
|
2963
|
+
}) & (O["years"] extends true ? {
|
|
2964
|
+
readonly year: string;
|
|
2965
|
+
} : {
|
|
2966
|
+
readonly year?: string;
|
|
2967
|
+
});
|
|
2968
|
+
/**
|
|
2969
|
+
* Creates a {@link ValueParser} for cron schedule expressions.
|
|
2970
|
+
*
|
|
2971
|
+
* By default, the parser accepts standard five-field cron expressions:
|
|
2972
|
+
* minute, hour, day of month, month, and day of week. Enable
|
|
2973
|
+
* {@link CronOptions.seconds} to require a leading seconds field, and
|
|
2974
|
+
* {@link CronOptions.years} to require a trailing year field. Successful
|
|
2975
|
+
* parses return a {@link CronExpression} object whose fields preserve the
|
|
2976
|
+
* validated cron field expressions.
|
|
2977
|
+
*
|
|
2978
|
+
* The standard syntax supports `*`, numeric values, ranges (`1-5`), lists
|
|
2979
|
+
* (`1,2,3`), intervals (for example every five units or `1-10/2`), and
|
|
2980
|
+
* month/day names such as
|
|
2981
|
+
* `JAN` and `MON`. Enable {@link CronOptions.quartz} to allow common Quartz
|
|
2982
|
+
* day-field tokens: `?`, `L`, `LW`, `nW`, `nL`, and `n#k`.
|
|
2983
|
+
*
|
|
2984
|
+
* @param options Configuration options.
|
|
2985
|
+
* @returns A sync value parser producing {@link CronExpressionForOptions}
|
|
2986
|
+
* objects for the configured options.
|
|
2987
|
+
* @throws {TypeError} If `options.metavar` is an empty string.
|
|
2988
|
+
* @throws {TypeError} If `seconds`, `years`, or `quartz` is not a boolean.
|
|
2989
|
+
* @since 1.2.0
|
|
2990
|
+
*/
|
|
2991
|
+
declare function cron(): ValueParser<"sync", CronExpression>;
|
|
2992
|
+
declare function cron<const O extends CronOptions>(options: O): ValueParser<"sync", CronExpressionForOptions<O>>;
|
|
2885
2993
|
/**
|
|
2886
2994
|
* Options for the {@link firstOf} combinator.
|
|
2887
2995
|
* @since 1.1.0
|
|
@@ -3058,4 +3166,4 @@ declare function firstOf<const TParsers extends readonly [ValueParser<"sync", un
|
|
|
3058
3166
|
*/
|
|
3059
3167
|
declare function firstOf<const TParsers extends readonly ValueParser<"sync", unknown>[]>(parsers: TParsers, options?: FirstOfOptions): ValueParser<"sync", ValueParserValue<TParsers[number]>>;
|
|
3060
3168
|
//#endregion
|
|
3061
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, 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, firstOf, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
|
|
3169
|
+
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, CronExpression, CronExpressionForOptions, CronOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FirstOfOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, Json, JsonOptions, KeyValueOptions, 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, cron, domain, email, ensureNonEmptyString, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
|
package/dist/valueparser.js
CHANGED
|
@@ -5844,6 +5844,218 @@ function findNonFiniteNumber(root) {
|
|
|
5844
5844
|
}
|
|
5845
5845
|
return void 0;
|
|
5846
5846
|
}
|
|
5847
|
+
const CRON_MONTH_NAMES = new Map([
|
|
5848
|
+
["JAN", 1],
|
|
5849
|
+
["FEB", 2],
|
|
5850
|
+
["MAR", 3],
|
|
5851
|
+
["APR", 4],
|
|
5852
|
+
["MAY", 5],
|
|
5853
|
+
["JUN", 6],
|
|
5854
|
+
["JUL", 7],
|
|
5855
|
+
["AUG", 8],
|
|
5856
|
+
["SEP", 9],
|
|
5857
|
+
["OCT", 10],
|
|
5858
|
+
["NOV", 11],
|
|
5859
|
+
["DEC", 12]
|
|
5860
|
+
]);
|
|
5861
|
+
const CRON_DAY_NAMES = new Map([
|
|
5862
|
+
["SUN", 0],
|
|
5863
|
+
["MON", 1],
|
|
5864
|
+
["TUE", 2],
|
|
5865
|
+
["WED", 3],
|
|
5866
|
+
["THU", 4],
|
|
5867
|
+
["FRI", 5],
|
|
5868
|
+
["SAT", 6]
|
|
5869
|
+
]);
|
|
5870
|
+
const CRON_FIELD_SPECS = {
|
|
5871
|
+
second: {
|
|
5872
|
+
kind: "second",
|
|
5873
|
+
min: 0,
|
|
5874
|
+
max: 59
|
|
5875
|
+
},
|
|
5876
|
+
minute: {
|
|
5877
|
+
kind: "minute",
|
|
5878
|
+
min: 0,
|
|
5879
|
+
max: 59
|
|
5880
|
+
},
|
|
5881
|
+
hour: {
|
|
5882
|
+
kind: "hour",
|
|
5883
|
+
min: 0,
|
|
5884
|
+
max: 23
|
|
5885
|
+
},
|
|
5886
|
+
dayOfMonth: {
|
|
5887
|
+
kind: "dayOfMonth",
|
|
5888
|
+
min: 1,
|
|
5889
|
+
max: 31
|
|
5890
|
+
},
|
|
5891
|
+
month: {
|
|
5892
|
+
kind: "month",
|
|
5893
|
+
min: 1,
|
|
5894
|
+
max: 12,
|
|
5895
|
+
names: CRON_MONTH_NAMES
|
|
5896
|
+
},
|
|
5897
|
+
dayOfWeek: {
|
|
5898
|
+
kind: "dayOfWeek",
|
|
5899
|
+
min: 0,
|
|
5900
|
+
max: 7,
|
|
5901
|
+
names: CRON_DAY_NAMES
|
|
5902
|
+
},
|
|
5903
|
+
year: {
|
|
5904
|
+
kind: "year",
|
|
5905
|
+
min: 1970,
|
|
5906
|
+
max: 2099
|
|
5907
|
+
}
|
|
5908
|
+
};
|
|
5909
|
+
function cron(options = {}) {
|
|
5910
|
+
const metavar$1 = options.metavar ?? "CRON";
|
|
5911
|
+
ensureNonEmptyString(metavar$1);
|
|
5912
|
+
checkBooleanOption(options, "seconds");
|
|
5913
|
+
checkBooleanOption(options, "years");
|
|
5914
|
+
checkBooleanOption(options, "quartz");
|
|
5915
|
+
const seconds = options.seconds ?? false;
|
|
5916
|
+
const years = options.years ?? false;
|
|
5917
|
+
const quartz = options.quartz ?? false;
|
|
5918
|
+
const invalidCronError = options.errors?.invalidCron;
|
|
5919
|
+
const expectedFieldCount = 5 + (seconds ? 1 : 0) + (years ? 1 : 0);
|
|
5920
|
+
function makeError(input) {
|
|
5921
|
+
const error = invalidCronError instanceof Function ? invalidCronError(input) : invalidCronError ?? message`Expected a valid cron expression, but got ${input}.`;
|
|
5922
|
+
return {
|
|
5923
|
+
success: false,
|
|
5924
|
+
error
|
|
5925
|
+
};
|
|
5926
|
+
}
|
|
5927
|
+
function parseCron(input) {
|
|
5928
|
+
const fields = input.trim() === "" ? [] : input.trim().split(/\s+/u);
|
|
5929
|
+
if (fields.length !== expectedFieldCount) return makeError(input);
|
|
5930
|
+
let index = 0;
|
|
5931
|
+
const second = seconds ? fields[index++] : void 0;
|
|
5932
|
+
const minute = fields[index++];
|
|
5933
|
+
const hour = fields[index++];
|
|
5934
|
+
const dayOfMonth = fields[index++];
|
|
5935
|
+
const month = fields[index++];
|
|
5936
|
+
const dayOfWeek = fields[index++];
|
|
5937
|
+
const year = years ? fields[index++] : void 0;
|
|
5938
|
+
const fieldChecks = [
|
|
5939
|
+
[second, CRON_FIELD_SPECS.second],
|
|
5940
|
+
[minute, CRON_FIELD_SPECS.minute],
|
|
5941
|
+
[hour, CRON_FIELD_SPECS.hour],
|
|
5942
|
+
[dayOfMonth, CRON_FIELD_SPECS.dayOfMonth],
|
|
5943
|
+
[month, CRON_FIELD_SPECS.month],
|
|
5944
|
+
[dayOfWeek, CRON_FIELD_SPECS.dayOfWeek],
|
|
5945
|
+
[year, CRON_FIELD_SPECS.year]
|
|
5946
|
+
];
|
|
5947
|
+
for (const [field, spec] of fieldChecks) if (field !== void 0 && !isValidCronField(field, spec, { quartz })) return makeError(input);
|
|
5948
|
+
if (quartz && dayOfMonth === "?" && dayOfWeek === "?") return makeError(input);
|
|
5949
|
+
return {
|
|
5950
|
+
success: true,
|
|
5951
|
+
value: {
|
|
5952
|
+
...second !== void 0 ? { second } : {},
|
|
5953
|
+
minute,
|
|
5954
|
+
hour,
|
|
5955
|
+
dayOfMonth,
|
|
5956
|
+
month,
|
|
5957
|
+
dayOfWeek,
|
|
5958
|
+
...year !== void 0 ? { year } : {}
|
|
5959
|
+
}
|
|
5960
|
+
};
|
|
5961
|
+
}
|
|
5962
|
+
return {
|
|
5963
|
+
mode: "sync",
|
|
5964
|
+
metavar: metavar$1,
|
|
5965
|
+
placeholder: {
|
|
5966
|
+
...seconds ? { second: "0" } : {},
|
|
5967
|
+
minute: "0",
|
|
5968
|
+
hour: "0",
|
|
5969
|
+
dayOfMonth: "*",
|
|
5970
|
+
month: "*",
|
|
5971
|
+
dayOfWeek: "*",
|
|
5972
|
+
...years ? { year: "1970" } : {}
|
|
5973
|
+
},
|
|
5974
|
+
parse: parseCron,
|
|
5975
|
+
format(value) {
|
|
5976
|
+
return [
|
|
5977
|
+
...seconds ? [value.second ?? "0"] : [],
|
|
5978
|
+
value.minute,
|
|
5979
|
+
value.hour,
|
|
5980
|
+
value.dayOfMonth,
|
|
5981
|
+
value.month,
|
|
5982
|
+
value.dayOfWeek,
|
|
5983
|
+
...years ? [value.year ?? "1970"] : []
|
|
5984
|
+
].join(" ");
|
|
5985
|
+
},
|
|
5986
|
+
validate(value) {
|
|
5987
|
+
if (seconds && value.second == null || years && value.year == null) return makeError(this.format(value));
|
|
5988
|
+
if (!seconds && value.second != null || !years && value.year != null) return makeError(this.format(value));
|
|
5989
|
+
const result = parseCron(this.format(value));
|
|
5990
|
+
return result.success ? {
|
|
5991
|
+
success: true,
|
|
5992
|
+
value: result.value
|
|
5993
|
+
} : result;
|
|
5994
|
+
}
|
|
5995
|
+
};
|
|
5996
|
+
}
|
|
5997
|
+
function isValidCronField(field, spec, options) {
|
|
5998
|
+
if (field === "") return false;
|
|
5999
|
+
const parts = field.split(",");
|
|
6000
|
+
const standard = !parts.some((part) => part === "") && parts.every((part) => isValidCronFieldPart(part, spec));
|
|
6001
|
+
return standard || isQuartzCronField(field, spec, options.quartz);
|
|
6002
|
+
}
|
|
6003
|
+
function isQuartzCronField(field, spec, quartz) {
|
|
6004
|
+
if (!quartz) return false;
|
|
6005
|
+
const upper = field.toUpperCase();
|
|
6006
|
+
if (upper === "?") return spec.kind === "dayOfMonth" || spec.kind === "dayOfWeek";
|
|
6007
|
+
if (spec.kind === "dayOfMonth") {
|
|
6008
|
+
if (upper === "L" || upper === "LW") return true;
|
|
6009
|
+
const match = /^(?<day>\d{1,2})W$/u.exec(upper);
|
|
6010
|
+
return match != null && isCronValueInRange(match.groups.day, spec);
|
|
6011
|
+
}
|
|
6012
|
+
if (spec.kind === "dayOfWeek") {
|
|
6013
|
+
if (upper === "L") return true;
|
|
6014
|
+
const lastMatch = /^(?<day>[A-Z]{3}|\d)L$/u.exec(upper);
|
|
6015
|
+
if (lastMatch != null) return parseQuartzDayOfWeekSuffixValue(lastMatch.groups.day);
|
|
6016
|
+
const nthMatch = /^(?<day>[A-Z]{3}|\d)#(?<nth>[1-5])$/u.exec(upper);
|
|
6017
|
+
if (nthMatch != null) return parseQuartzDayOfWeekSuffixValue(nthMatch.groups.day);
|
|
6018
|
+
}
|
|
6019
|
+
return false;
|
|
6020
|
+
}
|
|
6021
|
+
function parseQuartzDayOfWeekSuffixValue(value) {
|
|
6022
|
+
if (/^[1-7]$/u.test(value)) return true;
|
|
6023
|
+
if (!/^[A-Z]{3}$/u.test(value)) return false;
|
|
6024
|
+
return CRON_DAY_NAMES.has(value);
|
|
6025
|
+
}
|
|
6026
|
+
function isValidCronFieldPart(part, spec) {
|
|
6027
|
+
const stepParts = part.split("/");
|
|
6028
|
+
if (stepParts.length > 2) return false;
|
|
6029
|
+
const [base, step] = stepParts;
|
|
6030
|
+
if (base === "") return false;
|
|
6031
|
+
if (step !== void 0 && !isPositiveCronStep(step)) return false;
|
|
6032
|
+
if (base === "*") return true;
|
|
6033
|
+
const rangeParts = base.split("-");
|
|
6034
|
+
if (rangeParts.length === 1) return parseCronValue(base, spec) !== void 0;
|
|
6035
|
+
if (rangeParts.length !== 2) return false;
|
|
6036
|
+
const [rawStart, rawEnd] = rangeParts;
|
|
6037
|
+
if (rawStart === "" || rawEnd === "") return false;
|
|
6038
|
+
const start = parseCronValue(rawStart, spec);
|
|
6039
|
+
const end = parseCronRangeEnd(rawStart, rawEnd, spec);
|
|
6040
|
+
return start !== void 0 && end !== void 0 && start <= end;
|
|
6041
|
+
}
|
|
6042
|
+
function isPositiveCronStep(step) {
|
|
6043
|
+
return /^\d+$/u.test(step) && Number.parseInt(step, 10) > 0;
|
|
6044
|
+
}
|
|
6045
|
+
function isCronValueInRange(value, spec) {
|
|
6046
|
+
return parseCronValue(value, spec) !== void 0;
|
|
6047
|
+
}
|
|
6048
|
+
function parseCronRangeEnd(start, end, spec) {
|
|
6049
|
+
if (spec.kind === "dayOfWeek" && start.toUpperCase() !== "SUN" && (end.toUpperCase() === "SUN" || end === "0")) return 7;
|
|
6050
|
+
return parseCronValue(end, spec);
|
|
6051
|
+
}
|
|
6052
|
+
function parseCronValue(value, spec) {
|
|
6053
|
+
const named = spec.names?.get(value.toUpperCase());
|
|
6054
|
+
if (named !== void 0) return named;
|
|
6055
|
+
if (!/^\d+$/u.test(value)) return void 0;
|
|
6056
|
+
const number = Number.parseInt(value, 10);
|
|
6057
|
+
return number >= spec.min && number <= spec.max ? number : void 0;
|
|
6058
|
+
}
|
|
5847
6059
|
/**
|
|
5848
6060
|
* Implementation of the {@link firstOf} combinator.
|
|
5849
6061
|
*/
|
|
@@ -6097,4 +6309,4 @@ function plainObjectsEqual(a, b) {
|
|
|
6097
6309
|
}
|
|
6098
6310
|
|
|
6099
6311
|
//#endregion
|
|
6100
|
-
export { checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, keyValue, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
|
|
6312
|
+
export { checkBooleanOption, checkEnumOption, choice, cidr, color, cron, domain, email, ensureNonEmptyString, fileSize, firstOf, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, json, keyValue, 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.2.0-dev.
|
|
3
|
+
"version": "1.2.0-dev.2188",
|
|
4
4
|
"description": "Type-safe combinatorial command-line interface parser",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -208,7 +208,7 @@
|
|
|
208
208
|
"fast-check": "^4.7.0",
|
|
209
209
|
"tsdown": "^0.13.0",
|
|
210
210
|
"typescript": "^5.8.3",
|
|
211
|
-
"@optique/env": "1.2.0-dev.
|
|
211
|
+
"@optique/env": "1.2.0-dev.2188+dd035768"
|
|
212
212
|
},
|
|
213
213
|
"scripts": {
|
|
214
214
|
"build": "tsdown",
|