/** * Built-in validation functions for form fields. * * Each factory returns a {@link SyncValidator} that can be passed * to a field's `validators` array in {@link FormConfig}. * * @module bquery/forms */ import type { AsyncValidator, SyncValidator } from './types'; /** * Requires a non-empty value. * * Fails for `undefined`, `null`, empty strings (after trim), and empty arrays. * * @param message - Custom error message (default: `'This field is required'`) * @returns A sync validator function * * @example * ```ts * import { required } from '@bquery/bquery/forms'; * const validate = required('Name is required'); * validate(''); // 'Name is required' * validate('Ada'); // true * ``` */ export declare const required: (message?: string) => SyncValidator; /** * Requires a string to have at least `len` characters. * * Non-string values are coerced via `String()` before checking length. * * @param len - Minimum length * @param message - Custom error message * @returns A sync validator function * * @example * ```ts * import { minLength } from '@bquery/bquery/forms'; * const validate = minLength(3); * validate('ab'); // 'Must be at least 3 characters' * validate('abc'); // true * ``` */ export declare const minLength: (len: number, message?: string) => SyncValidator; /** * Requires a string to have at most `len` characters. * * Non-string values are coerced via `String()` before checking length. * * @param len - Maximum length * @param message - Custom error message * @returns A sync validator function * * @example * ```ts * import { maxLength } from '@bquery/bquery/forms'; * const validate = maxLength(10); * validate('hello world!!'); // 'Must be at most 10 characters' * validate('hello'); // true * ``` */ export declare const maxLength: (len: number, message?: string) => SyncValidator; /** * Requires a string to match a regular expression pattern. * * Non-string values are coerced via `String()` before testing. * * @param regex - Pattern to test against * @param message - Custom error message (default: `'Invalid format'`) * @returns A sync validator function * * @example * ```ts * import { pattern } from '@bquery/bquery/forms'; * const validate = pattern(/^\d+$/, 'Numbers only'); * validate('abc'); // 'Numbers only' * validate('123'); // true * ``` */ export declare const pattern: (regex: RegExp, message?: string) => SyncValidator; /** * RFC 5322–simplified email validation. * * @param message - Custom error message (default: `'Invalid email address'`) * @returns A sync validator function * * @example * ```ts * import { email } from '@bquery/bquery/forms'; * const validate = email(); * validate('nope'); // 'Invalid email address' * validate('ada@lovelace'); // 'Invalid email address' * validate('ada@love.co'); // true * ``` */ export declare const email: (message?: string) => SyncValidator; /** * Requires a string to be a valid URL. * * Uses the native `URL` constructor for validation. * * @param message - Custom error message (default: `'Invalid URL'`) * @returns A sync validator function * * @example * ```ts * import { url } from '@bquery/bquery/forms'; * const validate = url(); * validate('not-a-url'); // 'Invalid URL' * validate('https://example.com'); // true * ``` */ export declare const url: (message?: string) => SyncValidator; /** * Requires a numeric value to be at least `limit`. * * @param limit - Minimum allowed value (inclusive) * @param message - Custom error message * @returns A sync validator function * * @example * ```ts * import { min } from '@bquery/bquery/forms'; * const validate = min(1, 'Must be positive'); * validate(0); // 'Must be positive' * validate(1); // true * ``` */ export declare const min: (limit: number, message?: string) => SyncValidator; /** * Requires a numeric value to be at most `limit`. * * @param limit - Maximum allowed value (inclusive) * @param message - Custom error message * @returns A sync validator function * * @example * ```ts * import { max } from '@bquery/bquery/forms'; * const validate = max(100, 'Too high'); * validate(101); // 'Too high' * validate(100); // true * ``` */ export declare const max: (limit: number, message?: string) => SyncValidator; /** * Creates a custom synchronous validator from any predicate function. * * @param fn - Predicate that returns `true` when the value is valid * @param message - Error message when the predicate returns `false` * @returns A sync validator function * * @example * ```ts * import { custom } from '@bquery/bquery/forms'; * const isEven = custom((v: number) => v % 2 === 0, 'Must be even'); * isEven(3); // 'Must be even' * isEven(4); // true * ``` */ export declare const custom: (fn: (value: T) => boolean, message: string) => SyncValidator; /** * Creates a custom asynchronous validator. * * @param fn - Async predicate that resolves to `true` when valid * @param message - Error message when the predicate resolves to `false` * @returns An async validator function * * @example * ```ts * import { customAsync } from '@bquery/bquery/forms'; * const isUnique = customAsync( * async (name: string) => !(await checkExists(name)), * 'Already taken', * ); * ``` */ export declare const customAsync: (fn: (value: T) => Promise, message: string) => AsyncValidator; /** * Requires a field's value to match the current value of a reference signal. * * Typically used for "confirm password" or "confirm email" patterns where * one field must have the same value as another. * * @param ref - A reactive signal whose current value is the comparison target * @param message - Custom error message (default: `'Fields do not match'`) * @returns A sync validator function * * @example * ```ts * import { signal } from '@bquery/bquery/reactive'; * import { matchField } from '@bquery/bquery/forms'; * * const password = signal('secret'); * const confirmPassword = signal(''); * const validateConfirmPassword = matchField(password, 'Passwords must match'); * * validateConfirmPassword(confirmPassword.value); * ``` */ export declare const matchField: (ref: { readonly value: T; }, message?: string) => SyncValidator; //# sourceMappingURL=validators.d.ts.map