think_validtion
Version:
Validtion Util for Koatty and ThinkORM.
302 lines (301 loc) • 10 kB
TypeScript
import { ValidationOptions, IsIpVersion } from "class-validator";
interface IsEmailOptions {
allow_display_name?: boolean;
require_display_name?: boolean;
allow_utf8_local_part?: boolean;
require_tld?: boolean;
}
interface IsURLOptions {
protocols?: string[];
require_tld?: boolean;
require_protocol?: boolean;
require_host?: boolean;
require_valid_protocol?: boolean;
allow_underscores?: boolean;
host_whitelist?: (string | RegExp)[];
host_blacklist?: (string | RegExp)[];
allow_trailing_dot?: boolean;
allow_protocol_relative_urls?: boolean;
disallow_auth?: boolean;
}
declare class ValidateClass {
private static instance;
private constructor();
/**
*
*
* @static
* @returns
* @memberof ValidateUtil
*/
static getInstance(): ValidateClass;
/**
* validated data vs dto class
*
* @param {*} Clazz
* @param {*} data
* @param {boolean} [convert=false] auto convert paramers type
* @returns {Promise<any>}
* @memberof ValidateClass
*/
valid(Clazz: any, data: any, convert?: boolean): Promise<any>;
}
/**
* ClassValidator for manual
*/
export declare const ClassValidator: ValidateClass;
interface IsEmailOptions {
allow_display_name?: boolean;
require_display_name?: boolean;
allow_utf8_local_part?: boolean;
require_tld?: boolean;
}
interface IsURLOptions {
protocols?: string[];
require_tld?: boolean;
require_protocol?: boolean;
require_host?: boolean;
require_valid_protocol?: boolean;
allow_underscores?: boolean;
host_whitelist?: (string | RegExp)[];
host_blacklist?: (string | RegExp)[];
allow_trailing_dot?: boolean;
allow_protocol_relative_urls?: boolean;
disallow_auth?: boolean;
}
declare type HashAlgorithm = "md4" | "md5" | "sha1" | "sha256" | "sha384" | "sha512" | "ripemd128" | "ripemd160" | "tiger128" | "tiger160" | "tiger192" | "crc32" | "crc32b";
/**
* Validator Functions
*/
export declare const FunctionValidator: any;
/**
* type checked rules
*
* @export
* @type {number}
*/
export declare type ValidRules = "IsNotEmpty" | "IsDate" | "IsEmail" | "IsIP" | "IsPhoneNumber" | "IsUrl" | "IsHash" | "IsCnName" | "IsIdNumber" | "IsZipCode" | "IsMobile" | "IsPlateNumber";
/**
* Use functions or built-in rules for validation.
*
* @export
* @param {string} name
* @param {*} value
* @param {string} type
* @param {(ValidRules | ValidRules[] | Function)} rule
* @param {string} [message]
* @param {boolean} [checkType=true]
* @returns
*/
export declare function ValidatorFuncs(name: string, value: any, type: string, rule: ValidRules | ValidRules[] | Function, message?: string, checkType?: boolean): any;
/**
* append to the target class method to validated parameter.
*
* @export
* @param {*} target
* @param {string} propertyKey
*/
/**
* Set property as included in the process of transformation.
*
* @export
* @param {Object} object
* @param {(string | symbol)} propertyName
*/
export declare function setExpose(object: Object, propertyName: string | symbol): void;
/**
* Marks property as included in the process of transformation.
*
* @export
* @returns {PropertyDecorator}
*/
export declare function Expose(): PropertyDecorator;
/**
* Identifies that the field needs to be defined
*
* @export
* @returns {PropertyDecorator}
*/
export declare function IsDefined(): PropertyDecorator;
/**
* Checks if value is a chinese name.
*
* @export
* @param {string} property
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsCnName(validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if value is a idcard number(chinese).
*
* @export
* @param {string} property
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsIdNumber(validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if value is a zipcode(chinese).
*
* @export
* @param {string} property
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsZipCode(validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if value is a mobile phone number(chinese).
*
* @export
* @param {string} property
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsMobile(validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if value is a plate number(chinese).
*
* @export
* @param {string} property
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsPlateNumber(validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks value is not empty, undefined, null, '', NaN, [], {} and any empty string(including spaces, tabs, formfeeds, etc.), returns false.
*
* @export
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsNotEmpty(validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if value matches ("===") the comparison.
*
* @export
* @param {*} comparison
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function Equals(comparison: any, validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if value does not match ("!==") the comparison.
*
* @export
* @param {*} comparison
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function NotEquals(comparison: any, validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if the string contains the seed.
*
* @export
* @param {string} seed
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function Contains(seed: string, validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if given value is in a array of allowed values.
*
* @export
* @param {any[]} possibleValues
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsIn(possibleValues: any[], validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if given value not in a array of allowed values.
*
* @export
* @param {any[]} possibleValues
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsNotIn(possibleValues: any[], validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if a given value is a real date.
*
* @export
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsDate(validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if the first number is greater than or equal to the min value.
*
* @export
* @param {number} min
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function Min(min: number, validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if the first number is less than or equal to the max value.
*
* @export
* @param {number} max
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function Max(max: number, validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if the string's length falls in a range. Note: this function takes into account surrogate pairs. If given value is not a string, then it returns false.
*
* @export
* @param {number} min
* @param {number} [max]
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function Length(min: number, max?: number, validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if the string is an email. If given value is not a string, then it returns false.
*
* @export
* @param {IsEmailOptions} [options]
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsEmail(options?: IsEmailOptions, validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if the string is an IP (version 4 or 6). If given value is not a string, then it returns false.
*
* @export
* @param {number} [version]
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsIP(version?: IsIpVersion, validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if the string is a valid phone number.
*
* @export
* @param {string} {string} region 2 characters uppercase country code (e.g. DE, US, CH).
* If users must enter the intl. prefix (e.g. +41), then you may pass "ZZ" or null as region.
* See [google-libphonenumber, metadata.js:countryCodeToRegionCodeMap on github]{@link https://github.com/ruimarinho/google-libphonenumber/blob/1e46138878cff479aafe2ce62175c6c49cb58720/src/metadata.js#L33}
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsPhoneNumber(region: string, validationOptions?: ValidationOptions): PropertyDecorator;
/**
* Checks if the string is an url.
*
* @export
* @param {IsURLOptions} [options]
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsUrl(options?: IsURLOptions, validationOptions?: ValidationOptions): PropertyDecorator;
/**
* check if the string is a hash of type algorithm. Algorithm is one of ['md4', 'md5', 'sha1', 'sha256', 'sha384', 'sha512', 'ripemd128', 'ripemd160', 'tiger128', 'tiger160', 'tiger192', 'crc32', 'crc32b']
*
* @export
* @param {HashAlgorithm} algorithm
* @param {ValidationOptions} [validationOptions]
* @returns {PropertyDecorator}
*/
export declare function IsHash(algorithm: HashAlgorithm, validationOptions?: ValidationOptions): PropertyDecorator;
export {};