pretur.validation
Version:
Validation library with good support for i18n
19 lines (18 loc) • 903 B
TypeScript
import { Bundle, Formatter } from 'pretur.i18n';
import { Requester, ValidateResult } from 'pretur.sync';
export declare type ValidationError = undefined | Bundle | Bundle[];
export interface Validator<T> {
(value: T): Promise<ValidationError>;
}
export interface Validation<T> {
server: boolean;
name: string;
validate(requester: Requester, data: T): Promise<ValidateResult>;
}
export interface ServerOptions<T> {
catchEarly?: Validator<T>;
}
export declare function combineValidators<T>(...validators: Validator<T>[]): Validator<T>;
export declare function formatValidationError(formatter: Formatter<any>, error: ValidationError, join?: string): string;
export declare function buildValidation<T>(name: string, server: true, options?: ServerOptions<T>): Validation<T>;
export declare function buildValidation<T>(name: string, server: false, validate: Validator<T>): Validation<T>;