/** * Form Validation System for NA-Kit UI * * Provides a comprehensive, framework-agnostic validation system * with support for sync/async validators, custom rules, and form state. * * @module validators */ export interface ValidationResult { valid: boolean; message?: string; type?: string; } export type ValidatorFn = (value: unknown) => ValidationResult; export type AsyncValidatorFn = (value: unknown) => Promise; export interface FieldState { value: unknown; valid: boolean; invalid: boolean; errors: ValidationResult[]; touched: boolean; dirty: boolean; pristine: boolean; pending: boolean; } export interface FormState { valid: boolean; invalid: boolean; touched: boolean; dirty: boolean; pristine: boolean; pending: boolean; fields: Record; errors: Record; values: Record; } export interface ValidatorOptions { message?: string; } /** * Validates that a field is not empty */ export declare function required(options?: ValidatorOptions): ValidatorFn; /** * Validates email format (RFC 5322 simplified) */ export declare function email(options?: ValidatorOptions): ValidatorFn; /** * Validates phone number format (international) */ export declare function phone(options?: ValidatorOptions): ValidatorFn; /** * Validates URL format */ export declare function url(options?: ValidatorOptions): ValidatorFn; /** * Validates minimum string length */ export declare function minLength(min: number, options?: ValidatorOptions): ValidatorFn; /** * Validates maximum string length */ export declare function maxLength(max: number, options?: ValidatorOptions): ValidatorFn; /** * Validates minimum numeric value */ export declare function min(minVal: number, options?: ValidatorOptions): ValidatorFn; /** * Validates maximum numeric value */ export declare function max(maxVal: number, options?: ValidatorOptions): ValidatorFn; /** * Validates value against a regex pattern */ export declare function pattern(regex: RegExp, options?: ValidatorOptions): ValidatorFn; /** * Validates that value matches another field's value (e.g. confirm password) */ export declare function matches(fieldName: string, getValue: () => unknown, options?: ValidatorOptions): ValidatorFn; /** * Compose multiple validators into a single validator */ export declare function compose(...validators: ValidatorFn[]): ValidatorFn; /** * Compose multiple async validators */ export declare function composeAsync(...validators: AsyncValidatorFn[]): AsyncValidatorFn; /** * Create a custom validator */ export declare function custom(validatorFn: (value: unknown) => boolean, options?: ValidatorOptions): ValidatorFn; /** * Create an async custom validator (e.g. server-side uniqueness check) */ export declare function customAsync(validatorFn: (value: unknown) => Promise, options?: ValidatorOptions): AsyncValidatorFn; /** * Validates that a value is numeric */ export declare function numeric(options?: ValidatorOptions): ValidatorFn; /** * Validates that a value is an integer */ export declare function integer(options?: ValidatorOptions): ValidatorFn; /** * Validates that a date is after a minimum date */ export declare function minDate(min: Date, options?: ValidatorOptions): ValidatorFn; /** * Validates that a date is before a maximum date */ export declare function maxDate(max: Date, options?: ValidatorOptions): ValidatorFn; /** * Validates file size */ export declare function maxFileSize(maxBytes: number, options?: ValidatorOptions): ValidatorFn; /** * Validates file type */ export declare function fileType(allowedTypes: string[], options?: ValidatorOptions): ValidatorFn; /** * Manages validation state for a single form field */ export declare class FieldController { private _value; private _touched; private _dirty; private _pending; private _errors; private _validators; private _asyncValidators; private _debounceTimer; private _listeners; constructor(initialValue?: unknown, validators?: ValidatorFn[], asyncValidators?: AsyncValidatorFn[]); get state(): FieldState; get value(): unknown; set value(val: unknown); touch(): void; reset(value?: unknown): void; validate(): ValidationResult[]; subscribe(listener: (state: FieldState) => void): () => void; private _notify; } /** * Manages validation state for an entire form */ export declare class FormController { private _fields; private _listeners; private _fieldUnsubscribers; /** * Register a field with validators */ addField(name: string, initialValue?: unknown, validators?: ValidatorFn[], asyncValidators?: AsyncValidatorFn[]): FieldController; /** * Remove a field */ removeField(name: string): void; /** * Get a field controller */ getField(name: string): FieldController | undefined; /** * Set a field's value */ setValue(name: string, value: unknown): void; /** * Get all form values */ get values(): Record; /** * Get full form state */ get state(): FormState; /** * Validate all fields */ validateAll(): boolean; /** * Reset all fields */ reset(values?: Record): void; /** * Subscribe to form state changes */ subscribe(listener: (state: FormState) => void): () => void; /** * Destroy the form controller, cleaning up all subscriptions */ destroy(): void; private _notify; } //# sourceMappingURL=validators.d.ts.map