@jakubmazanec/args 2.0.15-unstable.1cfd6265 → 2.0.16-next.245f32ee
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
2
|
+
import _ from "lodash";
|
|
3
3
|
import { ParsingError } from "../ParsingError.js";
|
|
4
4
|
import { castValue } from "./castValue.js";
|
|
5
5
|
export class OptionScope {
|
|
@@ -10,7 +10,7 @@ export class OptionScope {
|
|
|
10
10
|
constructor(optionName, optionsConfig, allowUnknownOptions = false) {
|
|
11
11
|
this.name = optionName;
|
|
12
12
|
if (this.name.includes("-")) {
|
|
13
|
-
this.name = camelCase(this.name);
|
|
13
|
+
this.name = _.camelCase(this.name);
|
|
14
14
|
}
|
|
15
15
|
let optionConfig = optionsConfig[this.name];
|
|
16
16
|
if (!optionConfig) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../source/internals/OptionScope.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": ";AAAA,OAAO,
|
|
4
|
+
"sourcesContent": ["import _ from 'lodash';\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 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"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,OAAO;AAId,SAAQ,oBAAmB;AAC3B,SAAQ,iBAAgB;AAKjB,aAAM,YAAY;AAAA,EACvB;AAAA,EAEA,SAAoB,CAAC;AAAA,EACrB;AAAA,EACS;AAAA,EAET,YAAY,YAAoB,eAA8B,sBAAsB,OAAO;AACzF,SAAK,OAAO;AAGZ,QAAI,KAAK,KAAK,SAAS,GAAG,GAAG;AAC3B,WAAK,OAAO,EAAE,UAAU,KAAK,IAAI;AAAA,IACnC;AAEA,QAAI,eAAe,cAAc,KAAK,IAAI;AAE1C,QAAI,CAAC,cAAc;AACjB,UAAI,CAAC,qBAAqB;AACxB,cAAM,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O,QAAQ;AACrE,eAAS,CAAC,CAAC;AAAA,IACb;AAEA,QAAI,OAAO,YAAY,qBAAqB;AAC1C,eAAS,CAAC,GAAI,qBAAmC,GAAG,MAAM;AAAA,IAC5D;AAEA,QAAI,OAAO,SAAS,YAAY,OAAO,SAAS,qBAAqB;AACnE,eAAS,CAAE,OAAO,CAAC,IAAgB,mBAA8B;AAAA,IACnE;AAEA,WAAO,OAAO,WAAW,SAAS,OAAO,CAAC;AAAA,EAC5C;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakubmazanec/args",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16-next.245f32ee",
|
|
4
4
|
"description": "TypeScript-first library for parsing command line arguments.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,21 +27,19 @@
|
|
|
27
27
|
"typecheck": "tsc --project tsconfig.typecheck.json"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@jakubmazanec/error": "3.0.
|
|
31
|
-
"@jakubmazanec/ts-utils": "3.0.
|
|
32
|
-
"lodash
|
|
30
|
+
"@jakubmazanec/error": "^3.0.0",
|
|
31
|
+
"@jakubmazanec/ts-utils": "^3.0.0",
|
|
32
|
+
"lodash": "^4.17.21"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@jakubmazanec/eslint-config": "4.1.
|
|
35
|
+
"@jakubmazanec/eslint-config": "^4.1.0",
|
|
36
36
|
"@types/lodash": "^4.17.21",
|
|
37
|
-
"@types/lodash.camelcase": "^4.3.9",
|
|
38
37
|
"@types/node": "^24.0.4",
|
|
39
38
|
"@vitest/coverage-v8": "^3.2.4",
|
|
40
39
|
"concurrently": "^9.2.1",
|
|
41
40
|
"del-cli": "^6.0.0",
|
|
42
41
|
"esbuild": "^0.27.0",
|
|
43
42
|
"eslint": "^9.33.0",
|
|
44
|
-
"lodash": "^4.17.21",
|
|
45
43
|
"prettier": "^3.6.2",
|
|
46
44
|
"prettier-plugin-packagejson": "^2.5.19",
|
|
47
45
|
"typedoc": "^0.28.14",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _ from 'lodash';
|
|
2
2
|
|
|
3
3
|
import {type OptionConfig} from '../OptionConfig.js';
|
|
4
4
|
import {type OptionsConfig} from '../OptionsConfig.js';
|
|
@@ -20,7 +20,7 @@ export class OptionScope {
|
|
|
20
20
|
|
|
21
21
|
// Convert option to camel case
|
|
22
22
|
if (this.name.includes('-')) {
|
|
23
|
-
this.name = camelCase(this.name);
|
|
23
|
+
this.name = _.camelCase(this.name);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
let optionConfig = optionsConfig[this.name];
|