UNPKG

segment-matcher

Version:

Segment Matcher - TypeScript version with dual ESM/CJS format support

115 lines (114 loc) 3.01 kB
/** * 类型匹配器接口 * * 定义了各种特殊类型的匹配规则和转换逻辑。 * 每个类型匹配器负责验证输入格式并进行类型转换。 */ export interface TypeMatcher { /** * 匹配并转换输入值 * * @param text - 输入的文本内容 * @returns 匹配结果,包含是否成功和转换后的值 */ match(text: string): TypeMatchResult; } /** * 类型匹配结果 */ export interface TypeMatchResult { /** 是否匹配成功 */ success: boolean; /** 转换后的值(仅在成功时存在) */ value?: any; } /** * Number类型匹配器 * * 支持整数和小数:123, 123.45, 0, 0.5, -10, -3.14 */ export declare class NumberTypeMatcher implements TypeMatcher { private readonly regex; match(text: string): TypeMatchResult; } /** * Integer类型匹配器 * * 只支持整数:123, 0, -5 */ export declare class IntegerTypeMatcher implements TypeMatcher { private readonly regex; match(text: string): TypeMatchResult; } /** * Float类型匹配器 * * 只支持浮点数(必须包含小数点):123.45, 0.5, -3.14 */ export declare class FloatTypeMatcher implements TypeMatcher { private readonly regex; match(text: string): TypeMatchResult; } /** * Word类型匹配器 * * 匹配非空格字符序列(单词) * 支持:hello, world123, foo_bar, 你好 * 不支持:包含空格的字符串 */ export declare class WordTypeMatcher implements TypeMatcher { private readonly regex; match(text: string): TypeMatchResult; } /** * Boolean类型匹配器 * * 支持true/false字符串:true, false */ export declare class BooleanTypeMatcher implements TypeMatcher { private readonly regex; match(text: string): TypeMatchResult; } /** * Text类型匹配器 * * 直接返回文本内容,总是成功匹配 */ export declare class TextTypeMatcher implements TypeMatcher { match(text: string): TypeMatchResult; } /** * 类型匹配器注册表 * * 管理所有可用的类型匹配器,提供统一的访问接口。 */ export declare class TypeMatcherRegistry { private static readonly matchers; /** * 获取指定类型的匹配器 * * @param dataType - 数据类型名称 * @returns 对应的类型匹配器,如果不存在则返回null */ static getMatcher(dataType: string): TypeMatcher | null; /** * 检查是否支持指定类型的特殊匹配 * * @param dataType - 数据类型名称 * @returns 是否支持特殊匹配 */ static hasSpecialMatcher(dataType: string): boolean; /** * 注册新的类型匹配器 * * @param dataType - 数据类型名称 * @param matcher - 类型匹配器实例 */ static registerMatcher(dataType: string, matcher: TypeMatcher): void; /** * 获取所有支持的数据类型 * * @returns 支持的数据类型列表 */ static getSupportedTypes(): string[]; }