UNPKG

auto-form-validator

Version:

A smart, zero-setup form validation library for React with automatic rule detection, i18n support, async validation, and UI integration helpers.

59 lines (54 loc) 1.71 kB
import React from 'react'; type RuleWithMessage<T> = T | { value: T; message?: string; }; type ValidationRule = { required?: boolean | { value: boolean; message?: string; }; minLength?: number | { value: number; message?: string; }; maxLength?: number | { value: number; message?: string; }; pattern?: RegExp | { value: RegExp; message?: string; }; custom?: (value: any) => string | null; async?: (value: any) => Promise<string | null>; }; type ValidationSchema = Record<string, ValidationRule>; type Errors$1 = Record<string, string | null>; type Language = "en" | "hi"; type ValidationMessages = { required: string; minLength: (num: number) => string; maxLength: (num: number) => string; pattern: string; custom?: string; async?: string; }; type Errors = Record<string, string | null>; declare const useAutoValidator: (manualSchema?: Record<string, ValidationRule>, language?: Language) => { register: (name: string) => { name: string; ref: (el: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | null) => void; onBlur: () => Promise<void>; onChange: () => void; }; errors: Errors; validateForm: (values: Record<string, string>) => Promise<boolean>; resetErrors: () => void; }; interface ErrorMessageProps { name: string; errors: Record<string, string | null>; } declare const ErrorMessage: React.FC<ErrorMessageProps>; export { ErrorMessage, type Errors$1 as Errors, type Language, type RuleWithMessage, type ValidationMessages, type ValidationRule, type ValidationSchema, useAutoValidator };