UNPKG

@mmstack/form-validation

Version:

This is an internal library for providing localized validators :)

23 lines (22 loc) 1.36 kB
import { Validator } from '../validator.type'; import { createMustBeEmptyValidator, createMustBeValidator } from './must-be'; import { createNotValidator } from './not'; import { createNotOneOfValidator } from './not-one-of'; import { createOneOfValidator } from './one-of'; import { createRequiredValidator } from './required'; export type GeneralMessageFactories = { required: Parameters<typeof createRequiredValidator>[0]; mustBe: Parameters<typeof createMustBeValidator>[0]; mustBeNull: Parameters<typeof createMustBeEmptyValidator>[0]; not: Parameters<typeof createNotValidator>[0]; oneOf: Parameters<typeof createOneOfValidator>[0]; notOneOf: Parameters<typeof createNotOneOfValidator>[0]; }; export declare function createGeneralValidators(factories?: Partial<GeneralMessageFactories>): { required: <T>(label?: string) => Validator<T>; mustBe: <T>(value: T, valueLabel?: string, matcher?: (a: T, b: T) => boolean) => Validator<T>; mustBeNull: <T>() => Validator<T>; not: <T>(value: T, valueLabel?: string, matcher?: (a: T, b: T) => boolean) => Validator<T>; oneOf: <T>(values: T[], toLabel?: (value: T) => string, identity?: (a: T) => string, delimiter?: string) => Validator<T>; notOneOf: <T>(values: T[], toLabel?: (value: T) => string, identity?: (a: T) => string, delimiter?: string) => Validator<T>; };