UNPKG

vscroll

Version:
83 lines (82 loc) 3.1 kB
import { IValidationContext } from '../interfaces/validation'; import { IValidator, ValidatedValue, IValidatedData, IValidatedCommonProps, ICommonProps, ICommonProp } from '../interfaces/index'; export declare enum ValidatorType { number = "must be a number", integer = "must be an integer", integerUnlimited = "must be an integer or infinity", moreOrEqual = "must be a number greater than (or equal to) {arg1}", itemList = "must be an array of items {arg1}", boolean = "must be a boolean", object = "must be an object", element = "must be an html element", function = "must be a function", funcOfxArguments = "must have {arg1} argument(s)", funcOfxAndMoreArguments = "must have at least {arg1} argument(s)", funcOfXToYArguments = "must have {arg1} to {arg2} arguments", oneOfCan = "can be present as only one item of {arg1} list", oneOfMust = "must be present as only one item of {arg1} list", or = "must satisfy at least 1 validator from {arg1} list", enum = "must belong to {arg1} list" } type AbstractEnum = Record<string, string | number>; type TEnum = AbstractEnum; export declare const VALIDATORS: { NUMBER: { type: ValidatorType; method: (value: unknown) => ValidatedValue; }; INTEGER: { type: ValidatorType; method: (value: unknown) => ValidatedValue; }; INTEGER_UNLIMITED: { type: ValidatorType; method: (value: unknown) => ValidatedValue; }; MORE_OR_EQUAL: (limit: number, fallback?: boolean) => IValidator; BOOLEAN: { type: ValidatorType; method: (value: unknown) => ValidatedValue; }; OBJECT: { type: ValidatorType; method: (value: unknown) => ValidatedValue; }; ITEM_LIST: { type: ValidatorType; method: (value: unknown) => ValidatedValue; }; ELEMENT: { type: ValidatorType; method: (value: unknown) => ValidatedValue; }; FUNC: { type: ValidatorType; method: (value: unknown) => ValidatedValue; }; FUNC_WITH_X_ARGUMENTS: (count: number) => IValidator; FUNC_WITH_X_AND_MORE_ARGUMENTS: (count: number) => IValidator; FUNC_WITH_X_TO_Y_ARGUMENTS: (from: number, to: number) => IValidator; ONE_OF_CAN: (list: string[]) => IValidator; ONE_OF_MUST: (list: string[]) => IValidator; OR: (list: IValidator[]) => IValidator; ENUM: (list: TEnum) => IValidator; }; export declare class ValidatedData implements IValidatedData { context: IValidationContext; isValidContext: boolean; isValid: boolean; errors: string[]; params: IValidatedCommonProps<PropertyKey>; private contextErrors; constructor(context: unknown); private setContext; private setValidity; setCommonError(error: string): void; setParam(token: string, value: ValidatedValue): void; showErrors(): string; } export declare const runValidator: (current: ValidatedValue, validator: IValidator, context: IValidationContext) => ValidatedValue; export declare const validateOne: (context: IValidationContext, name: string, prop: ICommonProp) => ValidatedValue; export declare const validate: (context: unknown, params: ICommonProps<PropertyKey>) => IValidatedData; export {};