@thi.ng/args 2.1.3 → 2.1.6

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2021-11-21T17:09:28Z
3
+ - **Last updated**: 2022-04-07T14:17:30Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [2.1.6](https://github.com/thi-ng/umbrella/tree/@thi.ng/args@2.1.6) (2022-04-07)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - replace deprecated .substr() w/ .substring() ([0710509](https://github.com/thi-ng/umbrella/commit/0710509))
17
+
12
18
  ## [2.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/args@2.1.0) (2021-11-17)
13
19
 
14
20
  #### 🚀 Features
package/README.md CHANGED
@@ -233,4 +233,4 @@ If this project contributes to an academic publication, please cite it as:
233
233
 
234
234
  ## License
235
235
 
236
- © 2018 - 2021 Karsten Schmidt // Apache Software License 2.0
236
+ © 2018 - 2022 Karsten Schmidt // Apache Software License 2.0
package/args.d.ts CHANGED
@@ -4,7 +4,7 @@ import type { ArgSpec, KVDict, KVMultiDict, Tuple } from "./api.js";
4
4
  * Returns a full {@link ArgSpec} for a boolean flag. The mere presence of this
5
5
  * arg will enable the flag.
6
6
  *
7
- * @param spec
7
+ * @param spec -
8
8
  */
9
9
  export declare const flag: <S extends Partial<ArgSpec<boolean>>>(spec: S) => S & {
10
10
  flag: true;
@@ -14,7 +14,7 @@ export declare const flag: <S extends Partial<ArgSpec<boolean>>>(spec: S) => S &
14
14
  /**
15
15
  * Returns a full {@link ArgSpec} for a string value arg.
16
16
  *
17
- * @param spec
17
+ * @param spec -
18
18
  */
19
19
  export declare const string: <S extends Partial<ArgSpec<string>>>(spec: S) => S & {
20
20
  coerce: Fn<string, string>;
@@ -26,7 +26,7 @@ export declare const string: <S extends Partial<ArgSpec<string>>>(spec: S) => S
26
26
  * multi string value arg. This argument can be provided mutiple times with
27
27
  * values collected into an array.
28
28
  *
29
- * @param spec
29
+ * @param spec -
30
30
  */
31
31
  export declare const strings: <S extends Partial<ArgSpec<string[]> & {
32
32
  delim: string;
@@ -40,7 +40,7 @@ export declare const strings: <S extends Partial<ArgSpec<string[]> & {
40
40
  * Returns a full {@link ArgSpec} for a floating point value arg. The value
41
41
  * will be autoatically coerced into a number using {@link coerceFloat}.
42
42
  *
43
- * @param spec
43
+ * @param spec -
44
44
  */
45
45
  export declare const float: <S extends Partial<ArgSpec<number>>>(spec: S) => S & {
46
46
  coerce: Fn<string, number>;
@@ -51,7 +51,7 @@ export declare const float: <S extends Partial<ArgSpec<number>>>(spec: S) => S &
51
51
  * Returns a full {@link ArgSpec} for a single hex integer value arg. The value
52
52
  * will be autoatically coerced into a number using {@link coerceHexInt}.
53
53
  *
54
- * @param spec
54
+ * @param spec -
55
55
  */
56
56
  export declare const hex: <S extends Partial<ArgSpec<number>>>(spec: S) => S & {
57
57
  coerce: Fn<string, number>;
@@ -62,7 +62,7 @@ export declare const hex: <S extends Partial<ArgSpec<number>>>(spec: S) => S & {
62
62
  * Returns a full {@link ArgSpec} for a single integer value arg. The value
63
63
  * will be autoatically coerced into a number using {@link coerceInt}.
64
64
  *
65
- * @param spec
65
+ * @param spec -
66
66
  */
67
67
  export declare const int: <S extends Partial<ArgSpec<number>>>(spec: S) => S & {
68
68
  coerce: Fn<string, number>;
@@ -74,7 +74,7 @@ export declare const int: <S extends Partial<ArgSpec<number>>>(spec: S) => S & {
74
74
  * multi floating point value arg. This argument can be provided mutiple times
75
75
  * with values being coerced into numbers and collected into an array.
76
76
  *
77
- * @param spec
77
+ * @param spec -
78
78
  */
79
79
  export declare const floats: <S extends Partial<ArgSpec<number[]> & {
80
80
  delim: string;
@@ -89,7 +89,7 @@ export declare const floats: <S extends Partial<ArgSpec<number[]> & {
89
89
  * hex integer value arg. This argument can be provided mutiple times with
90
90
  * values being coerced into numbers and collected into an array.
91
91
  *
92
- * @param spec
92
+ * @param spec -
93
93
  */
94
94
  export declare const hexes: <S extends Partial<ArgSpec<number[]> & {
95
95
  delim: string;
@@ -104,7 +104,7 @@ export declare const hexes: <S extends Partial<ArgSpec<number[]> & {
104
104
  * integer value arg. This argument can be provided mutiple times with values
105
105
  * being coerced into numbers and collected into an array.
106
106
  *
107
- * @param spec
107
+ * @param spec -
108
108
  */
109
109
  export declare const ints: <S extends Partial<ArgSpec<number[]> & {
110
110
  delim: string;
@@ -118,7 +118,7 @@ export declare const ints: <S extends Partial<ArgSpec<number[]> & {
118
118
  * Returns full {@link ArgSpec} for a JSON value arg. The raw CLI value string
119
119
  * will be automcatically coerced using {@link coerceJson}.
120
120
  *
121
- * @param spec
121
+ * @param spec -
122
122
  */
123
123
  export declare const json: <T, S extends Partial<ArgSpec<T>>>(spec: S) => S & {
124
124
  coerce: Fn<string, T>;
@@ -129,8 +129,8 @@ export declare const json: <T, S extends Partial<ArgSpec<T>>>(spec: S) => S & {
129
129
  * Returns full {@link ArgSpec} for an enum-like string value arg. The raw CLI
130
130
  * value string will be automcatically validated using {@link coerceOneOf}.
131
131
  *
132
- * @param opts
133
- * @param spec
132
+ * @param opts -
133
+ * @param spec -
134
134
  */
135
135
  export declare const oneOf: <K extends string, S extends Partial<ArgSpec<K>>>(opts: readonly K[], spec: S) => S & {
136
136
  coerce: Fn<string, K>;
@@ -144,8 +144,8 @@ export declare const oneOf: <K extends string, S extends Partial<ArgSpec<K>>>(op
144
144
  * enum-like string value args. The raw CLI value strings will be automcatically
145
145
  * validated using {@link coerceOneOf} and collected into an array.
146
146
  *
147
- * @param opts
148
- * @param spec
147
+ * @param opts -
148
+ * @param spec -
149
149
  */
150
150
  export declare const oneOfMulti: <K extends string, S extends Partial<ArgSpec<K[]> & {
151
151
  delim: string;
@@ -166,8 +166,8 @@ export declare const oneOfMulti: <K extends string, S extends Partial<ArgSpec<K[
166
166
  * are allowed and will receive a `"true"` as their value. However, if `strict`
167
167
  * is true, only full KV pairs are allowed.
168
168
  *
169
- * @param spec
170
- * @param delim
169
+ * @param spec -
170
+ * @param delim -
171
171
  */
172
172
  export declare const kvPairs: <S extends Partial<ArgSpec<KVDict>>>(spec: S, delim?: string, strict?: boolean | undefined) => S & {
173
173
  coerce: Fn<string[], KVDict>;
@@ -180,9 +180,9 @@ export declare const kvPairs: <S extends Partial<ArgSpec<KVDict>>>(spec: S, deli
180
180
  * which supports multiple values per given key (each key's values are collected
181
181
  * into arrays).
182
182
  *
183
- * @param spec
184
- * @param delim
185
- * @param strict
183
+ * @param spec -
184
+ * @param delim -
185
+ * @param strict -
186
186
  */
187
187
  export declare const kvPairsMulti: <S extends Partial<ArgSpec<KVMultiDict>>>(spec: S, delim?: string, strict?: boolean | undefined) => S & {
188
188
  coerce: Fn<string[], KVMultiDict>;
@@ -211,10 +211,10 @@ export declare const kvPairsMulti: <S extends Partial<ArgSpec<KVMultiDict>>>(spe
211
211
  * // }
212
212
  * ```
213
213
  *
214
- * @param coerce
215
- * @param size
216
- * @param spec
217
- * @param delim
214
+ * @param coerce -
215
+ * @param size -
216
+ * @param spec -
217
+ * @param delim -
218
218
  */
219
219
  export declare const tuple: <T, S extends Partial<ArgSpec<Tuple<T>>>>(coerce: Fn<string, T>, size: number, spec: S, delim?: string) => S & {
220
220
  coerce: Fn<string, Tuple<T>>;
@@ -224,9 +224,9 @@ export declare const tuple: <T, S extends Partial<ArgSpec<Tuple<T>>>>(coerce: Fn
224
224
  /**
225
225
  * Syntax sugar for `tuple(coerceInt, size, {...}, delim)`.
226
226
  *
227
- * @param size
228
- * @param spec
229
- * @param delim
227
+ * @param size -
228
+ * @param spec -
229
+ * @param delim -
230
230
  */
231
231
  export declare const size: <S extends Partial<ArgSpec<Tuple<number>>>>(size: number, spec: S, delim?: string) => S & {
232
232
  coerce: Fn<string, Tuple<number>>;
@@ -236,9 +236,9 @@ export declare const size: <S extends Partial<ArgSpec<Tuple<number>>>>(size: num
236
236
  /**
237
237
  * Syntax sugar for `tuple(coerceFloat, size, {...}, delim)`.
238
238
  *
239
- * @param size
240
- * @param spec
241
- * @param delim
239
+ * @param size -
240
+ * @param spec -
241
+ * @param delim -
242
242
  */
243
243
  export declare const vec: <S extends Partial<ArgSpec<Tuple<number>>>>(size: number, spec: S, delim?: string) => S & {
244
244
  coerce: Fn<string, Tuple<number>>;
package/args.js CHANGED
@@ -18,7 +18,7 @@ const $hint = (hint, delim) => hint + (delim ? `[${delim}..]` : "");
18
18
  * Returns a full {@link ArgSpec} for a boolean flag. The mere presence of this
19
19
  * arg will enable the flag.
20
20
  *
21
- * @param spec
21
+ * @param spec -
22
22
  */
23
23
  export const flag = (spec) => ({
24
24
  flag: true,
@@ -29,7 +29,7 @@ export const flag = (spec) => ({
29
29
  /**
30
30
  * Returns a full {@link ArgSpec} for a string value arg.
31
31
  *
32
- * @param spec
32
+ * @param spec -
33
33
  */
34
34
  export const string = $single((x) => x, "STR");
35
35
  /**
@@ -37,28 +37,28 @@ export const string = $single((x) => x, "STR");
37
37
  * multi string value arg. This argument can be provided mutiple times with
38
38
  * values collected into an array.
39
39
  *
40
- * @param spec
40
+ * @param spec -
41
41
  */
42
42
  export const strings = $multi((x) => x, "STR");
43
43
  /**
44
44
  * Returns a full {@link ArgSpec} for a floating point value arg. The value
45
45
  * will be autoatically coerced into a number using {@link coerceFloat}.
46
46
  *
47
- * @param spec
47
+ * @param spec -
48
48
  */
49
49
  export const float = $single(coerceFloat, "NUM");
50
50
  /**
51
51
  * Returns a full {@link ArgSpec} for a single hex integer value arg. The value
52
52
  * will be autoatically coerced into a number using {@link coerceHexInt}.
53
53
  *
54
- * @param spec
54
+ * @param spec -
55
55
  */
56
56
  export const hex = $single(coerceHexInt, "HEX");
57
57
  /**
58
58
  * Returns a full {@link ArgSpec} for a single integer value arg. The value
59
59
  * will be autoatically coerced into a number using {@link coerceInt}.
60
60
  *
61
- * @param spec
61
+ * @param spec -
62
62
  */
63
63
  export const int = $single(coerceInt, "INT");
64
64
  /**
@@ -66,7 +66,7 @@ export const int = $single(coerceInt, "INT");
66
66
  * multi floating point value arg. This argument can be provided mutiple times
67
67
  * with values being coerced into numbers and collected into an array.
68
68
  *
69
- * @param spec
69
+ * @param spec -
70
70
  */
71
71
  export const floats = $multi(coerceFloats, "NUM");
72
72
  /**
@@ -74,7 +74,7 @@ export const floats = $multi(coerceFloats, "NUM");
74
74
  * hex integer value arg. This argument can be provided mutiple times with
75
75
  * values being coerced into numbers and collected into an array.
76
76
  *
77
- * @param spec
77
+ * @param spec -
78
78
  */
79
79
  export const hexes = $multi(coerceHexInts, "HEX");
80
80
  /**
@@ -82,14 +82,14 @@ export const hexes = $multi(coerceHexInts, "HEX");
82
82
  * integer value arg. This argument can be provided mutiple times with values
83
83
  * being coerced into numbers and collected into an array.
84
84
  *
85
- * @param spec
85
+ * @param spec -
86
86
  */
87
87
  export const ints = $multi(coerceInts, "INT");
88
88
  /**
89
89
  * Returns full {@link ArgSpec} for a JSON value arg. The raw CLI value string
90
90
  * will be automcatically coerced using {@link coerceJson}.
91
91
  *
92
- * @param spec
92
+ * @param spec -
93
93
  */
94
94
  export const json = (spec) => ({
95
95
  coerce: coerceJson,
@@ -102,8 +102,8 @@ const $desc = (opts, prefix) => `${prefix ? prefix + ": " : ""}${opts.map((x) =>
102
102
  * Returns full {@link ArgSpec} for an enum-like string value arg. The raw CLI
103
103
  * value string will be automcatically validated using {@link coerceOneOf}.
104
104
  *
105
- * @param opts
106
- * @param spec
105
+ * @param opts -
106
+ * @param spec -
107
107
  */
108
108
  export const oneOf = (opts, spec) => ({
109
109
  coerce: coerceOneOf(opts),
@@ -117,8 +117,8 @@ export const oneOf = (opts, spec) => ({
117
117
  * enum-like string value args. The raw CLI value strings will be automcatically
118
118
  * validated using {@link coerceOneOf} and collected into an array.
119
119
  *
120
- * @param opts
121
- * @param spec
120
+ * @param opts -
121
+ * @param spec -
122
122
  */
123
123
  export const oneOfMulti = (opts, spec) => ({
124
124
  coerce: (xs) => xs.map(coerceOneOf(opts)),
@@ -137,8 +137,8 @@ export const oneOfMulti = (opts, spec) => ({
137
137
  * are allowed and will receive a `"true"` as their value. However, if `strict`
138
138
  * is true, only full KV pairs are allowed.
139
139
  *
140
- * @param spec
141
- * @param delim
140
+ * @param spec -
141
+ * @param delim -
142
142
  */
143
143
  export const kvPairs = (spec, delim = "=", strict) => ({
144
144
  coerce: coerceKV(delim, strict),
@@ -152,9 +152,9 @@ export const kvPairs = (spec, delim = "=", strict) => ({
152
152
  * which supports multiple values per given key (each key's values are collected
153
153
  * into arrays).
154
154
  *
155
- * @param spec
156
- * @param delim
157
- * @param strict
155
+ * @param spec -
156
+ * @param delim -
157
+ * @param strict -
158
158
  */
159
159
  export const kvPairsMulti = (spec, delim = "=", strict) => ({
160
160
  coerce: coerceKV(delim, strict, true),
@@ -184,10 +184,10 @@ export const kvPairsMulti = (spec, delim = "=", strict) => ({
184
184
  * // }
185
185
  * ```
186
186
  *
187
- * @param coerce
188
- * @param size
189
- * @param spec
190
- * @param delim
187
+ * @param coerce -
188
+ * @param size -
189
+ * @param spec -
190
+ * @param delim -
191
191
  */
192
192
  export const tuple = (coerce, size, spec, delim = ",") => ({
193
193
  coerce: coerceTuple(coerce, size, delim),
@@ -198,16 +198,16 @@ export const tuple = (coerce, size, spec, delim = ",") => ({
198
198
  /**
199
199
  * Syntax sugar for `tuple(coerceInt, size, {...}, delim)`.
200
200
  *
201
- * @param size
202
- * @param spec
203
- * @param delim
201
+ * @param size -
202
+ * @param spec -
203
+ * @param delim -
204
204
  */
205
205
  export const size = (size, spec, delim = "x") => tuple(coerceInt, size, spec, delim);
206
206
  /**
207
207
  * Syntax sugar for `tuple(coerceFloat, size, {...}, delim)`.
208
208
  *
209
- * @param size
210
- * @param spec
211
- * @param delim
209
+ * @param size -
210
+ * @param spec -
211
+ * @param delim -
212
212
  */
213
213
  export const vec = (size, spec, delim = ",") => tuple(coerceFloat, size, spec, delim);
package/coerce.js CHANGED
@@ -20,8 +20,8 @@ export function coerceKV(delim = "=", strict = false, multi = false) {
20
20
  idx < 1 &&
21
21
  illegalArgs(`got '${x}', but expected a 'key${delim}value' pair`);
22
22
  if (idx > 0) {
23
- const id = x.substr(0, idx);
24
- const val = x.substr(idx + 1);
23
+ const id = x.substring(0, idx);
24
+ const val = x.substring(idx + 1);
25
25
  if (multi) {
26
26
  acc[id] ? acc[id].push(val) : (acc[id] = [val]);
27
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/args",
3
- "version": "2.1.3",
3
+ "version": "2.1.6",
4
4
  "description": "Declarative, functional & typechecked CLI argument/options parser, value coercions etc.",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,18 +34,18 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.3.2",
38
- "@thi.ng/checks": "^3.1.2",
39
- "@thi.ng/errors": "^2.1.2",
40
- "@thi.ng/strings": "^3.3.0"
37
+ "@thi.ng/api": "^8.3.5",
38
+ "@thi.ng/checks": "^3.1.5",
39
+ "@thi.ng/errors": "^2.1.5",
40
+ "@thi.ng/strings": "^3.3.3"
41
41
  },
42
42
  "devDependencies": {
43
- "@microsoft/api-extractor": "^7.18.19",
44
- "@thi.ng/testament": "^0.2.2",
43
+ "@microsoft/api-extractor": "^7.19.4",
44
+ "@thi.ng/testament": "^0.2.5",
45
45
  "rimraf": "^3.0.2",
46
46
  "tools": "^0.0.1",
47
- "typedoc": "^0.22.9",
48
- "typescript": "^4.5.2"
47
+ "typedoc": "^0.22.13",
48
+ "typescript": "^4.6.2"
49
49
  },
50
50
  "keywords": [
51
51
  "argument",
@@ -75,26 +75,26 @@
75
75
  ],
76
76
  "exports": {
77
77
  ".": {
78
- "import": "./index.js"
78
+ "default": "./index.js"
79
79
  },
80
80
  "./api": {
81
- "import": "./api.js"
81
+ "default": "./api.js"
82
82
  },
83
83
  "./args": {
84
- "import": "./args.js"
84
+ "default": "./args.js"
85
85
  },
86
86
  "./coerce": {
87
- "import": "./coerce.js"
87
+ "default": "./coerce.js"
88
88
  },
89
89
  "./parse": {
90
- "import": "./parse.js"
90
+ "default": "./parse.js"
91
91
  },
92
92
  "./usage": {
93
- "import": "./usage.js"
93
+ "default": "./usage.js"
94
94
  }
95
95
  },
96
96
  "thi.ng": {
97
97
  "year": 2018
98
98
  },
99
- "gitHead": "32cf1a96854f9bb97aca65ffa05ca862ea377059\n"
99
+ "gitHead": "5ee1feb590dd935593b1dd4e7f38a3ed3ba64765\n"
100
100
  }
package/parse.js CHANGED
@@ -57,10 +57,10 @@ const parseKey = (specs, aliases, acc, a) => {
57
57
  // terminator arg, stop parsing
58
58
  if (a === "--")
59
59
  return { state: 1 };
60
- id = camel(a.substr(2));
60
+ id = camel(a.substring(2));
61
61
  }
62
62
  else {
63
- id = aliases[a.substr(1)];
63
+ id = aliases[a.substring(1)];
64
64
  !id && illegalArgs(`unknown option: ${a}`);
65
65
  }
66
66
  const spec = specs[id];