Skip to content

Commit 4568eba

Browse files
committed
fix(parser): rename FlagTypeFunction to TypeFunction
1 parent 661705a commit 4568eba

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

packages/core/src/types/parameters.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { FlagTypeFunction } from "@clerc/parser";
1+
import type { TypeFunction } from "@clerc/parser";
22
import type { CamelCase, Prettify, UnionToIntersection } from "@clerc/utils";
33

44
type InferStringParameter<T extends string, Type = string> = T extends
@@ -14,7 +14,7 @@ type InferStringParameter<T extends string, Type = string> = T extends
1414
type InferParameter<T extends Parameter> = T extends string
1515
? InferStringParameter<T>
1616
: T extends ParameterDefinition
17-
? T["type"] extends FlagTypeFunction<infer U>
17+
? T["type"] extends TypeFunction<infer U>
1818
? InferStringParameter<T["key"], U>
1919
: InferStringParameter<T["key"]>
2020
: never;
@@ -28,6 +28,6 @@ export type InferParameters<T extends readonly Parameter[]> =
2828
export interface ParameterDefinition {
2929
key: string;
3030
description?: string;
31-
type?: FlagTypeFunction;
31+
type?: TypeFunction;
3232
}
3333
export type Parameter = string | ParameterDefinition;

packages/parser/src/flag-types.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { FlagTypeFunction } from "./types";
1+
import type { TypeFunction } from "./types";
22

33
/**
44
* Creates a Enum type function that validates the input against allowed values.
55
* The display name will be formatted as "value1 | value2 | ..." for help output.
66
*
77
* @param values - Array of allowed string values
8-
* @returns A FlagTypeFunction that validates and returns the input value
8+
* @returns A TypeFunction that validates and returns the input value
99
* @throws {Error} If the value is not in the allowed values list
1010
*
1111
* @example
@@ -14,7 +14,7 @@ import type { FlagTypeFunction } from "./types";
1414
* // Help output will show: json | yaml | xml
1515
* ```
1616
*/
17-
export function Enum<T extends string>(...values: T[]): FlagTypeFunction<T> {
17+
export function Enum<T extends string>(...values: T[]): TypeFunction<T> {
1818
const fn = ((value: string) => {
1919
if (!values.includes(value as any)) {
2020
throw new Error(
@@ -23,7 +23,7 @@ export function Enum<T extends string>(...values: T[]): FlagTypeFunction<T> {
2323
}
2424

2525
return value;
26-
}) as FlagTypeFunction<T>;
26+
}) as TypeFunction<T>;
2727

2828
fn.display = values.join(" | ");
2929

@@ -35,10 +35,10 @@ export function Enum<T extends string>(...values: T[]): FlagTypeFunction<T> {
3535
*
3636
* @param min - The minimum acceptable value (inclusive)
3737
* @param max - The maximum acceptable value (inclusive)
38-
* @returns A FlagTypeFunction that validates the input value
38+
* @returns A TypeFunction that validates the input value
3939
* @throws {Error} If the value is not a number or is outside the specified range
4040
*/
41-
export function Range(min: number, max: number): FlagTypeFunction<number> {
41+
export function Range(min: number, max: number): TypeFunction<number> {
4242
const fn = ((value: string) => {
4343
const num = Number(value);
4444
if (Number.isNaN(num) || num < min || num > max) {
@@ -48,7 +48,7 @@ export function Range(min: number, max: number): FlagTypeFunction<number> {
4848
}
4949

5050
return num;
51-
}) as FlagTypeFunction<number>;
51+
}) as TypeFunction<number>;
5252
fn.display = `${min}-${max}`;
5353

5454
return fn;
@@ -59,13 +59,13 @@ export function Range(min: number, max: number): FlagTypeFunction<number> {
5959
*
6060
* @param pattern - The regular expression pattern to validate against
6161
* @param description - Optional description for display purposes
62-
* @returns A FlagTypeFunction that validates the input value
62+
* @returns A TypeFunction that validates the input value
6363
* @throws {Error} If the value does not match the regex pattern
6464
*/
6565
export function Regex(
6666
pattern: RegExp,
6767
description?: string,
68-
): FlagTypeFunction<string> {
68+
): TypeFunction<string> {
6969
const fn = ((value: string) => {
7070
if (!pattern.test(value)) {
7171
throw new Error(
@@ -74,7 +74,7 @@ export function Regex(
7474
}
7575

7676
return value;
77-
}) as FlagTypeFunction<string>;
77+
}) as TypeFunction<string>;
7878
fn.display = description ?? pattern.toString();
7979

8080
return fn;

packages/parser/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type FlagDefaultValue<T = unknown> = T | FlagDefaultValueFunction<T>;
1414
*
1515
* @template T The target type.
1616
*/
17-
export interface FlagTypeFunction<T = unknown> {
17+
export interface TypeFunction<T = unknown> {
1818
(value: string): T;
1919
/**
2020
* Optional display name for the type, useful in help output.
@@ -37,8 +37,8 @@ export type IgnoreFunction = (
3737
) => boolean;
3838

3939
export type FlagType<T = unknown> =
40-
| FlagTypeFunction<T>
41-
| readonly [FlagTypeFunction<T>];
40+
| TypeFunction<T>
41+
| readonly [TypeFunction<T>];
4242

4343
export interface BaseFlagOptions<T extends FlagType = FlagType> {
4444
/**

0 commit comments

Comments
 (0)