@clerc/core 1.0.0-beta.19 → 1.0.0-beta.20
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 -11
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ type FlagDefaultValue<T = unknown> = T | FlagDefaultValueFunction<T>;
|
|
|
43
43
|
*
|
|
44
44
|
* @template T The target type.
|
|
45
45
|
*/
|
|
46
|
-
interface
|
|
46
|
+
interface TypeFunction<T = unknown> {
|
|
47
47
|
(value: string): T;
|
|
48
48
|
/**
|
|
49
49
|
* Optional display name for the type, useful in help output.
|
|
@@ -60,7 +60,7 @@ interface FlagTypeFunction<T = unknown> {
|
|
|
60
60
|
* @returns true to stop parsing, false to continue
|
|
61
61
|
*/
|
|
62
62
|
type IgnoreFunction = (type: typeof KNOWN_FLAG | typeof UNKNOWN_FLAG | typeof PARAMETER, arg: string) => boolean;
|
|
63
|
-
type FlagType<T = unknown> =
|
|
63
|
+
type FlagType<T = unknown> = TypeFunction<T> | readonly [TypeFunction<T>];
|
|
64
64
|
interface BaseFlagOptions<T extends FlagType = FlagType> {
|
|
65
65
|
/**
|
|
66
66
|
* The type constructor or a function to convert the string value.
|
|
@@ -167,7 +167,7 @@ type InferFlags<T extends FlagsDefinition> = Prettify<_InferFlags<T>>;
|
|
|
167
167
|
* The display name will be formatted as "value1 | value2 | ..." for help output.
|
|
168
168
|
*
|
|
169
169
|
* @param values - Array of allowed string values
|
|
170
|
-
* @returns A
|
|
170
|
+
* @returns A TypeFunction that validates and returns the input value
|
|
171
171
|
* @throws {Error} If the value is not in the allowed values list
|
|
172
172
|
*
|
|
173
173
|
* @example
|
|
@@ -176,25 +176,25 @@ type InferFlags<T extends FlagsDefinition> = Prettify<_InferFlags<T>>;
|
|
|
176
176
|
* // Help output will show: json | yaml | xml
|
|
177
177
|
* ```
|
|
178
178
|
*/
|
|
179
|
-
declare function Enum<T extends string>(...values: T[]):
|
|
179
|
+
declare function Enum<T extends string>(...values: T[]): TypeFunction<T>;
|
|
180
180
|
/**
|
|
181
181
|
* Creates a range type function that validates the input is a number within the specified range.
|
|
182
182
|
*
|
|
183
183
|
* @param min - The minimum acceptable value (inclusive)
|
|
184
184
|
* @param max - The maximum acceptable value (inclusive)
|
|
185
|
-
* @returns A
|
|
185
|
+
* @returns A TypeFunction that validates the input value
|
|
186
186
|
* @throws {Error} If the value is not a number or is outside the specified range
|
|
187
187
|
*/
|
|
188
|
-
declare function Range(min: number, max: number):
|
|
188
|
+
declare function Range(min: number, max: number): TypeFunction<number>;
|
|
189
189
|
/**
|
|
190
190
|
* Creates a regex type function that validates the input against the provided pattern.
|
|
191
191
|
*
|
|
192
192
|
* @param pattern - The regular expression pattern to validate against
|
|
193
193
|
* @param description - Optional description for display purposes
|
|
194
|
-
* @returns A
|
|
194
|
+
* @returns A TypeFunction that validates the input value
|
|
195
195
|
* @throws {Error} If the value does not match the regex pattern
|
|
196
196
|
*/
|
|
197
|
-
declare function Regex(pattern: RegExp, description?: string):
|
|
197
|
+
declare function Regex(pattern: RegExp, description?: string): TypeFunction<string>;
|
|
198
198
|
//#endregion
|
|
199
199
|
//#region ../parser/src/parse.d.ts
|
|
200
200
|
declare const DOUBLE_DASH = "--";
|
|
@@ -204,7 +204,7 @@ declare function createParser<T extends FlagsDefinition>(options?: ParserOptions
|
|
|
204
204
|
};
|
|
205
205
|
declare const parse: <T extends FlagsDefinition>(args: string[], options?: ParserOptions<T>) => ParsedResult<InferFlags<T>>;
|
|
206
206
|
declare namespace index_d_exports {
|
|
207
|
-
export { BaseFlagOptions, DOUBLE_DASH, Enum, FlagDefaultValue, FlagDefaultValueFunction, FlagDefinitionValue, FlagOptions, FlagType,
|
|
207
|
+
export { BaseFlagOptions, DOUBLE_DASH, Enum, FlagDefaultValue, FlagDefaultValueFunction, FlagDefinitionValue, FlagOptions, FlagType, FlagsDefinition, IgnoreFunction, InferFlags, InvalidSchemaError, KNOWN_FLAG, MissingRequiredFlagError, ObjectInputType, PARAMETER, ParsedResult, ParserOptions, Range, RawInputType, Regex, TypeFunction, UNKNOWN_FLAG, createParser, parse };
|
|
208
208
|
}
|
|
209
209
|
//#endregion
|
|
210
210
|
//#region src/types/clerc.d.ts
|
|
@@ -220,12 +220,12 @@ type ClercFlagsDefinition = Record<string, ClercFlagDefinitionValue>;
|
|
|
220
220
|
//#endregion
|
|
221
221
|
//#region src/types/parameters.d.ts
|
|
222
222
|
type InferStringParameter<T extends string, Type$1 = string> = T extends `<${infer Name extends string}...>` | `[${infer Name extends string}...]` ? Record<CamelCase<Name>, Type$1[]> : T extends `<${infer Name extends string}>` ? Record<CamelCase<Name>, Type$1> : T extends `[${infer Name extends string}]` ? Record<CamelCase<Name>, Type$1 | undefined> : never;
|
|
223
|
-
type InferParameter<T extends Parameter> = T extends string ? InferStringParameter<T> : T extends ParameterDefinition ? T["type"] extends
|
|
223
|
+
type InferParameter<T extends Parameter> = T extends string ? InferStringParameter<T> : T extends ParameterDefinition ? T["type"] extends TypeFunction<infer U> ? InferStringParameter<T["key"], U> : InferStringParameter<T["key"]> : never;
|
|
224
224
|
type InferParameters<T extends readonly Parameter[]> = T extends readonly (infer U extends Parameter)[] ? Prettify<UnionToIntersection<InferParameter<U>>> : never;
|
|
225
225
|
interface ParameterDefinition {
|
|
226
226
|
key: string;
|
|
227
227
|
description?: string;
|
|
228
|
-
type?:
|
|
228
|
+
type?: TypeFunction;
|
|
229
229
|
}
|
|
230
230
|
type Parameter = string | ParameterDefinition;
|
|
231
231
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.20",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc core",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"lite-emit": "^4.0.0",
|
|
48
|
-
"@clerc/parser": "^1.0.0-beta.
|
|
48
|
+
"@clerc/parser": "^1.0.0-beta.20"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"is-platform": "^1.0.0",
|
|
52
|
-
"@clerc/utils": "1.0.0-beta.
|
|
52
|
+
"@clerc/utils": "1.0.0-beta.20"
|
|
53
53
|
}
|
|
54
54
|
}
|