@jakubmazanec/args 2.0.0-unstable.e1ae458 → 2.0.0
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/build/Arguments.js +2 -0
- package/build/Arguments.js.map +7 -0
- package/build/ArgumentsCommand.js +2 -0
- package/build/ArgumentsCommand.js.map +7 -0
- package/{dist → build}/ArgumentsOptions.d.ts +1 -1
- package/build/ArgumentsOptions.js +2 -0
- package/build/ArgumentsOptions.js.map +7 -0
- package/{dist → build}/ArgumentsParameters.d.ts +10 -20
- package/build/ArgumentsParameters.js +2 -0
- package/build/ArgumentsParameters.js.map +7 -0
- package/build/ArgumentsUnknownOptions.js +2 -0
- package/build/ArgumentsUnknownOptions.js.map +7 -0
- package/build/Argv.js +2 -0
- package/build/Argv.js.map +7 -0
- package/build/CommandConfig.js +2 -0
- package/build/CommandConfig.js.map +7 -0
- package/build/CommandsConfig.js +2 -0
- package/build/CommandsConfig.js.map +7 -0
- package/build/LongOptionName.js +2 -0
- package/build/LongOptionName.js.map +7 -0
- package/build/OptionConfig.js +2 -0
- package/build/OptionConfig.js.map +7 -0
- package/build/OptionsConfig.js +2 -0
- package/build/OptionsConfig.js.map +7 -0
- package/build/ParameterConfig.js +2 -0
- package/build/ParameterConfig.js.map +7 -0
- package/build/ParametersConfig.js +2 -0
- package/build/ParametersConfig.js.map +7 -0
- package/build/ParserConfig.js +2 -0
- package/build/ParserConfig.js.map +7 -0
- package/build/ParsingError.js +9 -0
- package/build/ParsingError.js.map +7 -0
- package/build/ShortOptionName.js +2 -0
- package/build/ShortOptionName.js.map +7 -0
- package/build/ValidationError.js +14 -0
- package/build/ValidationError.js.map +7 -0
- package/build/internals/Checker.js +98 -0
- package/build/internals/Checker.js.map +7 -0
- package/build/internals/CommandScope.js +44 -0
- package/build/internals/CommandScope.js.map +7 -0
- package/build/internals/NormalizedCommandConfig.js +2 -0
- package/build/internals/NormalizedCommandConfig.js.map +7 -0
- package/build/internals/NormalizedCommandsConfig.js +2 -0
- package/build/internals/NormalizedCommandsConfig.js.map +7 -0
- package/build/internals/OptionScope.js +69 -0
- package/build/internals/OptionScope.js.map +7 -0
- package/build/internals/castValue.js +17 -0
- package/build/internals/castValue.js.map +7 -0
- package/build/internals/commandToArguments.js +14 -0
- package/build/internals/commandToArguments.js.map +7 -0
- package/build/internals/createOptionShortNameMap.js +11 -0
- package/build/internals/createOptionShortNameMap.js.map +7 -0
- package/build/internals/expandArguments.js +14 -0
- package/build/internals/expandArguments.js.map +7 -0
- package/build/internals/isCommand.js +6 -0
- package/build/internals/isCommand.js.map +7 -0
- package/build/internals/isFalseString.js +6 -0
- package/build/internals/isFalseString.js.map +7 -0
- package/build/internals/isLongOption.js +6 -0
- package/build/internals/isLongOption.js.map +7 -0
- package/build/internals/isOptionLike.js +6 -0
- package/build/internals/isOptionLike.js.map +7 -0
- package/build/internals/isShortOption.js +6 -0
- package/build/internals/isShortOption.js.map +7 -0
- package/build/internals/isShortOptionsGroup.js +6 -0
- package/build/internals/isShortOptionsGroup.js.map +7 -0
- package/build/internals/isTrueString.js +6 -0
- package/build/internals/isTrueString.js.map +7 -0
- package/build/internals.js +18 -0
- package/build/internals.js.map +7 -0
- package/build/main.js +20 -0
- package/build/main.js.map +7 -0
- package/build/parseArguments.js +236 -0
- package/build/parseArguments.js.map +7 -0
- package/package.json +25 -14
- package/{src → source}/ArgumentsCommand.ts +3 -4
- package/source/ArgumentsOptions.ts +82 -0
- package/source/ArgumentsParameters.ts +149 -0
- package/source/ArgumentsUnknownOptions.ts +5 -0
- package/{src → source}/internals/Checker.ts +6 -6
- package/{src → source}/internals/OptionScope.ts +1 -1
- package/{src → source}/internals/castValue.ts +13 -12
- package/{src → source}/internals/commandToArguments.ts +4 -6
- package/{src → source}/parseArguments.ts +18 -28
- package/dist/Arguments.js +0 -5
- package/dist/Arguments.js.map +0 -1
- package/dist/ArgumentsCommand.js +0 -3
- package/dist/ArgumentsCommand.js.map +0 -1
- package/dist/ArgumentsOptions.js +0 -3
- package/dist/ArgumentsOptions.js.map +0 -1
- package/dist/ArgumentsParameters.js +0 -3
- package/dist/ArgumentsParameters.js.map +0 -1
- package/dist/ArgumentsUnknownOptions.js +0 -3
- package/dist/ArgumentsUnknownOptions.js.map +0 -1
- package/dist/Argv.js +0 -3
- package/dist/Argv.js.map +0 -1
- package/dist/CommandConfig.js +0 -3
- package/dist/CommandConfig.js.map +0 -1
- package/dist/CommandsConfig.js +0 -3
- package/dist/CommandsConfig.js.map +0 -1
- package/dist/LongOptionName.js +0 -3
- package/dist/LongOptionName.js.map +0 -1
- package/dist/OptionConfig.js +0 -3
- package/dist/OptionConfig.js.map +0 -1
- package/dist/OptionsConfig.js +0 -3
- package/dist/OptionsConfig.js.map +0 -1
- package/dist/ParameterConfig.js +0 -3
- package/dist/ParameterConfig.js.map +0 -1
- package/dist/ParametersConfig.js +0 -3
- package/dist/ParametersConfig.js.map +0 -1
- package/dist/ParserConfig.js +0 -3
- package/dist/ParserConfig.js.map +0 -1
- package/dist/ParsingError.js +0 -11
- package/dist/ParsingError.js.map +0 -1
- package/dist/ShortOptionName.js +0 -3
- package/dist/ShortOptionName.js.map +0 -1
- package/dist/ValidationError.js +0 -16
- package/dist/ValidationError.js.map +0 -1
- package/dist/internals/Checker.js +0 -115
- package/dist/internals/Checker.js.map +0 -1
- package/dist/internals/CommandScope.js +0 -48
- package/dist/internals/CommandScope.js.map +0 -1
- package/dist/internals/NormalizedCommandConfig.js +0 -3
- package/dist/internals/NormalizedCommandConfig.js.map +0 -1
- package/dist/internals/NormalizedCommandsConfig.js +0 -3
- package/dist/internals/NormalizedCommandsConfig.js.map +0 -1
- package/dist/internals/OptionScope.js +0 -87
- package/dist/internals/OptionScope.js.map +0 -1
- package/dist/internals/castValue.js +0 -25
- package/dist/internals/castValue.js.map +0 -1
- package/dist/internals/commandToArguments.js +0 -21
- package/dist/internals/commandToArguments.js.map +0 -1
- package/dist/internals/createOptionShortNameMap.js +0 -16
- package/dist/internals/createOptionShortNameMap.js.map +0 -1
- package/dist/internals/expandArguments.js +0 -21
- package/dist/internals/expandArguments.js.map +0 -1
- package/dist/internals/isCommand.js +0 -11
- package/dist/internals/isCommand.js.map +0 -1
- package/dist/internals/isFalseString.js +0 -10
- package/dist/internals/isFalseString.js.map +0 -1
- package/dist/internals/isLongOption.js +0 -11
- package/dist/internals/isLongOption.js.map +0 -1
- package/dist/internals/isOptionLike.js +0 -11
- package/dist/internals/isOptionLike.js.map +0 -1
- package/dist/internals/isShortOption.js +0 -11
- package/dist/internals/isShortOption.js.map +0 -1
- package/dist/internals/isShortOptionsGroup.js +0 -11
- package/dist/internals/isShortOptionsGroup.js.map +0 -1
- package/dist/internals/isTrueString.js +0 -10
- package/dist/internals/isTrueString.js.map +0 -1
- package/dist/internals.js +0 -18
- package/dist/internals.js.map +0 -1
- package/dist/main.js +0 -20
- package/dist/main.js.map +0 -1
- package/dist/parseArguments.js +0 -244
- package/dist/parseArguments.js.map +0 -1
- package/src/ArgumentsOptions.ts +0 -89
- package/src/ArgumentsParameters.ts +0 -158
- package/src/ArgumentsUnknownOptions.ts +0 -6
- /package/{dist → build}/Arguments.d.ts +0 -0
- /package/{dist → build}/ArgumentsCommand.d.ts +0 -0
- /package/{dist → build}/ArgumentsUnknownOptions.d.ts +0 -0
- /package/{dist → build}/Argv.d.ts +0 -0
- /package/{dist → build}/CommandConfig.d.ts +0 -0
- /package/{dist → build}/CommandsConfig.d.ts +0 -0
- /package/{dist → build}/LongOptionName.d.ts +0 -0
- /package/{dist → build}/OptionConfig.d.ts +0 -0
- /package/{dist → build}/OptionsConfig.d.ts +0 -0
- /package/{dist → build}/ParameterConfig.d.ts +0 -0
- /package/{dist → build}/ParametersConfig.d.ts +0 -0
- /package/{dist → build}/ParserConfig.d.ts +0 -0
- /package/{dist → build}/ParsingError.d.ts +0 -0
- /package/{dist → build}/ShortOptionName.d.ts +0 -0
- /package/{dist → build}/ValidationError.d.ts +0 -0
- /package/{dist → build}/internals/Checker.d.ts +0 -0
- /package/{dist → build}/internals/CommandScope.d.ts +0 -0
- /package/{dist → build}/internals/NormalizedCommandConfig.d.ts +0 -0
- /package/{dist → build}/internals/NormalizedCommandsConfig.d.ts +0 -0
- /package/{dist → build}/internals/OptionScope.d.ts +0 -0
- /package/{dist → build}/internals/castValue.d.ts +0 -0
- /package/{dist → build}/internals/commandToArguments.d.ts +0 -0
- /package/{dist → build}/internals/createOptionShortNameMap.d.ts +0 -0
- /package/{dist → build}/internals/expandArguments.d.ts +0 -0
- /package/{dist → build}/internals/isCommand.d.ts +0 -0
- /package/{dist → build}/internals/isFalseString.d.ts +0 -0
- /package/{dist → build}/internals/isLongOption.d.ts +0 -0
- /package/{dist → build}/internals/isOptionLike.d.ts +0 -0
- /package/{dist → build}/internals/isShortOption.d.ts +0 -0
- /package/{dist → build}/internals/isShortOptionsGroup.d.ts +0 -0
- /package/{dist → build}/internals/isTrueString.d.ts +0 -0
- /package/{dist → build}/internals.d.ts +0 -0
- /package/{dist → build}/main.d.ts +0 -0
- /package/{dist → build}/parseArguments.d.ts +0 -0
- /package/{src → source}/Arguments.ts +0 -0
- /package/{src → source}/Argv.ts +0 -0
- /package/{src → source}/CommandConfig.ts +0 -0
- /package/{src → source}/CommandsConfig.ts +0 -0
- /package/{src → source}/LongOptionName.ts +0 -0
- /package/{src → source}/OptionConfig.ts +0 -0
- /package/{src → source}/OptionsConfig.ts +0 -0
- /package/{src → source}/ParameterConfig.ts +0 -0
- /package/{src → source}/ParametersConfig.ts +0 -0
- /package/{src → source}/ParserConfig.ts +0 -0
- /package/{src → source}/ParsingError.ts +0 -0
- /package/{src → source}/ShortOptionName.ts +0 -0
- /package/{src → source}/ValidationError.ts +0 -0
- /package/{src → source}/internals/CommandScope.ts +0 -0
- /package/{src → source}/internals/NormalizedCommandConfig.ts +0 -0
- /package/{src → source}/internals/NormalizedCommandsConfig.ts +0 -0
- /package/{src → source}/internals/createOptionShortNameMap.ts +0 -0
- /package/{src → source}/internals/expandArguments.ts +0 -0
- /package/{src → source}/internals/isCommand.ts +0 -0
- /package/{src → source}/internals/isFalseString.ts +0 -0
- /package/{src → source}/internals/isLongOption.ts +0 -0
- /package/{src → source}/internals/isOptionLike.ts +0 -0
- /package/{src → source}/internals/isShortOption.ts +0 -0
- /package/{src → source}/internals/isShortOptionsGroup.ts +0 -0
- /package/{src → source}/internals/isTrueString.ts +0 -0
- /package/{src → source}/internals.ts +0 -0
- /package/{src → source}/main.ts +0 -0
package/dist/ParametersConfig.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ParametersConfig.ts"],"sourcesContent":["import {type ParameterConfig} from './ParameterConfig.js';\n\n/** Parser's parameters configuration. */\nexport type ParametersConfig =\n | readonly [\n ParameterConfig,\n ParameterConfig,\n ParameterConfig,\n ParameterConfig,\n ParameterConfig,\n ParameterConfig,\n ]\n | readonly [ParameterConfig, ParameterConfig, ParameterConfig, ParameterConfig, ParameterConfig]\n | readonly [ParameterConfig, ParameterConfig, ParameterConfig, ParameterConfig]\n | readonly [ParameterConfig, ParameterConfig, ParameterConfig]\n | readonly [ParameterConfig, ParameterConfig]\n | readonly [ParameterConfig];\n"],"names":[],"mappings":"AAEA,uCAAuC,GACvC,WAa+B"}
|
package/dist/ParserConfig.js
DELETED
package/dist/ParserConfig.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ParserConfig.ts"],"sourcesContent":["import {type CommandsConfig} from './CommandsConfig.js';\nimport {type OptionsConfig} from './OptionsConfig.js';\nimport {type ParametersConfig} from './ParametersConfig.js';\n\n/** Parser configuration specifies how the command line arguments should be parsed. */\nexport type ParserConfig = {\n /** Commands configuration. */\n commands?: CommandsConfig | undefined;\n\n /** Parameters configuration. */\n parameters?: ParametersConfig | undefined;\n\n /** Options configuration. */\n options?: OptionsConfig | undefined;\n\n /** Allow parsing unknown options. */\n allowUnknownOptions?: boolean | undefined;\n\n /** Allow parsing unknown parameters. */\n allowUnknownParameters?: boolean | undefined;\n};\n"],"names":[],"mappings":"AAIA,oFAAoF,GACpF,WAeE"}
|
package/dist/ParsingError.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { createCustomError } from '@jakubmazanec/error';
|
|
2
|
-
/**
|
|
3
|
-
* A subclass of `Error` that indicates a parsing failure.
|
|
4
|
-
*/ export const ParsingError = createCustomError('ParsingError', {
|
|
5
|
-
INVALID_PARAMETER: 'Invalid parameter value "{0}" found. Allowed values for parameter "{1}" are: {2}.',
|
|
6
|
-
UNKNOWN_PARAMETER: 'Unknown parameter "{0}" found. Unknown parameters are not allowed.',
|
|
7
|
-
INVALID_OPTION: 'Invalid option value "{0}" found. Allowed values for option "{1}" are: {2}.',
|
|
8
|
-
UNKNOWN_OPTION: 'Unknown option "{0}" found. Unknown options are not allowed.'
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=ParsingError.js.map
|
package/dist/ParsingError.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ParsingError.ts"],"sourcesContent":["import {createCustomError} from '@jakubmazanec/error';\n\n/**\n * A subclass of `Error` that indicates a parsing failure.\n */\nexport const ParsingError = createCustomError('ParsingError', {\n INVALID_PARAMETER:\n 'Invalid parameter value \"{0}\" found. Allowed values for parameter \"{1}\" are: {2}.',\n UNKNOWN_PARAMETER: 'Unknown parameter \"{0}\" found. Unknown parameters are not allowed.',\n INVALID_OPTION: 'Invalid option value \"{0}\" found. Allowed values for option \"{1}\" are: {2}.',\n UNKNOWN_OPTION: 'Unknown option \"{0}\" found. Unknown options are not allowed.',\n});\n"],"names":["createCustomError","ParsingError","INVALID_PARAMETER","UNKNOWN_PARAMETER","INVALID_OPTION","UNKNOWN_OPTION"],"mappings":"AAAA,SAAQA,iBAAiB,QAAO,sBAAsB;AAEtD;;CAEC,GACD,OAAO,MAAMC,eAAeD,kBAAkB,gBAAgB;IAC5DE,mBACE;IACFC,mBAAmB;IACnBC,gBAAgB;IAChBC,gBAAgB;AAClB,GAAG"}
|
package/dist/ShortOptionName.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ShortOptionName.ts"],"sourcesContent":["/** Short option name. */\nexport type ShortOptionName =\n | 'A'\n | 'a'\n | 'B'\n | 'b'\n | 'C'\n | 'c'\n | 'D'\n | 'd'\n | 'E'\n | 'e'\n | 'F'\n | 'f'\n | 'G'\n | 'g'\n | 'H'\n | 'h'\n | 'I'\n | 'i'\n | 'J'\n | 'j'\n | 'K'\n | 'k'\n | 'L'\n | 'l'\n | 'M'\n | 'm'\n | 'N'\n | 'n'\n | 'O'\n | 'o'\n | 'P'\n | 'p'\n | 'Q'\n | 'q'\n | 'R'\n | 'r'\n | 'S'\n | 's'\n | 'T'\n | 't'\n | 'U'\n | 'u'\n | 'V'\n | 'v'\n | 'W'\n | 'w'\n | 'X'\n | 'x'\n | 'Y'\n | 'y'\n | 'Z'\n | 'z';\n"],"names":[],"mappings":"AAAA,uBAAuB,GACvB,WAoDQ"}
|
package/dist/ValidationError.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { createCustomError } from '@jakubmazanec/error';
|
|
2
|
-
/**
|
|
3
|
-
* A subclass of `Error` that indicates a validation issue.
|
|
4
|
-
*/ export const ValidationError = createCustomError('ValidationError', {
|
|
5
|
-
INVALID_COMMAND: 'Command "{0}" has invalid format. Only words consisting of letters, numbers or dashes separated by single space are allowed.',
|
|
6
|
-
MISSING_PARAMETER: 'Parameter "{0}" is required but its value is undefined.',
|
|
7
|
-
INVALID_PARAMETER_DEFAULT_AND_CHOICES: 'Parameter "{0}" has invalid default value "{1}". Default value must be one of the `choices` elements.',
|
|
8
|
-
INVALID_PARAMETER_ORDER: 'Parameter "{0}" has invalid order. All parameters before must have a default value or be required too',
|
|
9
|
-
MISSING_OPTION: 'Option "{0}" is required but its value is undefined.',
|
|
10
|
-
INVALID_OPTION_DEFAULT_AND_CHOICES: 'Option "{0}" has invalid default value "{1}". Default value must be one of the `choices` elements.',
|
|
11
|
-
INVALID_OPTION_NAME: 'Option "{0}" has invalid name. Only names consisting of letters, numbers or dashes are allowed.',
|
|
12
|
-
REPEATED_OPTION_NAME: 'Option "{0}" has invalid short name "{1}". Short option names must be unique.',
|
|
13
|
-
INVALID_OPTION_ARITY: 'Option "{0}" has invalid number of values. Found "{1}", require "{2}".'
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=ValidationError.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ValidationError.ts"],"sourcesContent":["import {createCustomError} from '@jakubmazanec/error';\n\n/**\n * A subclass of `Error` that indicates a validation issue.\n */\nexport const ValidationError = createCustomError('ValidationError', {\n INVALID_COMMAND:\n 'Command \"{0}\" has invalid format. Only words consisting of letters, numbers or dashes separated by single space are allowed.',\n MISSING_PARAMETER: 'Parameter \"{0}\" is required but its value is undefined.',\n INVALID_PARAMETER_DEFAULT_AND_CHOICES:\n 'Parameter \"{0}\" has invalid default value \"{1}\". Default value must be one of the `choices` elements.',\n INVALID_PARAMETER_ORDER:\n 'Parameter \"{0}\" has invalid order. All parameters before must have a default value or be required too',\n MISSING_OPTION: 'Option \"{0}\" is required but its value is undefined.',\n INVALID_OPTION_DEFAULT_AND_CHOICES:\n 'Option \"{0}\" has invalid default value \"{1}\". Default value must be one of the `choices` elements.',\n INVALID_OPTION_NAME:\n 'Option \"{0}\" has invalid name. Only names consisting of letters, numbers or dashes are allowed.',\n REPEATED_OPTION_NAME:\n 'Option \"{0}\" has invalid short name \"{1}\". Short option names must be unique.',\n INVALID_OPTION_ARITY: 'Option \"{0}\" has invalid number of values. Found \"{1}\", require \"{2}\".',\n});\n"],"names":["createCustomError","ValidationError","INVALID_COMMAND","MISSING_PARAMETER","INVALID_PARAMETER_DEFAULT_AND_CHOICES","INVALID_PARAMETER_ORDER","MISSING_OPTION","INVALID_OPTION_DEFAULT_AND_CHOICES","INVALID_OPTION_NAME","REPEATED_OPTION_NAME","INVALID_OPTION_ARITY"],"mappings":"AAAA,SAAQA,iBAAiB,QAAO,sBAAsB;AAEtD;;CAEC,GACD,OAAO,MAAMC,kBAAkBD,kBAAkB,mBAAmB;IAClEE,iBACE;IACFC,mBAAmB;IACnBC,uCACE;IACFC,yBACE;IACFC,gBAAgB;IAChBC,oCACE;IACFC,qBACE;IACFC,sBACE;IACFC,sBAAsB;AACxB,GAAG"}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { ValidationError } from '../ValidationError.js';
|
|
2
|
-
import { isCommand } from './isCommand.js';
|
|
3
|
-
import { isLongOption } from './isLongOption.js';
|
|
4
|
-
/**
|
|
5
|
-
* `Checker` is used for handling various checks before, during, and after parsing of the arguments.
|
|
6
|
-
*/ export class Checker {
|
|
7
|
-
errors = [];
|
|
8
|
-
checkCommandsConfig(commandsConfig) {
|
|
9
|
-
for (let commandConfig of commandsConfig){
|
|
10
|
-
if (!isCommand(commandConfig)) {
|
|
11
|
-
this.addError(new ValidationError('INVALID_COMMAND', {
|
|
12
|
-
messageParameters: [
|
|
13
|
-
commandConfig
|
|
14
|
-
]
|
|
15
|
-
}));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
checkParametersConfig(parametersConfig) {
|
|
20
|
-
for (let [i, parameterConfig] of parametersConfig.entries()){
|
|
21
|
-
// types of choices must be correct
|
|
22
|
-
if (parameterConfig.type !== 'boolean' && parameterConfig.choices && // default values and chocies do not contradict each other
|
|
23
|
-
typeof parameterConfig.defaultValue !== 'undefined' && !parameterConfig.choices.includes(parameterConfig.defaultValue)) {
|
|
24
|
-
this.addError(new ValidationError('INVALID_PARAMETER_DEFAULT_AND_CHOICES', {
|
|
25
|
-
messageParameters: [
|
|
26
|
-
parameterConfig.label ?? i,
|
|
27
|
-
parameterConfig.defaultValue
|
|
28
|
-
]
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
31
|
-
// if parameter is required, all parameters before must be required too
|
|
32
|
-
if (i >= 1 && parameterConfig.required === true && !parametersConfig.slice(0, i).every((previousParameterConfig)=>previousParameterConfig.required === true || typeof previousParameterConfig.defaultValue !== 'undefined')) {
|
|
33
|
-
this.addError(new ValidationError('INVALID_PARAMETER_ORDER', {
|
|
34
|
-
messageParameters: [
|
|
35
|
-
parameterConfig.label ?? i
|
|
36
|
-
]
|
|
37
|
-
}));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
checkOptionsConfig(optionsConfig) {
|
|
42
|
-
let usedShortOptionNames = new Set([]);
|
|
43
|
-
for (let [optionName, optionConfig] of Object.entries(optionsConfig)){
|
|
44
|
-
// option names must be in correct format
|
|
45
|
-
if (!isLongOption(`--${optionName}`)) {
|
|
46
|
-
this.addError(new ValidationError('INVALID_OPTION_NAME', {
|
|
47
|
-
messageParameters: [
|
|
48
|
-
optionName
|
|
49
|
-
]
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
// option short names must be unique
|
|
53
|
-
if (optionConfig.shortName && usedShortOptionNames.has(optionConfig.shortName)) {
|
|
54
|
-
this.addError(new ValidationError('REPEATED_OPTION_NAME', {
|
|
55
|
-
messageParameters: [
|
|
56
|
-
optionName,
|
|
57
|
-
optionConfig.shortName
|
|
58
|
-
]
|
|
59
|
-
}));
|
|
60
|
-
} else if (optionConfig.shortName) {
|
|
61
|
-
usedShortOptionNames.add(optionConfig.shortName);
|
|
62
|
-
}
|
|
63
|
-
// default values and chocies do not contradict each other
|
|
64
|
-
if ((optionConfig.type === 'string' || optionConfig.type === 'number' && !optionConfig.count) && optionConfig.choices && typeof optionConfig.defaultValue !== 'undefined' && !optionConfig.choices.includes(optionConfig.defaultValue)) {
|
|
65
|
-
this.addError(new ValidationError('INVALID_OPTION_DEFAULT_AND_CHOICES', {
|
|
66
|
-
messageParameters: [
|
|
67
|
-
optionName,
|
|
68
|
-
optionConfig.defaultValue
|
|
69
|
-
]
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
checkParsedParameters(parametersConfig, parsedParameters) {
|
|
75
|
-
for (let [i, parameterConfig] of parametersConfig.entries()){
|
|
76
|
-
let parsedParameter = parsedParameters[i];
|
|
77
|
-
// required parameters must have value
|
|
78
|
-
if (parameterConfig.required === true && typeof parsedParameter === 'undefined') {
|
|
79
|
-
this.addError(new ValidationError('MISSING_PARAMETER', {
|
|
80
|
-
messageParameters: [
|
|
81
|
-
parameterConfig.label ?? i
|
|
82
|
-
]
|
|
83
|
-
}));
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
checkParsedOptions(optionsConfig, parsedOptions) {
|
|
88
|
-
for (let [optionName, optionConfig] of Object.entries(optionsConfig)){
|
|
89
|
-
let parsedOption = parsedOptions[optionName];
|
|
90
|
-
// check required
|
|
91
|
-
if (optionConfig.required && typeof parsedOption === 'undefined') {
|
|
92
|
-
this.addError(new ValidationError('MISSING_OPTION', {
|
|
93
|
-
messageParameters: [
|
|
94
|
-
optionName
|
|
95
|
-
]
|
|
96
|
-
}));
|
|
97
|
-
}
|
|
98
|
-
// check arity
|
|
99
|
-
if (typeof parsedOption !== 'undefined' && (optionConfig.type === 'string' && optionConfig.multiple || optionConfig.type === 'number' && optionConfig.multiple) && typeof optionConfig.arity === 'number' && Array.isArray(parsedOption) && parsedOption.length > 0 && parsedOption.length !== optionConfig.arity) {
|
|
100
|
-
this.addError(new ValidationError('INVALID_OPTION_ARITY', {
|
|
101
|
-
messageParameters: [
|
|
102
|
-
optionName,
|
|
103
|
-
parsedOption.length,
|
|
104
|
-
optionConfig.arity
|
|
105
|
-
]
|
|
106
|
-
}));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
addError(error) {
|
|
111
|
-
this.errors.push(error);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
//# sourceMappingURL=Checker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/Checker.ts"],"sourcesContent":["import {type CommandsConfig} from '../CommandsConfig.js';\nimport {type OptionsConfig} from '../OptionsConfig.js';\nimport {type ParametersConfig} from '../ParametersConfig.js';\nimport {ValidationError} from '../ValidationError.js';\nimport {isCommand} from './isCommand.js';\nimport {isLongOption} from './isLongOption.js';\n\n/**\n * `Checker` is used for handling various checks before, during, and after parsing of the arguments.\n */\nexport class Checker {\n errors: Error[] = [];\n\n checkCommandsConfig(commandsConfig: CommandsConfig | []) {\n for (let commandConfig of commandsConfig) {\n if (!isCommand(commandConfig)) {\n this.addError(new ValidationError('INVALID_COMMAND', {messageParameters: [commandConfig]}));\n }\n }\n }\n\n checkParametersConfig(parametersConfig: ParametersConfig | []) {\n for (let [i, parameterConfig] of parametersConfig.entries()) {\n // types of choices must be correct\n if (\n parameterConfig.type !== 'boolean' &&\n parameterConfig.choices && // default values and chocies do not contradict each other\n typeof parameterConfig.defaultValue !== 'undefined' &&\n !parameterConfig.choices.includes(parameterConfig.defaultValue as never)\n ) {\n this.addError(\n new ValidationError('INVALID_PARAMETER_DEFAULT_AND_CHOICES', {\n messageParameters: [parameterConfig.label ?? i, parameterConfig.defaultValue],\n }),\n );\n }\n\n // if parameter is required, all parameters before must be required too\n if (\n i >= 1 &&\n parameterConfig.required === true &&\n !parametersConfig\n .slice(0, i)\n .every(\n (previousParameterConfig) =>\n previousParameterConfig.required === true ||\n typeof previousParameterConfig.defaultValue !== 'undefined',\n )\n ) {\n this.addError(\n new ValidationError('INVALID_PARAMETER_ORDER', {\n messageParameters: [parameterConfig.label ?? i],\n }),\n );\n }\n }\n }\n\n checkOptionsConfig(optionsConfig: OptionsConfig) {\n let usedShortOptionNames: Set<string> = new Set([]);\n\n for (let [optionName, optionConfig] of Object.entries(optionsConfig)) {\n // option names must be in correct format\n if (!isLongOption(`--${optionName}`)) {\n this.addError(\n new ValidationError('INVALID_OPTION_NAME', {\n messageParameters: [optionName],\n }),\n );\n }\n\n // option short names must be unique\n if (optionConfig.shortName && usedShortOptionNames.has(optionConfig.shortName)) {\n this.addError(\n new ValidationError('REPEATED_OPTION_NAME', {\n messageParameters: [optionName, optionConfig.shortName],\n }),\n );\n } else if (optionConfig.shortName) {\n usedShortOptionNames.add(optionConfig.shortName);\n }\n\n // default values and chocies do not contradict each other\n if (\n (optionConfig.type === 'string' ||\n (optionConfig.type === 'number' && !optionConfig.count)) &&\n optionConfig.choices &&\n typeof optionConfig.defaultValue !== 'undefined' &&\n !optionConfig.choices.includes(optionConfig.defaultValue as never)\n ) {\n this.addError(\n new ValidationError('INVALID_OPTION_DEFAULT_AND_CHOICES', {\n messageParameters: [optionName, optionConfig.defaultValue],\n }),\n );\n }\n }\n }\n\n checkParsedParameters(parametersConfig: ParametersConfig | [], parsedParameters: unknown[]) {\n for (let [i, parameterConfig] of parametersConfig.entries()) {\n let parsedParameter = parsedParameters[i];\n\n // required parameters must have value\n if (parameterConfig.required === true && typeof parsedParameter === 'undefined') {\n this.addError(\n new ValidationError('MISSING_PARAMETER', {\n messageParameters: [parameterConfig.label ?? i],\n }),\n );\n }\n }\n }\n\n checkParsedOptions(optionsConfig: OptionsConfig, parsedOptions: Record<string, unknown>) {\n for (let [optionName, optionConfig] of Object.entries(optionsConfig)) {\n let parsedOption = parsedOptions[optionName];\n\n // check required\n if (optionConfig.required && typeof parsedOption === 'undefined') {\n this.addError(\n new ValidationError('MISSING_OPTION', {\n messageParameters: [optionName],\n }),\n );\n }\n\n // check arity\n if (\n typeof parsedOption !== 'undefined' &&\n ((optionConfig.type === 'string' && optionConfig.multiple) ||\n (optionConfig.type === 'number' && optionConfig.multiple)) &&\n typeof optionConfig.arity === 'number' &&\n Array.isArray(parsedOption) &&\n (parsedOption as unknown[]).length > 0 &&\n (parsedOption as unknown[]).length !== optionConfig.arity\n ) {\n this.addError(\n new ValidationError('INVALID_OPTION_ARITY', {\n messageParameters: [optionName, (parsedOption as unknown[]).length, optionConfig.arity],\n }),\n );\n }\n }\n }\n\n addError(error: Error) {\n this.errors.push(error);\n }\n}\n"],"names":["ValidationError","isCommand","isLongOption","Checker","errors","checkCommandsConfig","commandsConfig","commandConfig","addError","messageParameters","checkParametersConfig","parametersConfig","i","parameterConfig","entries","type","choices","defaultValue","includes","label","required","slice","every","previousParameterConfig","checkOptionsConfig","optionsConfig","usedShortOptionNames","Set","optionName","optionConfig","Object","shortName","has","add","count","checkParsedParameters","parsedParameters","parsedParameter","checkParsedOptions","parsedOptions","parsedOption","multiple","arity","Array","isArray","length","error","push"],"mappings":"AAGA,SAAQA,eAAe,QAAO,wBAAwB;AACtD,SAAQC,SAAS,QAAO,iBAAiB;AACzC,SAAQC,YAAY,QAAO,oBAAoB;AAE/C;;CAEC,GACD,OAAO,MAAMC;IACXC,SAAkB,EAAE,CAAC;IAErBC,oBAAoBC,cAAmC,EAAE;QACvD,KAAK,IAAIC,iBAAiBD,eAAgB;YACxC,IAAI,CAACL,UAAUM,gBAAgB;gBAC7B,IAAI,CAACC,QAAQ,CAAC,IAAIR,gBAAgB,mBAAmB;oBAACS,mBAAmB;wBAACF;qBAAc;gBAAA;YAC1F;QACF;IACF;IAEAG,sBAAsBC,gBAAuC,EAAE;QAC7D,KAAK,IAAI,CAACC,GAAGC,gBAAgB,IAAIF,iBAAiBG,OAAO,GAAI;YAC3D,mCAAmC;YACnC,IACED,gBAAgBE,IAAI,KAAK,aACzBF,gBAAgBG,OAAO,IAAI,0DAA0D;YACrF,OAAOH,gBAAgBI,YAAY,KAAK,eACxC,CAACJ,gBAAgBG,OAAO,CAACE,QAAQ,CAACL,gBAAgBI,YAAY,GAC9D;gBACA,IAAI,CAACT,QAAQ,CACX,IAAIR,gBAAgB,yCAAyC;oBAC3DS,mBAAmB;wBAACI,gBAAgBM,KAAK,IAAIP;wBAAGC,gBAAgBI,YAAY;qBAAC;gBAC/E;YAEJ;YAEA,uEAAuE;YACvE,IACEL,KAAK,KACLC,gBAAgBO,QAAQ,KAAK,QAC7B,CAACT,iBACEU,KAAK,CAAC,GAAGT,GACTU,KAAK,CACJ,CAACC,0BACCA,wBAAwBH,QAAQ,KAAK,QACrC,OAAOG,wBAAwBN,YAAY,KAAK,cAEtD;gBACA,IAAI,CAACT,QAAQ,CACX,IAAIR,gBAAgB,2BAA2B;oBAC7CS,mBAAmB;wBAACI,gBAAgBM,KAAK,IAAIP;qBAAE;gBACjD;YAEJ;QACF;IACF;IAEAY,mBAAmBC,aAA4B,EAAE;QAC/C,IAAIC,uBAAoC,IAAIC,IAAI,EAAE;QAElD,KAAK,IAAI,CAACC,YAAYC,aAAa,IAAIC,OAAOhB,OAAO,CAACW,eAAgB;YACpE,yCAAyC;YACzC,IAAI,CAACvB,aAAa,CAAC,EAAE,EAAE0B,WAAW,CAAC,GAAG;gBACpC,IAAI,CAACpB,QAAQ,CACX,IAAIR,gBAAgB,uBAAuB;oBACzCS,mBAAmB;wBAACmB;qBAAW;gBACjC;YAEJ;YAEA,oCAAoC;YACpC,IAAIC,aAAaE,SAAS,IAAIL,qBAAqBM,GAAG,CAACH,aAAaE,SAAS,GAAG;gBAC9E,IAAI,CAACvB,QAAQ,CACX,IAAIR,gBAAgB,wBAAwB;oBAC1CS,mBAAmB;wBAACmB;wBAAYC,aAAaE,SAAS;qBAAC;gBACzD;YAEJ,OAAO,IAAIF,aAAaE,SAAS,EAAE;gBACjCL,qBAAqBO,GAAG,CAACJ,aAAaE,SAAS;YACjD;YAEA,0DAA0D;YAC1D,IACE,AAACF,CAAAA,aAAad,IAAI,KAAK,YACpBc,aAAad,IAAI,KAAK,YAAY,CAACc,aAAaK,KAAK,KACxDL,aAAab,OAAO,IACpB,OAAOa,aAAaZ,YAAY,KAAK,eACrC,CAACY,aAAab,OAAO,CAACE,QAAQ,CAACW,aAAaZ,YAAY,GACxD;gBACA,IAAI,CAACT,QAAQ,CACX,IAAIR,gBAAgB,sCAAsC;oBACxDS,mBAAmB;wBAACmB;wBAAYC,aAAaZ,YAAY;qBAAC;gBAC5D;YAEJ;QACF;IACF;IAEAkB,sBAAsBxB,gBAAuC,EAAEyB,gBAA2B,EAAE;QAC1F,KAAK,IAAI,CAACxB,GAAGC,gBAAgB,IAAIF,iBAAiBG,OAAO,GAAI;YAC3D,IAAIuB,kBAAkBD,gBAAgB,CAACxB,EAAE;YAEzC,sCAAsC;YACtC,IAAIC,gBAAgBO,QAAQ,KAAK,QAAQ,OAAOiB,oBAAoB,aAAa;gBAC/E,IAAI,CAAC7B,QAAQ,CACX,IAAIR,gBAAgB,qBAAqB;oBACvCS,mBAAmB;wBAACI,gBAAgBM,KAAK,IAAIP;qBAAE;gBACjD;YAEJ;QACF;IACF;IAEA0B,mBAAmBb,aAA4B,EAAEc,aAAsC,EAAE;QACvF,KAAK,IAAI,CAACX,YAAYC,aAAa,IAAIC,OAAOhB,OAAO,CAACW,eAAgB;YACpE,IAAIe,eAAeD,aAAa,CAACX,WAAW;YAE5C,iBAAiB;YACjB,IAAIC,aAAaT,QAAQ,IAAI,OAAOoB,iBAAiB,aAAa;gBAChE,IAAI,CAAChC,QAAQ,CACX,IAAIR,gBAAgB,kBAAkB;oBACpCS,mBAAmB;wBAACmB;qBAAW;gBACjC;YAEJ;YAEA,cAAc;YACd,IACE,OAAOY,iBAAiB,eACvB,CAAA,AAACX,aAAad,IAAI,KAAK,YAAYc,aAAaY,QAAQ,IACtDZ,aAAad,IAAI,KAAK,YAAYc,aAAaY,QAAQ,KAC1D,OAAOZ,aAAaa,KAAK,KAAK,YAC9BC,MAAMC,OAAO,CAACJ,iBACd,AAACA,aAA2BK,MAAM,GAAG,KACrC,AAACL,aAA2BK,MAAM,KAAKhB,aAAaa,KAAK,EACzD;gBACA,IAAI,CAAClC,QAAQ,CACX,IAAIR,gBAAgB,wBAAwB;oBAC1CS,mBAAmB;wBAACmB;wBAAaY,aAA2BK,MAAM;wBAAEhB,aAAaa,KAAK;qBAAC;gBACzF;YAEJ;QACF;IACF;IAEAlC,SAASsC,KAAY,EAAE;QACrB,IAAI,CAAC1C,MAAM,CAAC2C,IAAI,CAACD;IACnB;AACF"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `CommandScope` handles storing information about parsing of a command.
|
|
3
|
-
*/ export class CommandScope {
|
|
4
|
-
args;
|
|
5
|
-
config;
|
|
6
|
-
constructor(arg, normalizedCommandsConfig){
|
|
7
|
-
let normalizedArgument = arg.toLowerCase();
|
|
8
|
-
let commandConfig = normalizedCommandsConfig.find((commandConfig)=>commandConfig.args[0] === normalizedArgument);
|
|
9
|
-
this.config = commandConfig ?? [];
|
|
10
|
-
this.args = [
|
|
11
|
-
normalizedArgument
|
|
12
|
-
];
|
|
13
|
-
}
|
|
14
|
-
captureArg(arg) {
|
|
15
|
-
this.args.push(arg.toLowerCase());
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
isComplete() {
|
|
19
|
-
let isComplete = true;
|
|
20
|
-
for (let [i, arg] of this.config.args.entries()){
|
|
21
|
-
if (this.args[i] !== arg) {
|
|
22
|
-
isComplete = false;
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return isComplete;
|
|
27
|
-
}
|
|
28
|
-
isDone() {
|
|
29
|
-
let isDone = false;
|
|
30
|
-
for (let [i, arg] of this.config.args.entries()){
|
|
31
|
-
if (this.args[i] !== arg) {
|
|
32
|
-
isDone = true;
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return isDone;
|
|
37
|
-
}
|
|
38
|
-
getValue() {
|
|
39
|
-
return this.config.command;
|
|
40
|
-
}
|
|
41
|
-
getArgs() {
|
|
42
|
-
return [
|
|
43
|
-
...this.args
|
|
44
|
-
];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
//# sourceMappingURL=CommandScope.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/CommandScope.ts"],"sourcesContent":["import {type NormalizedCommandConfig} from './NormalizedCommandConfig.js';\nimport {type NormalizedCommandsConfig} from './NormalizedCommandsConfig.js';\n\n/**\n * `CommandScope` handles storing information about parsing of a command.\n */\nexport class CommandScope {\n private readonly args: string[];\n readonly config: NormalizedCommandConfig;\n\n constructor(arg: string, normalizedCommandsConfig: NormalizedCommandsConfig) {\n let normalizedArgument = arg.toLowerCase();\n let commandConfig = normalizedCommandsConfig.find(\n (commandConfig) => commandConfig.args[0] === normalizedArgument,\n );\n\n this.config = commandConfig ?? ([] as unknown as NormalizedCommandConfig);\n this.args = [normalizedArgument];\n }\n\n captureArg(arg: string) {\n this.args.push(arg.toLowerCase());\n\n return this;\n }\n\n isComplete() {\n let isComplete = true;\n\n for (let [i, arg] of this.config.args.entries()) {\n if (this.args[i] !== arg) {\n isComplete = false;\n\n break;\n }\n }\n\n return isComplete;\n }\n\n isDone() {\n let isDone = false;\n\n for (let [i, arg] of this.config.args.entries()) {\n if (this.args[i] !== arg) {\n isDone = true;\n\n break;\n }\n }\n\n return isDone;\n }\n\n getValue() {\n return this.config.command;\n }\n\n getArgs() {\n return [...this.args];\n }\n}\n"],"names":["CommandScope","args","config","constructor","arg","normalizedCommandsConfig","normalizedArgument","toLowerCase","commandConfig","find","captureArg","push","isComplete","i","entries","isDone","getValue","command","getArgs"],"mappings":"AAGA;;CAEC,GACD,OAAO,MAAMA;IACMC,KAAe;IACvBC,OAAgC;IAEzCC,YAAYC,GAAW,EAAEC,wBAAkD,CAAE;QAC3E,IAAIC,qBAAqBF,IAAIG,WAAW;QACxC,IAAIC,gBAAgBH,yBAAyBI,IAAI,CAC/C,CAACD,gBAAkBA,cAAcP,IAAI,CAAC,EAAE,KAAKK;QAG/C,IAAI,CAACJ,MAAM,GAAGM,iBAAkB,EAAE;QAClC,IAAI,CAACP,IAAI,GAAG;YAACK;SAAmB;IAClC;IAEAI,WAAWN,GAAW,EAAE;QACtB,IAAI,CAACH,IAAI,CAACU,IAAI,CAACP,IAAIG,WAAW;QAE9B,OAAO,IAAI;IACb;IAEAK,aAAa;QACX,IAAIA,aAAa;QAEjB,KAAK,IAAI,CAACC,GAAGT,IAAI,IAAI,IAAI,CAACF,MAAM,CAACD,IAAI,CAACa,OAAO,GAAI;YAC/C,IAAI,IAAI,CAACb,IAAI,CAACY,EAAE,KAAKT,KAAK;gBACxBQ,aAAa;gBAEb;YACF;QACF;QAEA,OAAOA;IACT;IAEAG,SAAS;QACP,IAAIA,SAAS;QAEb,KAAK,IAAI,CAACF,GAAGT,IAAI,IAAI,IAAI,CAACF,MAAM,CAACD,IAAI,CAACa,OAAO,GAAI;YAC/C,IAAI,IAAI,CAACb,IAAI,CAACY,EAAE,KAAKT,KAAK;gBACxBW,SAAS;gBAET;YACF;QACF;QAEA,OAAOA;IACT;IAEAC,WAAW;QACT,OAAO,IAAI,CAACd,MAAM,CAACe,OAAO;IAC5B;IAEAC,UAAU;QACR,OAAO;eAAI,IAAI,CAACjB,IAAI;SAAC;IACvB;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/NormalizedCommandConfig.ts"],"sourcesContent":["/** Normalized parser's command configuration. */\nexport type NormalizedCommandConfig = {\n command: string;\n args: string[];\n};\n"],"names":[],"mappings":"AAAA,+CAA+C,GAC/C,WAGE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/NormalizedCommandsConfig.ts"],"sourcesContent":["import {type NormalizedCommandConfig} from './NormalizedCommandConfig.js';\n\n/** Normalized arser's commands configuration. */\nexport type NormalizedCommandsConfig = NormalizedCommandConfig[];\n"],"names":[],"mappings":"AAEA,+CAA+C,GAC/C,WAAiE"}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import camelCase from 'lodash.camelcase';
|
|
2
|
-
import { ParsingError } from '../ParsingError.js';
|
|
3
|
-
import { castValue } from './castValue.js';
|
|
4
|
-
/**
|
|
5
|
-
* `CommandScope` handles storing information about parsing of an option..
|
|
6
|
-
*/ export class OptionScope {
|
|
7
|
-
name;
|
|
8
|
-
values = [];
|
|
9
|
-
previousParsedValue;
|
|
10
|
-
config;
|
|
11
|
-
constructor(optionName, optionsConfig, allowUnknownOptions = false){
|
|
12
|
-
this.name = optionName;
|
|
13
|
-
// Convert option to camel case
|
|
14
|
-
if (this.name.includes('-')) {
|
|
15
|
-
this.name = camelCase(this.name);
|
|
16
|
-
}
|
|
17
|
-
let optionConfig = optionsConfig[this.name];
|
|
18
|
-
if (!optionConfig) {
|
|
19
|
-
if (!allowUnknownOptions) {
|
|
20
|
-
throw new ParsingError('UNKNOWN_OPTION', {
|
|
21
|
-
messageParameters: [
|
|
22
|
-
this.name
|
|
23
|
-
]
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
optionConfig = {
|
|
27
|
-
type: 'string'
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
this.config = optionConfig;
|
|
31
|
-
}
|
|
32
|
-
captureArg(arg) {
|
|
33
|
-
let value = castValue(arg, this.config.type);
|
|
34
|
-
if ((this.config.type === 'number' && !this.config.count || this.config.type === 'string') && typeof this.config.choices !== 'undefined' && !this.config.choices.includes(value)) {
|
|
35
|
-
throw new ParsingError('INVALID_OPTION', {
|
|
36
|
-
messageParameters: [
|
|
37
|
-
value,
|
|
38
|
-
this.name,
|
|
39
|
-
this.config.choices.map((choice)=>`"${choice}"`).join(', ')
|
|
40
|
-
]
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
if (this.config.multiple) {
|
|
44
|
-
this.values.push(value);
|
|
45
|
-
} else {
|
|
46
|
-
this.values = [
|
|
47
|
-
value
|
|
48
|
-
];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
isComplete() {
|
|
52
|
-
if (!this.config.multiple && this.values.length === 1) {
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
if (this.config.multiple && typeof this.config.arity === 'number' && this.values.length + (this.previousParsedValue ?? []).length === this.config.arity) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
getValue() {
|
|
61
|
-
let { config, previousParsedValue } = this;
|
|
62
|
-
let { values } = this;
|
|
63
|
-
if (config.type === 'boolean' && !config.multiple && !values.length) {
|
|
64
|
-
values = [
|
|
65
|
-
true
|
|
66
|
-
];
|
|
67
|
-
} else if (config.type === 'number' && config.count && !values.length) {
|
|
68
|
-
values = [
|
|
69
|
-
1
|
|
70
|
-
];
|
|
71
|
-
}
|
|
72
|
-
if (config.multiple && previousParsedValue) {
|
|
73
|
-
values = [
|
|
74
|
-
...previousParsedValue,
|
|
75
|
-
...values
|
|
76
|
-
];
|
|
77
|
-
}
|
|
78
|
-
if (config.type === 'number' && config.count && previousParsedValue) {
|
|
79
|
-
values = [
|
|
80
|
-
values[0] + previousParsedValue
|
|
81
|
-
];
|
|
82
|
-
}
|
|
83
|
-
return config.multiple ? values : values[0];
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
//# sourceMappingURL=OptionScope.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/OptionScope.ts"],"sourcesContent":["import camelCase from 'lodash.camelcase';\n\nimport {type OptionConfig} from '../OptionConfig.js';\nimport {type OptionsConfig} from '../OptionsConfig.js';\nimport {ParsingError} from '../ParsingError.js';\nimport {castValue} from './castValue.js';\n\n/**\n * `CommandScope` handles storing information about parsing of an option..\n */\nexport class OptionScope {\n name: string;\n\n values: unknown[] = [];\n previousParsedValue?: unknown[] | unknown;\n readonly config: OptionConfig;\n\n constructor(optionName: string, optionsConfig: OptionsConfig, allowUnknownOptions = false) {\n this.name = optionName;\n\n // Convert option to camel case\n if (this.name.includes('-')) {\n this.name = camelCase(this.name);\n }\n\n let optionConfig = optionsConfig[this.name];\n\n if (!optionConfig) {\n if (!allowUnknownOptions) {\n throw new ParsingError('UNKNOWN_OPTION', {messageParameters: [this.name]});\n }\n\n optionConfig = {\n type: 'string',\n };\n }\n\n this.config = optionConfig;\n }\n\n captureArg(arg: string) {\n let value = castValue(arg, this.config.type);\n\n if (\n ((this.config.type === 'number' && !this.config.count) || this.config.type === 'string') &&\n typeof this.config.choices !== 'undefined' &&\n !this.config.choices.includes(value as never)\n ) {\n throw new ParsingError('INVALID_OPTION', {\n messageParameters: [\n value,\n this.name,\n this.config.choices.map((choice) => `\"${choice}\"`).join(', '),\n ],\n });\n }\n\n if (this.config.multiple) {\n this.values.push(value);\n } else {\n this.values = [value];\n }\n }\n\n isComplete() {\n if (!this.config.multiple && this.values.length === 1) {\n return true;\n }\n\n if (\n this.config.multiple &&\n typeof this.config.arity === 'number' &&\n this.values.length + ((this.previousParsedValue as unknown[] | undefined) ?? []).length ===\n this.config.arity\n ) {\n return true;\n }\n\n return false;\n }\n\n getValue() {\n let {config, previousParsedValue} = this;\n let {values} = this;\n\n if (config.type === 'boolean' && !config.multiple && !values.length) {\n values = [true];\n } else if (config.type === 'number' && config.count && !values.length) {\n values = [1];\n }\n\n if (config.multiple && previousParsedValue) {\n values = [...(previousParsedValue as unknown[]), ...values];\n }\n\n if (config.type === 'number' && config.count && previousParsedValue) {\n values = [(values[0] as number) + (previousParsedValue as number)];\n }\n\n return config.multiple ? values : values[0];\n }\n}\n"],"names":["camelCase","ParsingError","castValue","OptionScope","name","values","previousParsedValue","config","constructor","optionName","optionsConfig","allowUnknownOptions","includes","optionConfig","messageParameters","type","captureArg","arg","value","count","choices","map","choice","join","multiple","push","isComplete","length","arity","getValue"],"mappings":"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"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { isFalseString } from './isFalseString.js';
|
|
2
|
-
/**
|
|
3
|
-
* A function that casts string value to a specified type.
|
|
4
|
-
*
|
|
5
|
-
* @param value The value to be converted.
|
|
6
|
-
* @param type The type to convert the value into.
|
|
7
|
-
* */ export function castValue(value, type) {
|
|
8
|
-
switch(type){
|
|
9
|
-
case 'boolean':
|
|
10
|
-
{
|
|
11
|
-
let booleanString = String(value).toLowerCase();
|
|
12
|
-
return !(isFalseString(booleanString) || booleanString === '');
|
|
13
|
-
}
|
|
14
|
-
case 'number':
|
|
15
|
-
{
|
|
16
|
-
return Number.parseFloat(value);
|
|
17
|
-
}
|
|
18
|
-
default:
|
|
19
|
-
{
|
|
20
|
-
return String(value);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=castValue.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/castValue.ts"],"sourcesContent":["import {isFalseString} from './isFalseString.js';\n\n/**\n * A function that casts string value to a specified type.\n *\n * @param value The value to be converted.\n * @param type The type to convert the value into.\n * */\nexport function castValue<T extends 'boolean' | 'number' | 'string'>(\n value: string,\n type?: T,\n): T extends 'boolean' ? boolean : T extends 'number' ? number : string {\n switch (type) {\n case 'boolean': {\n let booleanString = String(value).toLowerCase();\n\n return !(isFalseString(booleanString) || booleanString === '') as T extends 'boolean'\n ? boolean\n : T extends 'number'\n ? number\n : string;\n }\n\n case 'number': {\n return Number.parseFloat(value) as T extends 'boolean'\n ? boolean\n : T extends 'number'\n ? number\n : string;\n }\n\n default: {\n return String(value) as T extends 'boolean' ? boolean : T extends 'number' ? number : string;\n }\n }\n}\n"],"names":["isFalseString","castValue","value","type","booleanString","String","toLowerCase","Number","parseFloat"],"mappings":"AAAA,SAAQA,aAAa,QAAO,qBAAqB;AAEjD;;;;;GAKG,GACH,OAAO,SAASC,UACdC,KAAa,EACbC,IAAQ;IAER,OAAQA;QACN,KAAK;YAAW;gBACd,IAAIC,gBAAgBC,OAAOH,OAAOI,WAAW;gBAE7C,OAAO,CAAEN,CAAAA,cAAcI,kBAAkBA,kBAAkB,EAAC;YAK9D;QAEA,KAAK;YAAU;gBACb,OAAOG,OAAOC,UAAU,CAACN;YAK3B;QAEA;YAAS;gBACP,OAAOG,OAAOH;YAChB;IACF;AACF"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a string representing a command into the arguments, i.e. array of strings.
|
|
3
|
-
*
|
|
4
|
-
* @param value The value to convert.
|
|
5
|
-
* @return Arguments.
|
|
6
|
-
*/ export function commandToArguments(value) {
|
|
7
|
-
let rawArgs = value.split(' ');
|
|
8
|
-
let args = [];
|
|
9
|
-
for (let [, rawValue] of rawArgs.entries()){
|
|
10
|
-
if (typeof rawValue !== 'undefined') {
|
|
11
|
-
if (rawValue === '' && args.at(-1)) {
|
|
12
|
-
args[args.length - 1] += ' ';
|
|
13
|
-
} else {
|
|
14
|
-
args.push(rawValue);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return args;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=commandToArguments.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/commandToArguments.ts"],"sourcesContent":["/**\n * Converts a string representing a command into the arguments, i.e. array of strings.\n *\n * @param value The value to convert.\n * @return Arguments.\n */\nexport function commandToArguments(value: string): string[] {\n let rawArgs = value.split(' ');\n let args: string[] = [];\n\n for (let [, rawValue] of rawArgs.entries()) {\n if (typeof rawValue !== 'undefined') {\n if (rawValue === '' && args.at(-1)) {\n args[args.length - 1] += ' ';\n } else {\n args.push(rawValue);\n }\n }\n }\n\n return args;\n}\n"],"names":["commandToArguments","value","rawArgs","split","args","rawValue","entries","at","length","push"],"mappings":"AAAA;;;;;CAKC,GACD,OAAO,SAASA,mBAAmBC,KAAa;IAC9C,IAAIC,UAAUD,MAAME,KAAK,CAAC;IAC1B,IAAIC,OAAiB,EAAE;IAEvB,KAAK,IAAI,GAAGC,SAAS,IAAIH,QAAQI,OAAO,GAAI;QAC1C,IAAI,OAAOD,aAAa,aAAa;YACnC,IAAIA,aAAa,MAAMD,KAAKG,EAAE,CAAC,CAAC,IAAI;gBAClCH,IAAI,CAACA,KAAKI,MAAM,GAAG,EAAE,IAAI;YAC3B,OAAO;gBACLJ,KAAKK,IAAI,CAACJ;YACZ;QACF;IACF;IAEA,OAAOD;AACT"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts options config to a map (i.e. an object) of short option names (object keys) to long option names (values).
|
|
3
|
-
*
|
|
4
|
-
* @optionsConfig Options config to create the map from.
|
|
5
|
-
* @return Resulting map.
|
|
6
|
-
*/ export function createOptionShortNameMap(optionsConfig) {
|
|
7
|
-
let map = {};
|
|
8
|
-
for (let [optionName, optionConfig] of Object.entries(optionsConfig)){
|
|
9
|
-
if (typeof optionConfig.shortName === 'string') {
|
|
10
|
-
map[optionConfig.shortName] = optionName;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return map;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=createOptionShortNameMap.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/createOptionShortNameMap.ts"],"sourcesContent":["import {type OptionsConfig} from '../OptionsConfig.js';\n\n/**\n * Converts options config to a map (i.e. an object) of short option names (object keys) to long option names (values).\n *\n * @optionsConfig Options config to create the map from.\n * @return Resulting map.\n */\nexport function createOptionShortNameMap(optionsConfig: OptionsConfig) {\n let map: Record<string, string> = {};\n\n for (let [optionName, optionConfig] of Object.entries(optionsConfig)) {\n if (typeof optionConfig.shortName === 'string') {\n map[optionConfig.shortName] = optionName;\n }\n }\n\n return map;\n}\n"],"names":["createOptionShortNameMap","optionsConfig","map","optionName","optionConfig","Object","entries","shortName"],"mappings":"AAEA;;;;;CAKC,GACD,OAAO,SAASA,yBAAyBC,aAA4B;IACnE,IAAIC,MAA8B,CAAC;IAEnC,KAAK,IAAI,CAACC,YAAYC,aAAa,IAAIC,OAAOC,OAAO,CAACL,eAAgB;QACpE,IAAI,OAAOG,aAAaG,SAAS,KAAK,UAAU;YAC9CL,GAAG,CAACE,aAAaG,SAAS,CAAC,GAAGJ;QAChC;IACF;IAEA,OAAOD;AACT"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { isShortOptionsGroup } from './isShortOptionsGroup.js';
|
|
2
|
-
/**
|
|
3
|
-
* Converts short options group in a provided list of arguments into separate short options.
|
|
4
|
-
*
|
|
5
|
-
* @param argv Arguments.
|
|
6
|
-
* @return Arguments that contain no short options group
|
|
7
|
-
*/ export function expandArguments(argv) {
|
|
8
|
-
let expandedArguments = [];
|
|
9
|
-
for (let arg of argv){
|
|
10
|
-
if (isShortOptionsGroup(arg)) {
|
|
11
|
-
expandedArguments.push(...[
|
|
12
|
-
...arg
|
|
13
|
-
].slice(1).map((value)=>`-${value}`));
|
|
14
|
-
} else {
|
|
15
|
-
expandedArguments.push(arg);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return expandedArguments;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=expandArguments.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/expandArguments.ts"],"sourcesContent":["import {type Argv} from '../Argv.js';\nimport {isShortOptionsGroup} from './isShortOptionsGroup.js';\n\n/**\n * Converts short options group in a provided list of arguments into separate short options.\n *\n * @param argv Arguments.\n * @return Arguments that contain no short options group\n */\nexport function expandArguments(argv: Argv): Argv {\n let expandedArguments = [];\n\n for (let arg of argv) {\n if (isShortOptionsGroup(arg)) {\n expandedArguments.push(...[...arg].slice(1).map((value) => `-${value}`));\n } else {\n expandedArguments.push(arg);\n }\n }\n\n return expandedArguments;\n}\n"],"names":["isShortOptionsGroup","expandArguments","argv","expandedArguments","arg","push","slice","map","value"],"mappings":"AACA,SAAQA,mBAAmB,QAAO,2BAA2B;AAE7D;;;;;CAKC,GACD,OAAO,SAASC,gBAAgBC,IAAU;IACxC,IAAIC,oBAAoB,EAAE;IAE1B,KAAK,IAAIC,OAAOF,KAAM;QACpB,IAAIF,oBAAoBI,MAAM;YAC5BD,kBAAkBE,IAAI,IAAI;mBAAID;aAAI,CAACE,KAAK,CAAC,GAAGC,GAAG,CAAC,CAACC,QAAU,CAAC,CAAC,EAAEA,MAAM,CAAC;QACxE,OAAO;YACLL,kBAAkBE,IAAI,CAACD;QACzB;IACF;IAEA,OAAOD;AACT"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const COMMAND_REGEXP = /^(?:[a-z][-a-z0-9]*[a-z])+(?:\s(?:[a-z][-a-z0-9]*[a-z])+)*$/iu;
|
|
2
|
-
/**
|
|
3
|
-
* A function that checks if a value is an argument that looks like command, i.e. space-separated words consisting only of letters, numbers (but not at the start of the word) or dashes.
|
|
4
|
-
*
|
|
5
|
-
* @param value The value to check.
|
|
6
|
-
* @return `true` if `value` is a command.
|
|
7
|
-
*/ export function isCommand(value) {
|
|
8
|
-
return COMMAND_REGEXP.test(value);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=isCommand.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/isCommand.ts"],"sourcesContent":["export const COMMAND_REGEXP = /^(?:[a-z][-a-z0-9]*[a-z])+(?:\\s(?:[a-z][-a-z0-9]*[a-z])+)*$/iu;\n\n/**\n * A function that checks if a value is an argument that looks like command, i.e. space-separated words consisting only of letters, numbers (but not at the start of the word) or dashes.\n *\n * @param value The value to check.\n * @return `true` if `value` is a command.\n */\nexport function isCommand(value: string): boolean {\n return COMMAND_REGEXP.test(value);\n}\n"],"names":["COMMAND_REGEXP","isCommand","value","test"],"mappings":"AAAA,OAAO,MAAMA,iBAAiB,gEAAgE;AAE9F;;;;;CAKC,GACD,OAAO,SAASC,UAAUC,KAAa;IACrC,OAAOF,eAAeG,IAAI,CAACD;AAC7B"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const FALSE_STRING_REGEXP = /^\s*(?:false|0|no|off)\s*$/iu;
|
|
2
|
-
/**
|
|
3
|
-
* A function that checks if a string value is a false string. A false string is `'false'`, `'0'`, `'no'`, or `'off'` (case insensitive).
|
|
4
|
-
*
|
|
5
|
-
* @param value The value to be tested.
|
|
6
|
-
* @return `true` if string is a false string. */ export function isFalseString(value) {
|
|
7
|
-
return FALSE_STRING_REGEXP.test(value);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=isFalseString.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/isFalseString.ts"],"sourcesContent":["const FALSE_STRING_REGEXP = /^\\s*(?:false|0|no|off)\\s*$/iu;\n\n/**\n * A function that checks if a string value is a false string. A false string is `'false'`, `'0'`, `'no'`, or `'off'` (case insensitive).\n *\n * @param value The value to be tested.\n * @return `true` if string is a false string. */\nexport function isFalseString(value: string) {\n return FALSE_STRING_REGEXP.test(value);\n}\n"],"names":["FALSE_STRING_REGEXP","isFalseString","value","test"],"mappings":"AAAA,MAAMA,sBAAsB;AAE5B;;;;+CAI+C,GAC/C,OAAO,SAASC,cAAcC,KAAa;IACzC,OAAOF,oBAAoBG,IAAI,CAACD;AAClC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const LONG_OPTION_REGEXP = /^--[a-z][-a-z0-9]+$/iu;
|
|
2
|
-
/**
|
|
3
|
-
* A function that checks if a value is an argument that looks like a long option, i.e. two dashes and a single word consisting only of letters, numbers (but not at the start of the word) or dashes; e.g. `'--some-option'`.
|
|
4
|
-
*
|
|
5
|
-
* @param value The value to check.
|
|
6
|
-
* @return `true` if `value` is a long option.
|
|
7
|
-
*/ export function isLongOption(arg) {
|
|
8
|
-
return LONG_OPTION_REGEXP.test(arg);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=isLongOption.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/isLongOption.ts"],"sourcesContent":["const LONG_OPTION_REGEXP = /^--[a-z][-a-z0-9]+$/iu;\n\n/**\n * A function that checks if a value is an argument that looks like a long option, i.e. two dashes and a single word consisting only of letters, numbers (but not at the start of the word) or dashes; e.g. `'--some-option'`.\n *\n * @param value The value to check.\n * @return `true` if `value` is a long option.\n */\nexport function isLongOption(arg: string): boolean {\n return LONG_OPTION_REGEXP.test(arg);\n}\n"],"names":["LONG_OPTION_REGEXP","isLongOption","arg","test"],"mappings":"AAAA,MAAMA,qBAAqB;AAE3B;;;;;CAKC,GACD,OAAO,SAASC,aAAaC,GAAW;IACtC,OAAOF,mBAAmBG,IAAI,CAACD;AACjC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const OPTION_LIKE = /^-{1,2}[a-z][-a-z0-9]*=?/iu;
|
|
2
|
-
/**
|
|
3
|
-
* A function that checks if a value is an argument that looks like a long option, short option, or a short options group i.e. one or two dashes and a single word consisting only of letters, numbers (but not at the start of the word) or dashes, optionally followed by `=`.
|
|
4
|
-
*
|
|
5
|
-
* @param value The value to check.
|
|
6
|
-
* @return `true` if `value` is an option.
|
|
7
|
-
*/ export function isOptionLike(value) {
|
|
8
|
-
return OPTION_LIKE.test(value);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=isOptionLike.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/isOptionLike.ts"],"sourcesContent":["const OPTION_LIKE = /^-{1,2}[a-z][-a-z0-9]*=?/iu;\n\n/**\n * A function that checks if a value is an argument that looks like a long option, short option, or a short options group i.e. one or two dashes and a single word consisting only of letters, numbers (but not at the start of the word) or dashes, optionally followed by `=`.\n *\n * @param value The value to check.\n * @return `true` if `value` is an option.\n */\nexport function isOptionLike(value: string): boolean {\n return OPTION_LIKE.test(value);\n}\n"],"names":["OPTION_LIKE","isOptionLike","value","test"],"mappings":"AAAA,MAAMA,cAAc;AAEpB;;;;;CAKC,GACD,OAAO,SAASC,aAAaC,KAAa;IACxC,OAAOF,YAAYG,IAAI,CAACD;AAC1B"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const SHORT_OPTION_REGEXP = /^-[a-z]{1}$/iu;
|
|
2
|
-
/**
|
|
3
|
-
* A function that checks if a value is an argument that looks like a short option, i.e. a dash and a single letter; e.g. `'-x'`.
|
|
4
|
-
*
|
|
5
|
-
* @param value The value to check.
|
|
6
|
-
* @return `true` if `value` is a short option.
|
|
7
|
-
*/ export function isShortOption(arg) {
|
|
8
|
-
return SHORT_OPTION_REGEXP.test(arg);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=isShortOption.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/isShortOption.ts"],"sourcesContent":["const SHORT_OPTION_REGEXP = /^-[a-z]{1}$/iu;\n\n/**\n * A function that checks if a value is an argument that looks like a short option, i.e. a dash and a single letter; e.g. `'-x'`.\n *\n * @param value The value to check.\n * @return `true` if `value` is a short option.\n */\nexport function isShortOption(arg: string): boolean {\n return SHORT_OPTION_REGEXP.test(arg);\n}\n"],"names":["SHORT_OPTION_REGEXP","isShortOption","arg","test"],"mappings":"AAAA,MAAMA,sBAAsB;AAE5B;;;;;CAKC,GACD,OAAO,SAASC,cAAcC,GAAW;IACvC,OAAOF,oBAAoBG,IAAI,CAACD;AAClC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const SHORT_OPTIONS_GROUP_REGEXP = /^-[a-z]{2,}$/iu;
|
|
2
|
-
/**
|
|
3
|
-
* A function that checks if a value is an argument that looks like a short options group, i.e. a dash and a single letter; e.g. `'-x'`.
|
|
4
|
-
*
|
|
5
|
-
* @param value The value to check.
|
|
6
|
-
* @return `true` if `value` is a short option.
|
|
7
|
-
*/ export function isShortOptionsGroup(arg) {
|
|
8
|
-
return SHORT_OPTIONS_GROUP_REGEXP.test(arg);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//# sourceMappingURL=isShortOptionsGroup.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/isShortOptionsGroup.ts"],"sourcesContent":["export const SHORT_OPTIONS_GROUP_REGEXP = /^-[a-z]{2,}$/iu;\n\n/**\n * A function that checks if a value is an argument that looks like a short options group, i.e. a dash and a single letter; e.g. `'-x'`.\n *\n * @param value The value to check.\n * @return `true` if `value` is a short option.\n */\nexport function isShortOptionsGroup(arg: string): boolean {\n return SHORT_OPTIONS_GROUP_REGEXP.test(arg);\n}\n"],"names":["SHORT_OPTIONS_GROUP_REGEXP","isShortOptionsGroup","arg","test"],"mappings":"AAAA,OAAO,MAAMA,6BAA6B,iBAAiB;AAE3D;;;;;CAKC,GACD,OAAO,SAASC,oBAAoBC,GAAW;IAC7C,OAAOF,2BAA2BG,IAAI,CAACD;AACzC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const TRUE_STRING_REGEXP = /^\s*(?:true|1|yes|on)\s*$/iu;
|
|
2
|
-
/**
|
|
3
|
-
* A function that checks if a string value is a true string. A true string is `'true'`, `'1'`, `'yes'`, or `'on'` (case insensitive).
|
|
4
|
-
*
|
|
5
|
-
* @param value The value to be tested.
|
|
6
|
-
* @return `true` if string is a true string. */ export function isTrueString(value) {
|
|
7
|
-
return TRUE_STRING_REGEXP.test(value);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
//# sourceMappingURL=isTrueString.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/internals/isTrueString.ts"],"sourcesContent":["const TRUE_STRING_REGEXP = /^\\s*(?:true|1|yes|on)\\s*$/iu;\n\n/**\n * A function that checks if a string value is a true string. A true string is `'true'`, `'1'`, `'yes'`, or `'on'` (case insensitive).\n *\n * @param value The value to be tested.\n * @return `true` if string is a true string. */\nexport function isTrueString(value: string) {\n return TRUE_STRING_REGEXP.test(value);\n}\n"],"names":["TRUE_STRING_REGEXP","isTrueString","value","test"],"mappings":"AAAA,MAAMA,qBAAqB;AAE3B;;;;8CAI8C,GAC9C,OAAO,SAASC,aAAaC,KAAa;IACxC,OAAOF,mBAAmBG,IAAI,CAACD;AACjC"}
|