UNPKG

validation-box

Version:

The only validation library - with flexible regex - you need.

60 lines (57 loc) 2.49 kB
import { V as ValidationResult, B as BaseValidationOptions, U as UsernameValidationOptions, a as UserValidationOptions, E as EmailValidationOptions, P as PasswordValidationOptions, A as AgeValidationOptions } from './generics-ZTID1fnX.mjs'; export { f as validateAge, e as validateBirthDate, c as validateEmail, d as validatePassword, b as validateUser, v as validateUsername } from './generics-ZTID1fnX.mjs'; export { validateNIFAO, validatePhoneAO } from './validators/countries/angola.mjs'; export { validateCNPJ, validateCPF, validatePhoneBR } from './validators/countries/brasil.mjs'; export { validatePhoneUS, validateSSN, validateZIPCode } from './validators/countries/usa.mjs'; type ValidatorFunction<T = any, O = {}> = (value: T, options?: O) => ValidationResult; type TransformFunction = (value: any) => any; interface SchemaField { fn: ValidatorFunction; options?: BaseValidationOptions; transform?: TransformFunction[]; } type SchemaRules = Record<string, SchemaField>; declare class vboxSchema<T extends SchemaRules> { private rules; private validateAll; private showErrors; constructor(rules: T, options?: { validateAll?: boolean; showErrors?: boolean; }); private transformValue; validate(data: Record<string, any>): { success: boolean; data?: Record<string, any>; errors?: Record<string, string[]>; }; addRule(field: string, rule: SchemaField): this; extend(schema: vboxSchema<any>): vboxSchema<any>; resolve(data: Record<string, any>, returnAllErrors?: boolean): { values: Record<string, any>; errors: Record<string, any>; }; } declare const validator: { username: (options?: UsernameValidationOptions) => { fn: ValidatorFunction<string>; options: UsernameValidationOptions | undefined; }; user: (options?: UserValidationOptions) => { fn: ValidatorFunction<string>; options: UserValidationOptions | undefined; }; email: (options?: EmailValidationOptions) => { fn: ValidatorFunction<string>; options: EmailValidationOptions | undefined; }; password: (options?: PasswordValidationOptions) => { fn: ValidatorFunction<string>; options: PasswordValidationOptions | undefined; }; age: (options?: AgeValidationOptions) => { fn: ValidatorFunction<number>; options: AgeValidationOptions | undefined; }; }; export { validator, vboxSchema };