UNPKG

think_validtion

Version:
117 lines (116 loc) 2.97 kB
/** * @ author: richen * @ copyright: Copyright (c) - <richenlin(at)gmail.com> * @ license: MIT * @ version: 2020-03-20 11:34:38 */ import "reflect-metadata"; export declare const PARAM_TYPE_KEY = "PARAM_TYPE_KEY"; export declare const PARAM_RULE_KEY = "PARAM_RULE_KEY"; export declare const PARAM_CHECK_KEY = "PARAM_CHECK_KEY"; export declare const ENABLE_VALIDATED = "ENABLE_VALIDATED"; export declare const paramterTypes: any; /** * get metadata value of a metadata key on the prototype chain of an object and property * @param metadataKey metadata's key * @param target the target of metadataKey */ export declare function recursiveGetMetadata(metadataKey: any, target: any, propertyKey?: string | symbol): any[]; /** * Dynamically add methods for target class types * * @param {Function} clazz * @param {string} protoName * @param {Function} func */ export declare function defineNewProperty(clazz: Function, protoName: string, func: Function): void; /** * * * @param {(string | symbol)} metadataKey * @param {*} target * @param {(string | symbol)} [propertyKey] * @returns */ export declare function getOriginMetadata(metadataKey: string | symbol, target: any, propertyKey?: string | symbol): any; /** * Convert paramer's type to defined. * * @param {*} param * @param {string} type * @returns */ export declare const convertParamsType: (param: any, type: string) => any; /** * Check the base types. * * @param {*} value * @param {string} type * @returns {*} */ export declare const checkParamsType: (value: any, type: string) => any; /** * * * @export * @param {*} clazz * @param {*} data * @param {boolean} [convert=false] * @returns */ export declare function plainToClass(clazz: any, data: any, convert?: boolean): any; /** * Checks if value is a chinese name. * * @param {string} value * @returns {boolean} */ export declare function cnname(value: string): boolean; /** * Checks if value is a idcard number. * * @param {string} value * @returns */ export declare function idnumber(value: string): boolean; /** * Checks if value is a mobile phone number. * * @param {string} value * @returns {boolean} */ export declare function mobile(value: string): boolean; /** * Checks if value is a zipcode. * * @param {string} value * @returns {boolean} */ export declare function zipcode(value: string): boolean; /** * Checks if value is a platenumber. * * @param {string} value * @returns {boolean} */ export declare function platenumber(value: string): boolean; interface ParamOptions { index: number; isDto: boolean; type: string; validRules: any[]; dtoCheck: boolean; } /** * Check parameters against predefined rules * * @export * @param {*} param * @param {number} index * @param {ParamOptions} [paramOptions={ * validRules: [], * dtoCheck: false * }] */ export declare function checkParams(value: any, paramOptions: ParamOptions): Promise<any>; export {};