/** * Validation utilities for DuskMoon form elements * * Provides composable validator functions that can be used with * any form element supporting ValidationState and errorMessage props. * * @example * ```ts * import { validate, validators } from '@duskmoon-dev/el-base'; * * const result = validate('hello@example.com', [ * validators.required('Email is required'), * validators.email('Must be a valid email'), * ]); * * // result = { state: 'valid', message: undefined } * * inputEl.validationState = result.state; * inputEl.errorMessage = result.message ?? ''; * ``` */ import type { ValidationState } from './types.js'; /** * Result of a validation check */ export interface ValidationResult { state: NonNullable; message: string | undefined; } /** * A validator function takes a value and returns an error message * if invalid, or undefined/null if valid. */ export type Validator = (value: T) => string | undefined | null; /** * Run a value through a list of validators, returning on the first failure. * Returns { state: 'valid' } if all pass, { state: 'invalid', message } on first failure. */ export declare function validate(value: T, rules: Validator[]): ValidationResult; /** * Run a value through an async validator. * Sets state to 'pending' during execution. */ export declare function validateAsync(value: T, rules: Validator[], asyncRule: (value: T) => Promise): Promise; /** * Built-in validators for common patterns */ export declare const validators: { /** Requires a non-empty value */ readonly required: (message?: string) => Validator; /** Requires a minimum string length */ readonly minLength: (min: number, message?: string) => Validator; /** Requires a maximum string length */ readonly maxLength: (max: number, message?: string) => Validator; /** Requires a value matching a regex pattern */ readonly pattern: (regex: RegExp, message?: string) => Validator; /** Requires a valid email address */ readonly email: (message?: string) => Validator; /** Requires a numeric value within a range */ readonly range: (min: number, max: number, message?: string) => Validator; /** Custom validator from a predicate function */ readonly custom: (predicate: (value: T) => boolean, message: string) => Validator; }; //# sourceMappingURL=validation.d.ts.map