@clerc/parser 1.0.0-beta.15 → 1.0.0-beta.17
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.d.ts +11 -8
- package/dist/index.js +4 -4
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare class MissingRequiredFlagError extends Error {
|
|
|
8
8
|
//#endregion
|
|
9
9
|
//#region src/flag-types.d.ts
|
|
10
10
|
/**
|
|
11
|
-
* Creates a
|
|
11
|
+
* Creates a Enum type function that validates the input against allowed values.
|
|
12
12
|
* The display name will be formatted as "value1 | value2 | ..." for help output.
|
|
13
13
|
*
|
|
14
14
|
* @param values - Array of allowed string values
|
|
@@ -17,11 +17,11 @@ declare class MissingRequiredFlagError extends Error {
|
|
|
17
17
|
*
|
|
18
18
|
* @example
|
|
19
19
|
* ```typescript
|
|
20
|
-
* const format =
|
|
20
|
+
* const format = Enum(['json', 'yaml', 'xml']);
|
|
21
21
|
* // Help output will show: json | yaml | xml
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
declare function
|
|
24
|
+
declare function Enum<T extends string>(...values: T[]): FlagTypeFunction<T>;
|
|
25
25
|
//#endregion
|
|
26
26
|
//#region ../utils/src/types/type-fest.d.ts
|
|
27
27
|
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
@@ -31,21 +31,24 @@ type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
|
31
31
|
type MaybeArray<T> = T | T[];
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/types.d.ts
|
|
34
|
-
|
|
34
|
+
interface FlagDefaultValueFunction<T> {
|
|
35
|
+
(): T;
|
|
35
36
|
display?: string;
|
|
36
|
-
}
|
|
37
|
+
}
|
|
38
|
+
type FlagDefaultValue<T = unknown> = T | FlagDefaultValueFunction<T>;
|
|
37
39
|
/**
|
|
38
40
|
* Defines how a string input is converted to the target type T.
|
|
39
41
|
*
|
|
40
42
|
* @template T The target type.
|
|
41
43
|
*/
|
|
42
|
-
|
|
44
|
+
interface FlagTypeFunction<T = unknown> {
|
|
45
|
+
(value: string): T;
|
|
43
46
|
/**
|
|
44
47
|
* Optional display name for the type, useful in help output.
|
|
45
48
|
* If provided, this will be shown instead of the function name.
|
|
46
49
|
*/
|
|
47
50
|
display?: string;
|
|
48
|
-
}
|
|
51
|
+
}
|
|
49
52
|
/**
|
|
50
53
|
* A callback function to conditionally stop parsing.
|
|
51
54
|
* When it returns true, parsing stops and remaining arguments are preserved in `ignored`.
|
|
@@ -169,4 +172,4 @@ declare function createParser<T extends FlagsDefinition>(options?: ParserOptions
|
|
|
169
172
|
};
|
|
170
173
|
declare const parse: <T extends FlagsDefinition>(args: string[], options?: ParserOptions<T>) => ParsedResult<InferFlags<T>>;
|
|
171
174
|
//#endregion
|
|
172
|
-
export { BaseFlagOptions,
|
|
175
|
+
export { BaseFlagOptions, DOUBLE_DASH, Enum, FlagDefaultValue, FlagDefaultValueFunction, FlagDefinitionValue, FlagOptions, FlagType, FlagTypeFunction, FlagsDefinition, IgnoreFunction, InferFlags, InvalidSchemaError, KNOWN_FLAG, MissingRequiredFlagError, ObjectInputType, PARAMETER, ParsedResult, ParserOptions, RawInputType, UNKNOWN_FLAG, createParser, parse };
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var MissingRequiredFlagError = class extends Error {
|
|
|
15
15
|
//#endregion
|
|
16
16
|
//#region src/flag-types.ts
|
|
17
17
|
/**
|
|
18
|
-
* Creates a
|
|
18
|
+
* Creates a Enum type function that validates the input against allowed values.
|
|
19
19
|
* The display name will be formatted as "value1 | value2 | ..." for help output.
|
|
20
20
|
*
|
|
21
21
|
* @param values - Array of allowed string values
|
|
@@ -24,11 +24,11 @@ var MissingRequiredFlagError = class extends Error {
|
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
26
|
* ```typescript
|
|
27
|
-
* const format =
|
|
27
|
+
* const format = Enum(['json', 'yaml', 'xml']);
|
|
28
28
|
* // Help output will show: json | yaml | xml
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
function
|
|
31
|
+
function Enum(...values) {
|
|
32
32
|
const fn = ((value) => {
|
|
33
33
|
if (!values.includes(value)) throw new Error(`Invalid value: ${value}. Must be one of: ${values.join(", ")}`);
|
|
34
34
|
return value;
|
|
@@ -348,4 +348,4 @@ function createParser(options = {}) {
|
|
|
348
348
|
const parse = (args, options = {}) => createParser(options).parse(args);
|
|
349
349
|
|
|
350
350
|
//#endregion
|
|
351
|
-
export {
|
|
351
|
+
export { DOUBLE_DASH, Enum, InvalidSchemaError, KNOWN_FLAG, MissingRequiredFlagError, PARAMETER, UNKNOWN_FLAG, createParser, parse };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/parser",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.17",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc parser",
|
|
@@ -56,6 +56,6 @@
|
|
|
56
56
|
"nopt": "^9.0.0",
|
|
57
57
|
"type-flag": "^4.0.3",
|
|
58
58
|
"yargs-parser": "^22.0.0",
|
|
59
|
-
"@clerc/utils": "1.0.0-beta.
|
|
59
|
+
"@clerc/utils": "1.0.0-beta.17"
|
|
60
60
|
}
|
|
61
61
|
}
|