@ents24/be-sure
Version:
NPM module for terse, 'throwy' validation
22 lines (21 loc) • 958 B
TypeScript
/**
* All BeSureValidators accept a single value and return a boolean indicating validation outcome
*/
export type BeSureValidator = (value: any) => boolean;
export type BeSureKey = 'array' | 'array-not-empty' | 'bool' | 'email' | 'id' | 'int' | 'int+' | 'name' | 'defined' | 'object' | 'object-not-empty' | 'page' | 'slug' | 'slug-mixed' | 'string' | 'string-not-empty';
export declare function getValidator(key: BeSureKey): BeSureValidator;
export type CustomValidators = {
[key: string]: BeSureValidator;
};
/**
*
* @param {string} key the key used to refer to the new validator
* @param {BeSureValidator} func the validator function
*/
export declare function setCustomValidators(cvs: CustomValidators): void;
/**
*
* @param {string} key the key to seek in coreValidators and customValidators
* @returns {BeSureValidator} function if a match is found
*/
export declare function getCustomValidator(key: string): BeSureValidator | undefined;