UNPKG

@agile-ts/multieditor

Version:

Simple Form Manager for UI-Frameworks

98 lines (97 loc) 2.79 kB
import { Multieditor } from '../multieditor'; import { Item, ItemKey } from '../item'; export declare class Validator<ValueType = any> { config: ValidatorConfigInterface; _key?: ValidatorKey; validationMethods: ValidationMethodContainerInterface<ValueType>[]; /** * Handles the validation of Items. * * @public * @param config - Configuration object */ constructor(config?: ValidatorConfigInterface); /** * Updates the key/name identifier of the Validator. * * @public * @param value - New key/name identifier. */ set key(value: ValidatorKey | undefined); /** * Returns the key/name identifier of the Validator. * * @public */ get key(): ValidatorKey | undefined; /** * Validates the specified value * and updates the Status of the provided Item. * * @public * @param item - Item to apply the computed status to. * @param value - Value to be validated. */ validate(item: Item<ValueType>, value: ValueType): Promise<boolean>; /** * Assigns a new validation method to the Validator. * * @public * @param method - Validation method to be added. * @param config = Configuration object */ addValidationMethod(method: ValidationMethodInterface<ValueType>, config?: AddValidationMethodConfigInterface): this; /** * Appends the specified Validator to this Validator. * * @public * @param validator - Validator to be appended to this Validator. */ append(validator: Validator): this; /** * Returns a fresh reference free copy of this Validator. * * @public */ copy(): Validator<ValueType>; } export declare type ValidatorKey = string | number; export interface ValidatorConfigInterface { /** * Key/Name identifier of the Validator. * @default undefined */ key?: ValidatorKey; } export declare type ValidationMethodInterface<ValueType = any> = ( /** * Key/Name identifier of the Item whose value to be validated. */ toValidateItemKey: ItemKey, /** * Value to be validated. */ value: ValueType, /** * Multieditor the to validate Item belongs to. */ editor: Multieditor) => Promise<boolean> | boolean; export interface ValidationMethodContainerInterface<DataType = any> { /** * Key/Name identifier of the validation method. * @default undefined */ key?: ValidationMethodKey; /** * Validation method */ method: ValidationMethodInterface<DataType>; } export interface AddValidationMethodConfigInterface { /** * Key/Name identifier of the validation method. * @default undefined */ key?: string; } export declare type ValidationMethodKey = string | number;