fastest-validator
Advanced tools
Comparing version 1.11.0 to 1.11.1
@@ -0,1 +1,12 @@ | ||
<a name="1.11.1"></a> | ||
# 1.11.1 (2021-07-14) | ||
## Changes | ||
- fix debug mode. [#237](https://github.com/icebob/fastest-validator/pull/237) | ||
- fix object "toString" issue. [#235](https://github.com/icebob/fastest-validator/pull/235) | ||
- remove Node 10 from CI pipeline. | ||
- refactoring the typescript definitions. [#251](https://github.com/icebob/fastest-validator/pull/251) | ||
- update examples in readme. [#255](https://github.com/icebob/fastest-validator/pull/255) | ||
-------------------------------------------------- | ||
<a name="1.11.0"></a> | ||
@@ -58,2 +69,3 @@ # 1.11.0 (2021-05-11) | ||
- | ||
-------------------------------------------------- | ||
<a name="1.10.1"></a> | ||
@@ -60,0 +72,0 @@ # 1.10.1 (2021-03-22) |
1823
dist/index.d.ts
@@ -1,815 +0,809 @@ | ||
declare module "fastest-validator" { | ||
export type ValidationRuleName = | ||
| "any" | ||
| "array" | ||
| "boolean" | ||
| "class" | ||
| "custom" | ||
| "date" | ||
| "email" | ||
| "enum" | ||
| "equal" | ||
| "forbidden" | ||
| "function" | ||
| "luhn" | ||
| "mac" | ||
| "multi" | ||
| "number" | ||
| "object" | ||
| "string" | ||
| "url" | ||
| "uuid" | ||
| string; | ||
/** | ||
* Validation schema definition for "any" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#any | ||
*/ | ||
export interface RuleAny extends RuleCustom { | ||
/** | ||
* Type of all possible Built-in validators names | ||
* Name of built-in validator | ||
*/ | ||
export type ValidationRuleName = | ||
| "any" | ||
| "array" | ||
| "boolean" | ||
| "class" | ||
| "custom" | ||
| "date" | ||
| "email" | ||
| "enum" | ||
| "equal" | ||
| "forbidden" | ||
| "function" | ||
| "luhn" | ||
| "mac" | ||
| "multi" | ||
| "number" | ||
| "object" | ||
| "string" | ||
| "url" | ||
| "uuid" | ||
| string; | ||
type: "any"; | ||
} | ||
/** | ||
* Validation schema definition for "array" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#array | ||
*/ | ||
export interface RuleArray<T = any> extends RuleCustom { | ||
/** | ||
* Validation schema definition for "any" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#any | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleAny extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "any"; | ||
} | ||
type: "array"; | ||
/** | ||
* Validation schema definition for "array" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#array | ||
* If true, the validator accepts an empty array []. | ||
* @default true | ||
*/ | ||
export interface RuleArray<T = any> extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "array"; | ||
/** | ||
* If true, the validator accepts an empty array []. | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
/** | ||
* Minimum count of elements | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum count of elements | ||
*/ | ||
max?: number; | ||
/** | ||
* Fixed count of elements | ||
*/ | ||
length?: number; | ||
/** | ||
* The array must contain this element too | ||
*/ | ||
contains?: T | T[]; | ||
/** | ||
* Every element must be an element of the enum array | ||
*/ | ||
enum?: T[]; | ||
/** | ||
* Validation rules that should be applied to each element of array | ||
*/ | ||
items?: ValidationRule; | ||
} | ||
empty?: boolean; | ||
/** | ||
* Minimum count of elements | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum count of elements | ||
*/ | ||
max?: number; | ||
/** | ||
* Fixed count of elements | ||
*/ | ||
length?: number; | ||
/** | ||
* The array must contain this element too | ||
*/ | ||
contains?: T | T[]; | ||
/** | ||
* Every element must be an element of the enum array | ||
*/ | ||
enum?: T[]; | ||
/** | ||
* Validation rules that should be applied to each element of array | ||
*/ | ||
items?: ValidationRule; | ||
} | ||
/** | ||
* Validation schema definition for "boolean" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#boolean | ||
*/ | ||
export interface RuleBoolean extends RuleCustom { | ||
/** | ||
* Validation schema definition for "boolean" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#boolean | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleBoolean extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "boolean"; | ||
/** | ||
* if true and the type is not Boolean, try to convert. 1, "true", "1", "on" will be true. 0, "false", "0", "off" will be false. | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
} | ||
type: "boolean"; | ||
/** | ||
* if true and the type is not Boolean, try to convert. 1, "true", "1", "on" will be true. 0, "false", "0", "off" will be false. | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "class" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#class | ||
*/ | ||
export interface RuleClass<T = any> extends RuleCustom { | ||
/** | ||
* Validation schema definition for "class" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#class | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleClass<T = any> extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "class"; | ||
/** | ||
* Checked Class | ||
*/ | ||
instanceOf?: T; | ||
} | ||
type: "class"; | ||
/** | ||
* Checked Class | ||
*/ | ||
instanceOf?: T; | ||
} | ||
/** | ||
* Validation schema definition for "date" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#date | ||
*/ | ||
export interface RuleDate extends RuleCustom { | ||
/** | ||
* Validation schema definition for "date" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#date | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleDate extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "date"; | ||
/** | ||
* if true and the type is not Date, try to convert with new Date() | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
} | ||
type: "date"; | ||
/** | ||
* if true and the type is not Date, try to convert with new Date() | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "email" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#email | ||
*/ | ||
export interface RuleEmail extends RuleCustom { | ||
/** | ||
* Validation schema definition for "email" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#email | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleEmail extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "email"; | ||
/** | ||
* If true, the validator accepts an empty string "" | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
/** | ||
* Checker method. Can be quick or precise | ||
*/ | ||
mode?: "quick" | "precise"; | ||
/** | ||
* Minimum value length | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum value length | ||
*/ | ||
max?: number; | ||
type: "email"; | ||
/** | ||
* If true, the validator accepts an empty string "" | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
/** | ||
* Checker method. Can be quick or precise | ||
*/ | ||
mode?: "quick" | "precise"; | ||
/** | ||
* Minimum value length | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum value length | ||
*/ | ||
max?: number; | ||
normalize?: boolean; | ||
} | ||
normalize?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "enum" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#enum | ||
*/ | ||
export interface RuleEnum<T = any> extends RuleCustom { | ||
/** | ||
* Validation schema definition for "enum" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#enum | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleEnum<T = any> extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "enum"; | ||
/** | ||
* The valid values | ||
*/ | ||
values: T[]; | ||
} | ||
type: "enum"; | ||
/** | ||
* The valid values | ||
*/ | ||
values: T[]; | ||
} | ||
/** | ||
* Validation schema definition for "equal" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#equal | ||
*/ | ||
export interface RuleEqual<T = any> extends RuleCustom { | ||
/** | ||
* Validation schema definition for "equal" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#equal | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleEqual<T = any> extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "equal"; | ||
/** | ||
* The valid value | ||
*/ | ||
value?: T; | ||
type: "equal"; | ||
/** | ||
* The valid value | ||
*/ | ||
value?: T; | ||
/** | ||
* Another field name | ||
*/ | ||
field?: string; | ||
/** | ||
* Another field name | ||
*/ | ||
field?: string; | ||
/** | ||
* Strict value checking. | ||
* | ||
* @type {'boolean'} | ||
* @memberof RuleEqual | ||
*/ | ||
strict?: boolean; | ||
} | ||
/** | ||
* Strict value checking. | ||
* | ||
* @type {'boolean'} | ||
* @memberof RuleEqual | ||
*/ | ||
strict?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "forbidden" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#forbidden | ||
*/ | ||
export interface RuleForbidden extends RuleCustom { | ||
/** | ||
* Validation schema definition for "forbidden" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#forbidden | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleForbidden extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "forbidden"; | ||
type: "forbidden"; | ||
/** | ||
* Removes the forbidden value. | ||
* | ||
* @type {'boolean'} | ||
* @memberof RuleForbidden | ||
*/ | ||
remove?: boolean; | ||
} | ||
/** | ||
* Removes the forbidden value. | ||
* | ||
* @type {'boolean'} | ||
* @memberof RuleForbidden | ||
*/ | ||
remove?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "function" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#function | ||
*/ | ||
export interface RuleFunction extends RuleCustom { | ||
/** | ||
* Validation schema definition for "function" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#function | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleFunction extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "function"; | ||
} | ||
type: "function"; | ||
} | ||
/** | ||
* Validation schema definition for "luhn" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#luhn | ||
*/ | ||
export interface RuleLuhn extends RuleCustom { | ||
/** | ||
* Validation schema definition for "luhn" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#luhn | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleLuhn extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "luhn"; | ||
} | ||
type: "luhn"; | ||
} | ||
/** | ||
* Validation schema definition for "mac" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#mac | ||
*/ | ||
export interface RuleMac extends RuleCustom { | ||
/** | ||
* Validation schema definition for "mac" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#mac | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleMac extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "mac"; | ||
} | ||
type: "mac"; | ||
} | ||
/** | ||
* Validation schema definition for "multi" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#multi | ||
*/ | ||
export interface RuleMulti extends RuleCustom { | ||
/** | ||
* Validation schema definition for "multi" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#multi | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleMulti extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "multi"; | ||
type: "multi"; | ||
rules: RuleCustom[] | string[]; | ||
} | ||
rules: RuleCustom[] | string[]; | ||
} | ||
/** | ||
* Validation schema definition for "number" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#number | ||
*/ | ||
export interface RuleNumber extends RuleCustom { | ||
/** | ||
* Validation schema definition for "number" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#number | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleNumber extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "number"; | ||
/** | ||
* Minimum value | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum value | ||
*/ | ||
max?: number; | ||
/** | ||
* Fixed value | ||
*/ | ||
equal?: number; | ||
/** | ||
* Can't be equal to this value | ||
*/ | ||
notEqual?: number; | ||
/** | ||
* The value must be a non-decimal value | ||
* @default false | ||
*/ | ||
integer?: boolean; | ||
/** | ||
* The value must be greater than zero | ||
* @default false | ||
*/ | ||
positive?: boolean; | ||
/** | ||
* The value must be less than zero | ||
* @default false | ||
*/ | ||
negative?: boolean; | ||
/** | ||
* if true and the type is not Number, converts with Number() | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
} | ||
type: "number"; | ||
/** | ||
* Minimum value | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum value | ||
*/ | ||
max?: number; | ||
/** | ||
* Fixed value | ||
*/ | ||
equal?: number; | ||
/** | ||
* Can't be equal to this value | ||
*/ | ||
notEqual?: number; | ||
/** | ||
* The value must be a non-decimal value | ||
* @default false | ||
*/ | ||
integer?: boolean; | ||
/** | ||
* The value must be greater than zero | ||
* @default false | ||
*/ | ||
positive?: boolean; | ||
/** | ||
* The value must be less than zero | ||
* @default false | ||
*/ | ||
negative?: boolean; | ||
/** | ||
* if true and the type is not Number, converts with Number() | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "object" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#object | ||
*/ | ||
export interface RuleObject extends RuleCustom { | ||
/** | ||
* Validation schema definition for "object" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#object | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleObject extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "object"; | ||
/** | ||
* if true any properties which are not defined on the schema will throw an error. | ||
* @default false | ||
*/ | ||
strict?: boolean; | ||
/** | ||
* List of properties that should be validated by this rule | ||
*/ | ||
properties?: ValidationSchema; | ||
props?: ValidationSchema; | ||
/** | ||
* If set to a number, will throw if the number of props is less than that number. | ||
*/ | ||
minProps?: number; | ||
/** | ||
* If set to a number, will throw if the number of props is greater than that number. | ||
*/ | ||
maxProps?: number; | ||
} | ||
type: "object"; | ||
/** | ||
* if true any properties which are not defined on the schema will throw an error. | ||
* @default false | ||
*/ | ||
strict?: boolean; | ||
/** | ||
* List of properties that should be validated by this rule | ||
*/ | ||
properties?: ValidationSchema; | ||
props?: ValidationSchema; | ||
/** | ||
* If set to a number, will throw if the number of props is less than that number. | ||
*/ | ||
minProps?: number; | ||
/** | ||
* If set to a number, will throw if the number of props is greater than that number. | ||
*/ | ||
maxProps?: number; | ||
} | ||
export interface RuleObjectID extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "objectID"; | ||
/** | ||
* To inject ObjectID dependency | ||
*/ | ||
ObjectID?: { | ||
new (id?: string | number | ObjectIdAbstract): ObjectIdAbstract; | ||
isValid(o: any): boolean; | ||
}; | ||
/** | ||
* Convert HexStringObjectID to ObjectID | ||
*/ | ||
convert?: boolean | "hexString"; | ||
} | ||
export interface RuleObjectID extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "objectID"; | ||
/** | ||
* To inject ObjectID dependency | ||
*/ | ||
ObjectID?: any; | ||
/** | ||
* Convert HexStringObjectID to ObjectID | ||
*/ | ||
convert?: boolean | "hexString"; | ||
} | ||
/** | ||
* Validation schema definition for "string" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#string | ||
*/ | ||
export interface RuleString extends RuleCustom { | ||
/** | ||
* Validation schema definition for "string" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#string | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleString extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "string"; | ||
/** | ||
* If true, the validator accepts an empty string "" | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
/** | ||
* Minimum value length | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum value length | ||
*/ | ||
max?: number; | ||
/** | ||
* Fixed value length | ||
*/ | ||
length?: number; | ||
/** | ||
* Regex pattern | ||
*/ | ||
pattern?: string | RegExp; | ||
/** | ||
* The value must contain this text | ||
*/ | ||
contains?: string[]; | ||
/** | ||
* The value must be an element of the enum array | ||
*/ | ||
enum?: string[]; | ||
/** | ||
* The value must be an alphabetic string | ||
*/ | ||
numeric?: boolean; | ||
/** | ||
* The value must be a numeric string | ||
*/ | ||
alpha?: boolean; | ||
/** | ||
* The value must be an alphanumeric string | ||
*/ | ||
alphanum?: boolean; | ||
/** | ||
* The value must be an alphabetic string that contains dashes | ||
*/ | ||
alphadash?: boolean; | ||
/** | ||
* The value must be a hex string | ||
* @default false | ||
*/ | ||
hex?: boolean; | ||
/** | ||
* The value must be a singleLine string | ||
* @default false | ||
*/ | ||
singleLine?: boolean; | ||
/** | ||
* The value must be a base64 string | ||
* @default false | ||
*/ | ||
base64?: boolean; | ||
/** | ||
* if true and the type is not a String, converts with String() | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
type: "string"; | ||
/** | ||
* If true, the validator accepts an empty string "" | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
/** | ||
* Minimum value length | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum value length | ||
*/ | ||
max?: number; | ||
/** | ||
* Fixed value length | ||
*/ | ||
length?: number; | ||
/** | ||
* Regex pattern | ||
*/ | ||
pattern?: string | RegExp; | ||
/** | ||
* The value must contain this text | ||
*/ | ||
contains?: string[]; | ||
/** | ||
* The value must be an element of the enum array | ||
*/ | ||
enum?: string[]; | ||
/** | ||
* The value must be an alphabetic string | ||
*/ | ||
numeric?: boolean; | ||
/** | ||
* The value must be a numeric string | ||
*/ | ||
alpha?: boolean; | ||
/** | ||
* The value must be an alphanumeric string | ||
*/ | ||
alphanum?: boolean; | ||
/** | ||
* The value must be an alphabetic string that contains dashes | ||
*/ | ||
alphadash?: boolean; | ||
/** | ||
* The value must be a hex string | ||
* @default false | ||
*/ | ||
hex?: boolean; | ||
/** | ||
* The value must be a singleLine string | ||
* @default false | ||
*/ | ||
singleLine?: boolean; | ||
/** | ||
* The value must be a base64 string | ||
* @default false | ||
*/ | ||
base64?: boolean; | ||
/** | ||
* if true and the type is not a String, converts with String() | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
trim?: boolean; | ||
trimLeft?: boolean; | ||
trimRight?: boolean; | ||
trim?: boolean; | ||
trimLeft?: boolean; | ||
trimRight?: boolean; | ||
padStart?: number; | ||
padEnd?: number; | ||
padChar?: string; | ||
padStart?: number; | ||
padEnd?: number; | ||
padChar?: string; | ||
lowercase?: boolean; | ||
uppercase?: boolean; | ||
localeLowercase?: boolean; | ||
localeUppercase?: boolean; | ||
} | ||
lowercase?: boolean; | ||
uppercase?: boolean; | ||
localeLowercase?: boolean; | ||
localeUppercase?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "tuple" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#array | ||
*/ | ||
export interface RuleTuple<T = any> extends RuleCustom { | ||
/** | ||
* Validation schema definition for "tuple" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#array | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleTuple<T = any> extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "tuple"; | ||
/** | ||
* Validation rules that should be applied to the corresponding element of array | ||
*/ | ||
items?: [ValidationRule, ValidationRule]; | ||
} | ||
type: "tuple"; | ||
/** | ||
* Validation rules that should be applied to the corresponding element of array | ||
*/ | ||
items?: [ValidationRule, ValidationRule]; | ||
} | ||
/** | ||
* Validation schema definition for "url" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#url | ||
*/ | ||
export interface RuleURL extends RuleCustom { | ||
/** | ||
* Validation schema definition for "url" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#url | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleURL extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "url"; | ||
/** | ||
* If true, the validator accepts an empty string "" | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
} | ||
type: "url"; | ||
/** | ||
* If true, the validator accepts an empty string "" | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "uuid" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#uuid | ||
*/ | ||
export interface RuleUUID extends RuleCustom { | ||
/** | ||
* Validation schema definition for "uuid" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#uuid | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleUUID extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "uuid"; | ||
/** | ||
* UUID version in range 0-6 | ||
*/ | ||
version?: 0 | 1 | 2 | 3 | 4 | 5 | 6; | ||
} | ||
type: "uuid"; | ||
/** | ||
* UUID version in range 0-6 | ||
*/ | ||
version?: 0 | 1 | 2 | 3 | 4 | 5 | 6; | ||
} | ||
/** | ||
* Validation schema definition for custom inline validator | ||
* @see https://github.com/icebob/fastest-validator#custom-validator | ||
*/ | ||
export interface RuleCustomInline<T = any> extends RuleCustom { | ||
/** | ||
* Validation schema definition for custom inline validator | ||
* @see https://github.com/icebob/fastest-validator#custom-validator | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleCustomInline<T = any> extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "custom"; | ||
/** | ||
* Custom checker function | ||
*/ | ||
check: CheckerFunction<T>; | ||
} | ||
type: "custom"; | ||
/** | ||
* Custom checker function | ||
*/ | ||
check: CheckerFunction<T>; | ||
} | ||
/** | ||
* Validation schema definition for custom validator | ||
* @see https://github.com/icebob/fastest-validator#custom-validator | ||
*/ | ||
export interface RuleCustom { | ||
/** | ||
* Validation schema definition for custom validator | ||
* @see https://github.com/icebob/fastest-validator#custom-validator | ||
* Name of custom validator that will be used in validation rules | ||
*/ | ||
export interface RuleCustom { | ||
/** | ||
* Name of custom validator that will be used in validation rules | ||
*/ | ||
type: string; | ||
/** | ||
* Every field in the schema will be required by default. If you'd like to define optional fields, set optional: true. | ||
* @default false | ||
*/ | ||
optional?: boolean; | ||
type: string; | ||
/** | ||
* Every field in the schema will be required by default. If you'd like to define optional fields, set optional: true. | ||
* @default false | ||
*/ | ||
optional?: boolean; | ||
/** | ||
* If you want disallow `undefined` value but allow `null` value, use `nullable` instead of `optional`. | ||
* @default false | ||
*/ | ||
nullable?: boolean; | ||
/** | ||
* If you want disallow `undefined` value but allow `null` value, use `nullable` instead of `optional`. | ||
* @default false | ||
*/ | ||
nullable?: boolean; | ||
/** | ||
* You can set your custom messages in the validator constructor | ||
* Sometimes the standard messages are too generic. You can customise messages per validation type per field | ||
*/ | ||
messages?: MessagesType; | ||
/** | ||
* You can set your custom messages in the validator constructor | ||
* Sometimes the standard messages are too generic. You can customise messages per validation type per field | ||
*/ | ||
messages?: MessagesType; | ||
/** | ||
* Default value | ||
*/ | ||
default?: any; | ||
/** | ||
* Default value | ||
*/ | ||
default?: any; | ||
/** | ||
* Custom checker function | ||
*/ | ||
custom?: CheckerFunction; | ||
/** | ||
* Custom checker function | ||
*/ | ||
custom?: CheckerFunction; | ||
/** | ||
* You can define any additional options for custom validators | ||
*/ | ||
[key: string]: any; | ||
} | ||
/** | ||
* You can define any additional options for custom validators | ||
*/ | ||
[key: string]: any; | ||
} | ||
/** | ||
* List of all possible keys that can be used for error message override | ||
*/ | ||
export interface BuiltInMessages { | ||
/** | ||
* List of all possible keys that can be used for error message override | ||
* The '{field}' field is required. | ||
*/ | ||
export interface BuiltInMessages { | ||
/** | ||
* The '{field}' field is required. | ||
*/ | ||
required?: string; | ||
/** | ||
* The '{field}' field must be a string. | ||
*/ | ||
string?: string; | ||
/** | ||
* The '{field}' field must not be empty. | ||
*/ | ||
stringEmpty?: string; | ||
/** | ||
* The '{field}' field length must be greater than or equal to {expected} characters long. | ||
*/ | ||
stringMin?: string; | ||
/** | ||
* The '{field}' field length must be less than or equal to {expected} characters long. | ||
*/ | ||
stringMax?: string; | ||
/** | ||
* The '{field}' field length must be {expected} characters long. | ||
*/ | ||
stringLength?: string; | ||
/** | ||
* The '{field}' field fails to match the required pattern. | ||
*/ | ||
stringPattern?: string; | ||
/** | ||
* The '{field}' field must contain the '{expected}' text. | ||
*/ | ||
stringContains?: string; | ||
/** | ||
* The '{field}' field does not match any of the allowed values. | ||
*/ | ||
stringEnum?: string; | ||
/** | ||
* The '{field}' field must be a numeric string. | ||
*/ | ||
stringNumeric?: string; | ||
/** | ||
* The '{field}' field must be an alphabetic string. | ||
*/ | ||
stringAlpha?: string; | ||
/** | ||
* The '{field}' field must be an alphanumeric string. | ||
*/ | ||
stringAlphanum?: string; | ||
/** | ||
* The '{field}' field must be an alphadash string. | ||
*/ | ||
stringAlphadash?: string; | ||
required?: string; | ||
/** | ||
* The '{field}' field must be a string. | ||
*/ | ||
string?: string; | ||
/** | ||
* The '{field}' field must not be empty. | ||
*/ | ||
stringEmpty?: string; | ||
/** | ||
* The '{field}' field length must be greater than or equal to {expected} characters long. | ||
*/ | ||
stringMin?: string; | ||
/** | ||
* The '{field}' field length must be less than or equal to {expected} characters long. | ||
*/ | ||
stringMax?: string; | ||
/** | ||
* The '{field}' field length must be {expected} characters long. | ||
*/ | ||
stringLength?: string; | ||
/** | ||
* The '{field}' field fails to match the required pattern. | ||
*/ | ||
stringPattern?: string; | ||
/** | ||
* The '{field}' field must contain the '{expected}' text. | ||
*/ | ||
stringContains?: string; | ||
/** | ||
* The '{field}' field does not match any of the allowed values. | ||
*/ | ||
stringEnum?: string; | ||
/** | ||
* The '{field}' field must be a numeric string. | ||
*/ | ||
stringNumeric?: string; | ||
/** | ||
* The '{field}' field must be an alphabetic string. | ||
*/ | ||
stringAlpha?: string; | ||
/** | ||
* The '{field}' field must be an alphanumeric string. | ||
*/ | ||
stringAlphanum?: string; | ||
/** | ||
* The '{field}' field must be an alphadash string. | ||
*/ | ||
stringAlphadash?: string; | ||
/** | ||
* The '{field}' field must be a number. | ||
*/ | ||
number?: string; | ||
/** | ||
* The '{field}' field must be greater than or equal to {expected}. | ||
*/ | ||
numberMin?: string; | ||
/** | ||
* The '{field}' field must be less than or equal to {expected}. | ||
*/ | ||
numberMax?: string; | ||
/** | ||
* The '{field}' field must be equal with {expected}. | ||
*/ | ||
numberEqual?: string; | ||
/** | ||
* The '{field}' field can't be equal with {expected}. | ||
*/ | ||
numberNotEqual?: string; | ||
/** | ||
* The '{field}' field must be an integer. | ||
*/ | ||
numberInteger?: string; | ||
/** | ||
* The '{field}' field must be a positive number. | ||
*/ | ||
numberPositive?: string; | ||
/** | ||
* The '{field}' field must be a negative number. | ||
*/ | ||
numberNegative?: string; | ||
/** | ||
* The '{field}' field must be a number. | ||
*/ | ||
number?: string; | ||
/** | ||
* The '{field}' field must be greater than or equal to {expected}. | ||
*/ | ||
numberMin?: string; | ||
/** | ||
* The '{field}' field must be less than or equal to {expected}. | ||
*/ | ||
numberMax?: string; | ||
/** | ||
* The '{field}' field must be equal with {expected}. | ||
*/ | ||
numberEqual?: string; | ||
/** | ||
* The '{field}' field can't be equal with {expected}. | ||
*/ | ||
numberNotEqual?: string; | ||
/** | ||
* The '{field}' field must be an integer. | ||
*/ | ||
numberInteger?: string; | ||
/** | ||
* The '{field}' field must be a positive number. | ||
*/ | ||
numberPositive?: string; | ||
/** | ||
* The '{field}' field must be a negative number. | ||
*/ | ||
numberNegative?: string; | ||
/** | ||
* The '{field}' field must be an array. | ||
*/ | ||
array?: string; | ||
/** | ||
* The '{field}' field must not be an empty array. | ||
*/ | ||
arrayEmpty?: string; | ||
/** | ||
* The '{field}' field must contain at least {expected} items. | ||
*/ | ||
arrayMin?: string; | ||
/** | ||
* The '{field}' field must contain less than or equal to {expected} items. | ||
*/ | ||
arrayMax?: string; | ||
/** | ||
* The '{field}' field must contain {expected} items. | ||
*/ | ||
arrayLength?: string; | ||
/** | ||
* The '{field}' field must contain the '{expected}' item. | ||
*/ | ||
arrayContains?: string; | ||
/** | ||
* The '{field} field value '{expected}' does not match any of the allowed values. | ||
*/ | ||
arrayEnum?: string; | ||
/** | ||
* The '{field}' field must be an array. | ||
*/ | ||
array?: string; | ||
/** | ||
* The '{field}' field must not be an empty array. | ||
*/ | ||
arrayEmpty?: string; | ||
/** | ||
* The '{field}' field must contain at least {expected} items. | ||
*/ | ||
arrayMin?: string; | ||
/** | ||
* The '{field}' field must contain less than or equal to {expected} items. | ||
*/ | ||
arrayMax?: string; | ||
/** | ||
* The '{field}' field must contain {expected} items. | ||
*/ | ||
arrayLength?: string; | ||
/** | ||
* The '{field}' field must contain the '{expected}' item. | ||
*/ | ||
arrayContains?: string; | ||
/** | ||
* The '{field} field value '{expected}' does not match any of the allowed values. | ||
*/ | ||
arrayEnum?: string; | ||
/** | ||
* The '{field}' field must be a boolean. | ||
*/ | ||
boolean?: string; | ||
/** | ||
* The '{field}' field must be a boolean. | ||
*/ | ||
boolean?: string; | ||
/** | ||
* The '{field}' field must be a Date. | ||
*/ | ||
date?: string; | ||
/** | ||
* The '{field}' field must be greater than or equal to {expected}. | ||
*/ | ||
dateMin?: string; | ||
/** | ||
* The '{field}' field must be less than or equal to {expected}. | ||
*/ | ||
dateMax?: string; | ||
/** | ||
* The '{field}' field must be a Date. | ||
*/ | ||
date?: string; | ||
/** | ||
* The '{field}' field must be greater than or equal to {expected}. | ||
*/ | ||
dateMin?: string; | ||
/** | ||
* The '{field}' field must be less than or equal to {expected}. | ||
*/ | ||
dateMax?: string; | ||
/** | ||
* The '{field}' field value '{expected}' does not match any of the allowed values. | ||
*/ | ||
enumValue?: string; | ||
/** | ||
* The '{field}' field value '{expected}' does not match any of the allowed values. | ||
*/ | ||
enumValue?: string; | ||
/** | ||
* The '{field}' field value must be equal to '{expected}'. | ||
*/ | ||
equalValue?: string; | ||
/** | ||
* The '{field}' field value must be equal to '{expected}' field value. | ||
*/ | ||
equalField?: string; | ||
/** | ||
* The '{field}' field value must be equal to '{expected}'. | ||
*/ | ||
equalValue?: string; | ||
/** | ||
* The '{field}' field value must be equal to '{expected}' field value. | ||
*/ | ||
equalField?: string; | ||
/** | ||
* The '{field}' field is forbidden. | ||
*/ | ||
forbidden?: string; | ||
/** | ||
* The '{field}' field is forbidden. | ||
*/ | ||
forbidden?: string; | ||
/** | ||
* The '{field}' field must be a function. | ||
*/ | ||
function?: string; | ||
/** | ||
* The '{field}' field must be a function. | ||
*/ | ||
function?: string; | ||
/** | ||
* The '{field}' field must be a valid e-mail. | ||
*/ | ||
email?: string; | ||
/** | ||
* The '{field}' field must be a valid e-mail. | ||
*/ | ||
email?: string; | ||
/** | ||
* The '{field}' field must be a valid checksum luhn. | ||
*/ | ||
luhn?: string; | ||
/** | ||
* The '{field}' field must be a valid checksum luhn. | ||
*/ | ||
luhn?: string; | ||
/** | ||
* The '{field}' field must be a valid MAC address. | ||
*/ | ||
mac?: string; | ||
/** | ||
* The '{field}' field must be a valid MAC address. | ||
*/ | ||
mac?: string; | ||
/** | ||
* The '{field}' must be an Object. | ||
*/ | ||
object?: string; | ||
/** | ||
* The object '{field}' contains forbidden keys: '{actual}'. | ||
*/ | ||
objectStrict?: string; | ||
/** | ||
* The '{field}' must be an Object. | ||
*/ | ||
object?: string; | ||
/** | ||
* The object '{field}' contains forbidden keys: '{actual}'. | ||
*/ | ||
objectStrict?: string; | ||
/** | ||
* The '{field}' field must be a valid URL. | ||
*/ | ||
url?: string; | ||
/** | ||
* The '{field}' field must be a valid URL. | ||
*/ | ||
url?: string; | ||
/** | ||
* The '{field}' field must be a valid UUID. | ||
*/ | ||
uuid?: string; | ||
/** | ||
* The '{field}' field must be a valid UUID version provided. | ||
*/ | ||
uuidVersion?: string; | ||
} | ||
/** | ||
* Type with description of custom error messages | ||
* The '{field}' field must be a valid UUID. | ||
*/ | ||
export type MessagesType = BuiltInMessages & { [key: string]: string }; | ||
uuid?: string; | ||
/** | ||
* The '{field}' field must be a valid UUID version provided. | ||
*/ | ||
uuidVersion?: string; | ||
} | ||
/** | ||
* Type with description of custom error messages | ||
*/ | ||
export type MessagesType = BuiltInMessages & { [key: string]: string }; | ||
/** | ||
* Union type of all possible built-in validators | ||
*/ | ||
export type ValidationRuleObject = | ||
| RuleAny | ||
| RuleArray | ||
| RuleBoolean | ||
| RuleClass | ||
| RuleDate | ||
| RuleEmail | ||
| RuleEqual | ||
| RuleEnum | ||
| RuleForbidden | ||
| RuleFunction | ||
| RuleLuhn | ||
| RuleMac | ||
| RuleMulti | ||
| RuleNumber | ||
| RuleObject | ||
| RuleObjectID | ||
| RuleString | ||
| RuleTuple | ||
| RuleURL | ||
| RuleUUID | ||
| RuleCustom | ||
| RuleCustomInline; | ||
/** | ||
* Description of validation rule definition for a some property | ||
*/ | ||
export type ValidationRule = | ||
| ValidationRuleObject | ||
| ValidationRuleObject[] | ||
| ValidationRuleName; | ||
/** | ||
* Definition for validation schema based on validation rules | ||
*/ | ||
export type ValidationSchema<T = any> = { | ||
/** | ||
* Union type of all possible built-in validators | ||
* Object properties which are not specified on the schema are ignored by default. | ||
* If you set the $$strict option to true any additional properties will result in an strictObject error. | ||
* @default false | ||
*/ | ||
export type ValidationRuleObject = | ||
| RuleAny | ||
| RuleArray | ||
| RuleBoolean | ||
| RuleClass | ||
| RuleDate | ||
| RuleEmail | ||
| RuleEqual | ||
| RuleEnum | ||
| RuleForbidden | ||
| RuleFunction | ||
| RuleLuhn | ||
| RuleMac | ||
| RuleMulti | ||
| RuleNumber | ||
| RuleObject | ||
| RuleObjectID | ||
| RuleString | ||
| RuleTuple | ||
| RuleURL | ||
| RuleUUID | ||
| RuleCustom | ||
| RuleCustomInline; | ||
$$strict?: boolean | "remove"; | ||
/** | ||
* Description of validation rule definition for a some property | ||
* Enable asynchronous functionality. In this case the `validate` and `compile` methods return a `Promise`. | ||
* @default false | ||
*/ | ||
export type ValidationRule = | ||
| ValidationRuleObject | ||
| ValidationRuleObject[] | ||
| ValidationRuleName; | ||
$$async?: boolean; | ||
/** | ||
* Definition for validation schema based on validation rules | ||
* Basically the validator expects that you want to validate a Javascript object. | ||
* If you want others, you can define the root level schema. | ||
* @default false | ||
*/ | ||
export type ValidationSchema<T = any> = { | ||
$$root?: boolean; | ||
} & { | ||
/** | ||
* Object properties which are not specified on the schema are ignored by default. | ||
* If you set the $$strict option to true any additional properties will result in an strictObject error. | ||
* @default false | ||
*/ | ||
$$strict?: boolean | "remove"; | ||
/** | ||
* Enable asynchronous functionality. In this case the `validate` and `compile` methods return a `Promise`. | ||
* @default false | ||
*/ | ||
$$async?: boolean; | ||
/** | ||
* Basically the validator expects that you want to validate a Javascript object. | ||
* If you want others, you can define the root level schema. | ||
* @default false | ||
*/ | ||
$$root?: boolean; | ||
} & { | ||
/** | ||
* List of validation rules for each defined field | ||
@@ -820,245 +814,238 @@ */ | ||
/** | ||
* Structure with description of validation error message | ||
*/ | ||
export interface ValidationError { | ||
/** | ||
* Structure with description of validation error message | ||
* Name of validation rule that generates this message | ||
*/ | ||
export interface ValidationError { | ||
/** | ||
* Name of validation rule that generates this message | ||
*/ | ||
type: keyof BuiltInMessages | string; | ||
/** | ||
* Field that catch validation error | ||
*/ | ||
field: string; | ||
/** | ||
* Description of current validation error | ||
*/ | ||
message?: string; | ||
/** | ||
* Expected value from validation rule | ||
*/ | ||
expected?: any; | ||
/** | ||
* Actual value received by validation rule | ||
*/ | ||
actual?: any; | ||
} | ||
type: keyof BuiltInMessages | string; | ||
/** | ||
* Field that catch validation error | ||
*/ | ||
field: string; | ||
/** | ||
* Description of current validation error | ||
*/ | ||
message?: string; | ||
/** | ||
* Expected value from validation rule | ||
*/ | ||
expected?: any; | ||
/** | ||
* Actual value received by validation rule | ||
*/ | ||
actual?: any; | ||
} | ||
/** | ||
* List of possible validator constructor options | ||
*/ | ||
export interface ValidatorConstructorOptions { | ||
debug?: boolean; | ||
/** | ||
* List of possible validator constructor options | ||
* List of possible error messages | ||
*/ | ||
export interface ValidatorConstructorOptions { | ||
debug?: boolean; | ||
/** | ||
* List of possible error messages | ||
*/ | ||
messages?: MessagesType; | ||
messages?: MessagesType; | ||
/** | ||
* using checker function v2? | ||
*/ | ||
useNewCustomCheckerFunction?: boolean; | ||
/** | ||
* using checker function v2? | ||
*/ | ||
useNewCustomCheckerFunction?: boolean; | ||
/** | ||
* Default settings for rules | ||
*/ | ||
defaults?: { | ||
[key in ValidationRuleName]: ValidationSchema; | ||
}; | ||
/** | ||
* Default settings for rules | ||
*/ | ||
defaults?: { | ||
[key in ValidationRuleName]: ValidationSchema; | ||
}; | ||
/** | ||
* For set aliases | ||
*/ | ||
aliases?: { | ||
[key: string]: ValidationRuleObject; | ||
}; | ||
/** | ||
* For set aliases | ||
*/ | ||
aliases?: { | ||
[key: string]: ValidationRuleObject; | ||
}; | ||
/** | ||
* For set custom rules. | ||
*/ | ||
customRules?: { | ||
[key: string]: CompilationFunction; | ||
}; | ||
/** | ||
* For set custom rules. | ||
*/ | ||
customRules?: { | ||
[key: string]: CompilationFunction; | ||
}; | ||
/** | ||
* For set plugins. | ||
*/ | ||
plugins?: PluginFn<any>[]; | ||
} | ||
/** | ||
* For set plugins. | ||
*/ | ||
plugins?: PluginFn<any>[]; | ||
} | ||
export interface CompilationRule { | ||
index: number; | ||
ruleFunction: CompilationFunction; | ||
schema: ValidationSchema; | ||
messages: MessagesType; | ||
} | ||
export interface CompilationRule { | ||
index: number; | ||
ruleFunction: CompilationFunction; | ||
schema: ValidationSchema; | ||
messages: MessagesType; | ||
} | ||
export interface Context { | ||
index: number; | ||
async: boolean; | ||
rules: ValidationRuleObject[]; | ||
fn: Function[]; | ||
customs: { | ||
[ruleName: string]: { schema: RuleCustom; messages: MessagesType }; | ||
}; | ||
meta?: object; | ||
} | ||
export interface Context { | ||
index: number; | ||
async: boolean; | ||
rules: ValidationRuleObject[]; | ||
fn: Function[]; | ||
customs: { | ||
[ruleName: string]: { schema: RuleCustom; messages: MessagesType }; | ||
}; | ||
meta?: object; | ||
} | ||
export interface CheckerFunctionError { | ||
type: string; | ||
expected?: unknown; | ||
actual?: unknown; | ||
field?: string; | ||
} | ||
export interface CheckerFunctionError { | ||
type: string; | ||
expected?: unknown; | ||
actual?: unknown; | ||
field?: string; | ||
} | ||
export type CheckerFunctionV1<T = unknown> = ( | ||
value: T, | ||
ruleSchema: ValidationRuleObject, | ||
path: string, | ||
parent: object | null, | ||
context: Context | ||
) => true | ValidationError[]; | ||
export type CheckerFunctionV2<T = unknown> = ( | ||
value: T, | ||
errors: CheckerFunctionError[], | ||
ruleSchema: ValidationRuleObject, | ||
path: string, | ||
parent: object | null, | ||
context: Context | ||
) => T; | ||
export type CheckerFunctionV1<T = unknown> = ( | ||
value: T, | ||
ruleSchema: ValidationRuleObject, | ||
path: string, | ||
parent: object | null, | ||
context: Context | ||
) => true | ValidationError[]; | ||
export type CheckerFunctionV2<T = unknown> = ( | ||
value: T, | ||
errors: CheckerFunctionError[], | ||
ruleSchema: ValidationRuleObject, | ||
path: string, | ||
parent: object | null, | ||
context: Context | ||
) => T; | ||
export type CheckerFunction<T = unknown> = | ||
| CheckerFunctionV1<T> | ||
| CheckerFunctionV2<T>; | ||
export type CheckerFunction<T = unknown> = | ||
| CheckerFunctionV1<T> | ||
| CheckerFunctionV2<T>; | ||
export type CompilationFunction = ( | ||
rule: CompilationRule, | ||
path: string, | ||
context: Context | ||
) => { sanitized?: boolean; source: string }; | ||
export type CompilationFunction = ( | ||
rule: CompilationRule, | ||
path: string, | ||
context: Context | ||
) => { sanitized?: boolean; source: string }; | ||
export type PluginFn<T = void> = (validator: Validator) => T; | ||
export type PluginFn<T = void> = (validator: Validator) => T; | ||
export class ObjectIdAbstract { | ||
static isValid(o: any): boolean; | ||
constructor(id?: string | number | ObjectIdAbstract); | ||
toHexString(): string; | ||
} | ||
export interface CheckFunctionOptions { | ||
meta?: object | null; | ||
} | ||
export interface CheckFunctionOptions { | ||
meta?: object | null; | ||
} | ||
export interface SyncCheckFunction { | ||
(value: any, opts?: CheckFunctionOptions): true | ValidationError[] | ||
async: false | ||
} | ||
export interface SyncCheckFunction { | ||
(value: any, opts?: CheckFunctionOptions): true | ValidationError[] | ||
async: false | ||
} | ||
export interface AsyncCheckFunction { | ||
(value: any, opts?: CheckFunctionOptions): Promise<true | ValidationError[]> | ||
async: true | ||
} | ||
export interface AsyncCheckFunction { | ||
(value: any, opts?: CheckFunctionOptions): Promise<true | ValidationError[]> | ||
async: true | ||
} | ||
export default class Validator { | ||
/** | ||
* List of possible error messages | ||
*/ | ||
messages: MessagesType; | ||
export default class Validator { | ||
/** | ||
* List of possible error messages | ||
*/ | ||
messages: MessagesType; | ||
/** | ||
* List of rules attached to current validator | ||
*/ | ||
rules: { [key: string]: ValidationRuleObject }; | ||
/** | ||
* List of rules attached to current validator | ||
*/ | ||
rules: { [key: string]: ValidationRuleObject }; | ||
/** | ||
* List of aliases attached to current validator | ||
*/ | ||
aliases: { [key: string]: ValidationRule }; | ||
/** | ||
* List of aliases attached to current validator | ||
*/ | ||
aliases: { [key: string]: ValidationRule }; | ||
/** | ||
* Constructor of validation class | ||
* @param {ValidatorConstructorOptions} opts List of possible validator constructor options | ||
*/ | ||
constructor(opts?: ValidatorConstructorOptions); | ||
/** | ||
* Constructor of validation class | ||
* @param {ValidatorConstructorOptions} opts List of possible validator constructor options | ||
*/ | ||
constructor(opts?: ValidatorConstructorOptions); | ||
/** | ||
* Register a custom validation rule in validation object | ||
* @param {string} type | ||
* @param fn | ||
*/ | ||
add(type: string, fn: CompilationFunction): void; | ||
/** | ||
* Register a custom validation rule in validation object | ||
* @param {string} type | ||
* @param fn | ||
*/ | ||
add(type: string, fn: CompilationFunction): void; | ||
/** | ||
* Add a message | ||
* | ||
* @param {String} name | ||
* @param {String} message | ||
*/ | ||
addMessage(name: string, message: string): void; | ||
/** | ||
* Add a message | ||
* | ||
* @param {String} name | ||
* @param {String} message | ||
*/ | ||
addMessage(name: string, message: string): void; | ||
/** | ||
* Register an alias in validation object | ||
* @param {string} name | ||
* @param {ValidationRuleObject} validationRule | ||
*/ | ||
alias(name: string, validationRule: ValidationRuleObject): void; | ||
/** | ||
* Register an alias in validation object | ||
* @param {string} name | ||
* @param {ValidationRuleObject} validationRule | ||
*/ | ||
alias(name: string, validationRule: ValidationRuleObject): void; | ||
/** | ||
* Add a plugin | ||
* | ||
* @param {Function} fn | ||
*/ | ||
plugin<T = void>(fn: PluginFn<T>): T; | ||
/** | ||
* Add a plugin | ||
* | ||
* @param {Function} fn | ||
*/ | ||
plugin<T = void>(fn: PluginFn<T>): T; | ||
/** | ||
* Build error message | ||
* @return {ValidationError} | ||
* @param {Object} opts | ||
* @param {String} opts.type | ||
* @param {String} opts.field | ||
* @param {any=} opts.expected | ||
* @param {any=} opts.actual | ||
* @param {MessagesType} opts.messages | ||
*/ | ||
makeError(opts: { | ||
type: keyof MessagesType; | ||
field?: string; | ||
expected?: any; | ||
actual?: any; | ||
messages: MessagesType; | ||
}): string; | ||
/** | ||
* Build error message | ||
* @return {ValidationError} | ||
* @param {Object} opts | ||
* @param {String} opts.type | ||
* @param {String} opts.field | ||
* @param {any=} opts.expected | ||
* @param {any=} opts.actual | ||
* @param {MessagesType} opts.messages | ||
*/ | ||
makeError(opts: { | ||
type: keyof MessagesType; | ||
field?: string; | ||
expected?: any; | ||
actual?: any; | ||
messages: MessagesType; | ||
}): string; | ||
/** | ||
* Compile validator functions that working up 100 times faster that native validation process | ||
* @param {ValidationSchema | ValidationSchema[]} schema Validation schema definition that should be used for validation | ||
* @return {(value: any) => (true | ValidationError[])} function that can be used next for validation of current schema | ||
*/ | ||
compile<T = any>( | ||
schema: ValidationSchema<T> | ValidationSchema<T>[] | ||
): SyncCheckFunction | AsyncCheckFunction; | ||
/** | ||
* Compile validator functions that working up 100 times faster that native validation process | ||
* @param {ValidationSchema | ValidationSchema[]} schema Validation schema definition that should be used for validation | ||
* @return {(value: any) => (true | ValidationError[])} function that can be used next for validation of current schema | ||
*/ | ||
compile<T = any>( | ||
schema: ValidationSchema<T> | ValidationSchema<T>[] | ||
): SyncCheckFunction | AsyncCheckFunction; | ||
/** | ||
* Native validation method to validate obj | ||
* @param {any} value that should be validated | ||
* @param {ValidationSchema} schema Validation schema definition that should be used for validation | ||
* @return {{true} | ValidationError[]} | ||
*/ | ||
validate( | ||
value: any, | ||
schema: ValidationSchema | ||
): true | ValidationError[] | Promise<true | ValidationError[]>; | ||
/** | ||
* Native validation method to validate obj | ||
* @param {any} value that should be validated | ||
* @param {ValidationSchema} schema Validation schema definition that should be used for validation | ||
* @return {{true} | ValidationError[]} | ||
*/ | ||
validate( | ||
value: any, | ||
schema: ValidationSchema | ||
): true | ValidationError[] | Promise<true | ValidationError[]>; | ||
/** | ||
* Get defined in validator rule | ||
* @param {ValidationRuleName | ValidationRuleName[]} name List or name of defined rule | ||
* @return {ValidationRule} | ||
*/ | ||
getRuleFromSchema( | ||
name: ValidationRuleName | ValidationRuleName[] | { [key: string]: unknown } | ||
): { | ||
messages: MessagesType; | ||
schema: ValidationSchema; | ||
ruleFunction: Function; | ||
}; | ||
} | ||
/** | ||
* Get defined in validator rule | ||
* @param {ValidationRuleName | ValidationRuleName[]} name List or name of defined rule | ||
* @return {ValidationRule} | ||
*/ | ||
getRuleFromSchema( | ||
name: ValidationRuleName | ValidationRuleName[] | { [key: string]: unknown } | ||
): { | ||
messages: MessagesType; | ||
schema: ValidationSchema; | ||
ruleFunction: Function; | ||
}; | ||
} |
@@ -29,2 +29,11 @@ (function (global, factory) { | ||
function convertible(value) { | ||
if (value === undefined) { return ""; } | ||
if (value === null) { return ""; } | ||
if (typeof value.toString === "function") { return value; } | ||
return typeof value; | ||
} | ||
var replace = function (string, searchValue, newValue) { return string.replace(searchValue, convertible(newValue)); }; | ||
var messages = { | ||
@@ -953,5 +962,5 @@ required: "The '{field}' field is required.", | ||
//const flatten = require("./helpers/flatten"); | ||
function loadMessages() { | ||
@@ -1020,2 +1029,12 @@ return Object.assign({} , messages); | ||
} | ||
/* istanbul ignore next */ | ||
if (this.opts.debug) { | ||
var formatter = function (code) { return code; }; | ||
if (typeof window === "undefined") { | ||
formatter = prettier_1; | ||
} | ||
this._formatter = formatter; | ||
} | ||
} | ||
@@ -1093,3 +1112,6 @@ }; | ||
fn: [], | ||
customs: {} | ||
customs: {}, | ||
utils: { | ||
replace: replace, | ||
}, | ||
}; | ||
@@ -1129,3 +1151,3 @@ this.cache.clear(); | ||
sourceCode.push("if (errors.length) {"); | ||
sourceCode.push("\n\t\t\treturn errors.map(err => {\n\t\t\t\tif (err.message)\n\t\t\t\t\terr.message = err.message\n\t\t\t\t\t\t.replace(/\\{field\\}/g, err.field || \"\")\n\t\t\t\t\t\t.replace(/\\{expected\\}/g, err.expected != null ? err.expected : \"\")\n\t\t\t\t\t\t.replace(/\\{actual\\}/g, err.actual != null ? err.actual : \"\");\n\n\t\t\t\treturn err;\n\t\t\t});\n\t\t"); | ||
sourceCode.push("\n\t\t\treturn errors.map(err => {\n\t\t\t\tif (err.message) {\n\t\t\t\t\terr.message = context.utils.replace(err.message, /\\{field\\}/g, err.field);\n\t\t\t\t\terr.message = context.utils.replace(err.message, /\\{expected\\}/g, err.expected);\n\t\t\t\t\terr.message = context.utils.replace(err.message, /\\{actual\\}/g, err.actual);\n\t\t\t\t}\n\n\t\t\t\treturn err;\n\t\t\t});\n\t\t"); | ||
@@ -1142,8 +1164,3 @@ sourceCode.push("}"); | ||
if (this.opts.debug) { | ||
var formatter = function (code) { return code; }; | ||
if (typeof window === "undefined") // eslint-disable-line no-undef | ||
{ formatter = prettier_1; } | ||
context.fn.forEach(function (fn, i) { return console.log(formatter("// Context.fn[" + i + "]\n" + fn.toString())); }); // eslint-disable-line no-console | ||
console.log(formatter("// Main check function\n" + checkFn.toString())); // eslint-disable-line no-console | ||
console.log(this._formatter("// Main check function\n" + checkFn.toString())); // eslint-disable-line no-console | ||
} | ||
@@ -1198,2 +1215,7 @@ | ||
sourceCode.push(this.makeCustomValidator({vName: resVar, path: customPath, schema: rule.schema, context: context, messages: rule.messages, ruleIndex: rule.index})); | ||
/* istanbul ignore next */ | ||
if (this.opts.debug) { | ||
console.log(this._formatter("// Context.fn[" + (rule.index) + "]\n" + fn.toString())); // eslint-disable-line no-console | ||
} | ||
} | ||
@@ -1200,0 +1222,0 @@ |
@@ -1,1 +0,1 @@ | ||
"use strict";function v(){function t(t){if(this.opts={},this.defaults={},this.messages=Object.assign({},N),this.rules={any:k,array:S,boolean:E,class:x,custom:b,currency:y,date:v,email:d,enum:g,equal:m,forbidden:h,function:f,multi:p,number:c,object:o,objectID:l,string:u,tuple:i,url:s,uuid:a,mac:r,luhn:n},this.aliases={},this.cache=new Map,t){if(O(this.opts,t),t.defaults&&O(this.defaults,t.defaults),t.messages)for(var e in t.messages)this.addMessage(e,t.messages[e]);if(t.aliases)for(var j in t.aliases)this.alias(j,t.aliases[j]);if(t.customRules)for(var w in t.customRules)this.add(w,t.customRules[w]);if(t.plugins){if(t=t.plugins,!Array.isArray(t))throw Error("Plugins type must be array");t.forEach(this.plugin.bind(this))}}}function e(t){return T||(T=w(),_={parser:"babel",useTabs:!1,printWidth:120,trailingComma:"none",tabWidth:4,singleQuote:!1,semi:!0,bracketSpacing:!0},A=w(),I={language:"js",theme:A.fromJson({keyword:["white","bold"],built_in:"magenta",literal:"cyan",number:"magenta",regexp:"red",string:["yellow","bold"],symbol:"plain",class:"blue",attr:"plain",function:["white","bold"],title:"plain",params:"green",comment:"grey"})}),t=T.format(t,_),A.highlight(t,I)}function n(t){return t=t.messages,{source:'\n\t\t\tif (typeof value !== "string") {\n\t\t\t\t'+this.makeError({type:"string",actual:"value",messages:t})+'\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tif (typeof value !== "string")\n\t\t\t\tvalue = String(value);\n\n\t\t\tval = value.replace(/\\D+/g, "");\n\n\t\t\tvar array = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9];\n\t\t\tvar len = val ? val.length : 0,\n\t\t\t\tbit = 1,\n\t\t\t\tsum = 0;\n\t\t\twhile (len--) {\n\t\t\t\tsum += !(bit ^= 1) ? parseInt(val[len], 10) : array[val[len]];\n\t\t\t}\n\n\t\t\tif (!(sum % 10 === 0 && sum > 0)) {\n\t\t\t\t'+this.makeError({type:"luhn",actual:"value",messages:t})+"\n\t\t\t}\n\n\t\t\treturn value;\n\t\t"}}function r(t){return t=t.messages,{source:'\n\t\t\tif (typeof value !== "string") {\n\t\t\t\t'+this.makeError({type:"string",actual:"value",messages:t})+"\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tvar v = value.toLowerCase();\n\t\t\tif (!"+Y.toString()+".test(v)) {\n\t\t\t\t"+this.makeError({type:"mac",actual:"value",messages:t})+"\n\t\t\t}\n\t\t\t\n\t\t\treturn value;\n\t\t"}}function a(t){var e=t.schema;t=t.messages;var n=[];return n.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+this.makeError({type:"string",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tvar val = value.toLowerCase();\n\t\tif (!"+z.toString()+".test(val)) {\n\t\t\t"+this.makeError({type:"uuid",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tconst version = val.charAt(14) | 0;\n\t"),7>parseInt(e.version)&&n.push("\n\t\t\tif ("+e.version+" !== version) {\n\t\t\t\t"+this.makeError({type:"uuidVersion",expected:e.version,actual:"version",messages:t})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t"),n.push('\n\t\tswitch (version) {\n\t\tcase 0:\n\t\tcase 1:\n\t\tcase 2:\n\t\tcase 6:\n\t\t\tbreak;\n\t\tcase 3:\n\t\tcase 4:\n\t\tcase 5:\n\t\t\tif (["8", "9", "a", "b"].indexOf(val.charAt(19)) === -1) {\n\t\t\t\t'+this.makeError({type:"uuid",actual:"value",messages:t})+"\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t"),{source:n.join("\n")}}function s(t){var e=t.schema;t=t.messages;var n=[];return n.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+this.makeError({type:"string",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\t"),e.empty?n.push("\n\t\t\tif (value.length === 0) return value;\n\t\t"):n.push("\n\t\t\tif (value.length === 0) {\n\t\t\t\t"+this.makeError({type:"urlEmpty",actual:"value",messages:t})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t"),n.push("\n\t\tif (!"+D.toString()+".test(value)) {\n\t\t\t"+this.makeError({type:"url",actual:"value",messages:t})+"\n\t\t}\n\n\t\treturn value;\n\t"),{source:n.join("\n")}}function i(t,e,n){var r=t.schema,a=t.messages;if(t=[],null!=r.items){if(!Array.isArray(r.items))throw Error("Invalid '"+r.type+"' schema. The 'items' field must be an array.");if(0===r.items.length)throw Error("Invalid '"+r.type+"' schema. The 'items' field must not be an empty array.")}if(t.push("\n\t\tif (!Array.isArray(value)) {\n\t\t\t"+this.makeError({type:"tuple",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tvar len = value.length;\n\t"),!1===r.empty&&t.push("\n\t\t\tif (len === 0) {\n\t\t\t\t"+this.makeError({type:"tupleEmpty",actual:"value",messages:a})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t"),null!=r.items){for(t.push("\n\t\t\tif ("+r.empty+" !== false && len === 0) {\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tif (len !== "+r.items.length+") {\n\t\t\t\t"+this.makeError({type:"tupleLength",expected:r.items.length,actual:"len",messages:a})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t"),t.push("\n\t\t\tvar arr = value;\n\t\t\tvar parentField = field;\n\t\t"),a=0;a<r.items.length;a++){t.push("\n\t\t\tvalue = arr["+a+"];\n\t\t");var s=e+"["+a+"]",i=this.getRuleFromSchema(r.items[a]);t.push(this.compileRule(i,n,s,"\n\t\t\tarr["+a+"] = "+(n.async?"await ":"")+"context.fn[%%INDEX%%](arr["+a+'], (parentField ? parentField : "") + "[" + '+a+' + "]", parent, errors, context);\n\t\t',"arr["+a+"]"))}t.push("\n\t\treturn arr;\n\t")}else t.push("\n\t\treturn value;\n\t");return{source:t.join("\n")}}function u(t){var e=t.schema;t=t.messages;var n=[],r=!1;if(!0===e.convert&&(r=!0,n.push('\n\t\t\tif (typeof value !== "string") {\n\t\t\t\tvalue = String(value);\n\t\t\t}\n\t\t')),n.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+this.makeError({type:"string",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tvar origValue = value;\n\t"),e.trim&&(r=!0,n.push("\n\t\t\tvalue = value.trim();\n\t\t")),e.trimLeft&&(r=!0,n.push("\n\t\t\tvalue = value.trimLeft();\n\t\t")),e.trimRight&&(r=!0,n.push("\n\t\t\tvalue = value.trimRight();\n\t\t")),e.padStart&&(r=!0,n.push("\n\t\t\tvalue = value.padStart("+e.padStart+", "+JSON.stringify(null!=e.padChar?e.padChar:" ")+");\n\t\t")),e.padEnd&&(r=!0,n.push("\n\t\t\tvalue = value.padEnd("+e.padEnd+", "+JSON.stringify(null!=e.padChar?e.padChar:" ")+");\n\t\t")),e.lowercase&&(r=!0,n.push("\n\t\t\tvalue = value.toLowerCase();\n\t\t")),e.uppercase&&(r=!0,n.push("\n\t\t\tvalue = value.toUpperCase();\n\t\t")),e.localeLowercase&&(r=!0,n.push("\n\t\t\tvalue = value.toLocaleLowerCase();\n\t\t")),e.localeUppercase&&(r=!0,n.push("\n\t\t\tvalue = value.toLocaleUpperCase();\n\t\t")),n.push("\n\t\t\tvar len = value.length;\n\t"),!1===e.empty&&n.push("\n\t\t\tif (len === 0) {\n\t\t\t\t"+this.makeError({type:"stringEmpty",actual:"value",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.min&&n.push("\n\t\t\tif (len < "+e.min+") {\n\t\t\t\t"+this.makeError({type:"stringMin",expected:e.min,actual:"len",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.max&&n.push("\n\t\t\tif (len > "+e.max+") {\n\t\t\t\t"+this.makeError({type:"stringMax",expected:e.max,actual:"len",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.length&&n.push("\n\t\t\tif (len !== "+e.length+") {\n\t\t\t\t"+this.makeError({type:"stringLength",expected:e.length,actual:"len",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.pattern){var a=e.pattern;"string"==typeof e.pattern&&(a=new RegExp(e.pattern,e.patternFlags)),a="\n\t\t\tif (!"+a.toString()+".test(value))\n\t\t\t\t"+this.makeError({type:"stringPattern",expected:'"'+a.toString().replace(/"/g,"\\$&")+'"',actual:"origValue",messages:t})+"\n\t\t",n.push("\n\t\t\tif ("+e.empty+" === true && len === 0) {\n\t\t\t\t// Do nothing\n\t\t\t} else {\n\t\t\t\t"+a+"\n\t\t\t}\n\t\t")}return null!=e.contains&&n.push('\n\t\t\tif (value.indexOf("'+e.contains+'") === -1) {\n\t\t\t\t'+this.makeError({type:"stringContains",expected:'"'+e.contains+'"',actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.enum&&(a=JSON.stringify(e.enum),n.push("\n\t\t\tif ("+a+".indexOf(value) === -1) {\n\t\t\t\t"+this.makeError({type:"stringEnum",expected:'"'+e.enum.join(", ")+'"',actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t")),!0===e.numeric&&n.push("\n\t\t\tif (!"+L.toString()+".test(value) ) {\n\t\t\t\t"+this.makeError({type:"stringNumeric",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.alpha&&n.push("\n\t\t\tif(!"+V.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringAlpha",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.alphanum&&n.push("\n\t\t\tif(!"+R.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringAlphanum",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.alphadash&&n.push("\n\t\t\tif(!"+$.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringAlphadash",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.hex&&n.push("\n\t\t\tif(value.length % 2 !== 0 || !"+q.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringHex",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.singleLine&&n.push('\n\t\t\tif(value.includes("\\n")) {\n\t\t\t\t'+this.makeError({type:"stringSingleLine",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.base64&&n.push("\n\t\t\tif(!"+U.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringBase64",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),n.push("\n\t\treturn value;\n\t"),{sanitized:r,source:n.join("\n")}}function l(t,e,n){e=t.schema;var r=t.messages;t=t.index;var a=[];return n.customs[t]?n.customs[t].schema=e:n.customs[t]={schema:e},a.push("\n\t\tconst ObjectID = context.customs["+t+"].schema.ObjectID;\n\t\tif (!ObjectID.isValid(value)) {\n\t\t\t"+this.makeError({type:"objectID",actual:"value",messages:r})+"\n\t\t\treturn;\n\t\t}\n\t"),!0===e.convert?a.push("return new ObjectID(value)"):"hexString"===e.convert?a.push("return value.toString()"):a.push("return value"),{source:a.join("\n")}}function o(t,e,n){var r=t.schema;t=t.messages;var a=[];a.push('\n\t\tif (typeof value !== "object" || value === null || Array.isArray(value)) {\n\t\t\t'+this.makeError({type:"object",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\t");var s=r.properties||r.props;if(s){a.push("var parentObj = value;"),a.push("var parentField = field;");for(var i=Object.keys(s),u=0;u<i.length;u++){var l=i[u],o=j(l),c=P.test(o)?"."+o:"['"+o+"']",p="parentObj"+c,f=(e?e+".":"")+l;a.push("\n// Field: "+j(f)),a.push('field = parentField ? parentField + "'+c+'" : "'+o+'";'),a.push("value = "+p+";"),l=this.getRuleFromSchema(s[l]),a.push(this.compileRule(l,n,f,"\n\t\t\t\t"+p+" = "+(n.async?"await ":"")+"context.fn[%%INDEX%%](value, field, parentObj, errors, context);\n\t\t\t",p))}r.strict&&(e=Object.keys(s),a.push("\n\t\t\t\tfield = parentField;\n\t\t\t\tvar invalidProps = [];\n\t\t\t\tvar props = Object.keys(parentObj);\n\n\t\t\t\tfor (let i = 0; i < props.length; i++) {\n\t\t\t\t\tif ("+JSON.stringify(e)+".indexOf(props[i]) === -1) {\n\t\t\t\t\t\tinvalidProps.push(props[i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (invalidProps.length) {\n\t\t\t"),"remove"==r.strict?a.push("\n\t\t\t\t\tinvalidProps.forEach(function(field) {\n\t\t\t\t\t\tdelete parentObj[field];\n\t\t\t\t\t});\n\t\t\t\t"):a.push("\n\t\t\t\t\t"+this.makeError({type:"objectStrict",expected:'"'+e.join(", ")+'"',actual:"invalidProps.join(', ')",messages:t})+"\n\t\t\t\t"),a.push("\n\t\t\t\t}\n\t\t\t"))}return null==r.minProps&&null==r.maxProps||(r.strict?a.push("\n\t\t\t\tprops = Object.keys("+(s?"parentObj":"value")+");\n\t\t\t"):a.push("\n\t\t\t\tvar props = Object.keys("+(s?"parentObj":"value")+");\n\t\t\t\t"+(s?"field = parentField;":"")+"\n\t\t\t")),null!=r.minProps&&a.push("\n\t\t\tif (props.length < "+r.minProps+") {\n\t\t\t\t"+this.makeError({type:"objectMinProps",expected:r.minProps,actual:"props.length",messages:t})+"\n\t\t\t}\n\t\t"),null!=r.maxProps&&a.push("\n\t\t\tif (props.length > "+r.maxProps+") {\n\t\t\t\t"+this.makeError({type:"objectMaxProps",expected:r.maxProps,actual:"props.length",messages:t})+"\n\t\t\t}\n\t\t"),s?a.push("\n\t\t\treturn parentObj;\n\t\t"):a.push("\n\t\t\treturn value;\n\t\t"),{source:a.join("\n")}}function c(t){var e=t.schema;t=t.messages;var n=[];n.push("\n\t\tvar origValue = value;\n\t");var r=!1;return!0===e.convert&&(r=!0,n.push('\n\t\t\tif (typeof value !== "number") {\n\t\t\t\tvalue = Number(value);\n\t\t\t}\n\t\t')),n.push('\n\t\tif (typeof value !== "number" || isNaN(value) || !isFinite(value)) {\n\t\t\t'+this.makeError({type:"number",actual:"origValue",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\t"),null!=e.min&&n.push("\n\t\t\tif (value < "+e.min+") {\n\t\t\t\t"+this.makeError({type:"numberMin",expected:e.min,actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.max&&n.push("\n\t\t\tif (value > "+e.max+") {\n\t\t\t\t"+this.makeError({type:"numberMax",expected:e.max,actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.equal&&n.push("\n\t\t\tif (value !== "+e.equal+") {\n\t\t\t\t"+this.makeError({type:"numberEqual",expected:e.equal,actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.notEqual&&n.push("\n\t\t\tif (value === "+e.notEqual+") {\n\t\t\t\t"+this.makeError({type:"numberNotEqual",expected:e.notEqual,actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.integer&&n.push("\n\t\t\tif (value % 1 !== 0) {\n\t\t\t\t"+this.makeError({type:"numberInteger",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.positive&&n.push("\n\t\t\tif (value <= 0) {\n\t\t\t\t"+this.makeError({type:"numberPositive",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.negative&&n.push("\n\t\t\tif (value >= 0) {\n\t\t\t\t"+this.makeError({type:"numberNegative",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),n.push("\n\t\treturn value;\n\t"),{sanitized:r,source:n.join("\n")}}function p(t,e,n){t=t.schema;var r=[];r.push("\n\t\tvar prevErrLen = errors.length;\n\t\tvar errBefore;\n\t\tvar hasValid = false;\n\t\tvar newVal = value;\n\t");for(var a=0;a<t.rules.length;a++){r.push("\n\t\t\tif (!hasValid) {\n\t\t\t\terrBefore = errors.length;\n\t\t");var s=this.getRuleFromSchema(t.rules[a]);r.push(this.compileRule(s,n,e,"var tmpVal = "+(n.async?"await ":"")+"context.fn[%%INDEX%%](value, field, parent, errors, context);","tmpVal")),r.push("\n\t\t\t\tif (errors.length == errBefore) {\n\t\t\t\t\thasValid = true;\n\t\t\t\t\tnewVal = tmpVal;\n\t\t\t\t}\n\t\t\t}\n\t\t")}return r.push("\n\t\tif (hasValid) {\n\t\t\terrors.length = prevErrLen;\n\t\t}\n\n\t\treturn newVal;\n\t"),{source:r.join("\n")}}function f(t){return{source:'\n\t\t\tif (typeof value !== "function")\n\t\t\t\t'+this.makeError({type:"function",actual:"value",messages:t.messages})+"\n\n\t\t\treturn value;\n\t\t"}}function h(t){var e=t.schema;t=t.messages;var n=[];return n.push("\n\t\tif (value !== null && value !== undefined) {\n\t"),e.remove?n.push("\n\t\t\treturn undefined;\n\t\t"):n.push("\n\t\t\t"+this.makeError({type:"forbidden",actual:"value",messages:t})+"\n\t\t"),n.push("\n\t\t}\n\n\t\treturn value;\n\t"),{source:n.join("\n")}}function m(t){var e=t.schema;t=t.messages;var n=[];return e.field?(e.strict?n.push('\n\t\t\t\tif (value !== parent["'+e.field+'"])\n\t\t\t'):n.push('\n\t\t\t\tif (value != parent["'+e.field+'"])\n\t\t\t'),n.push("\n\t\t\t\t"+this.makeError({type:"equalField",actual:"value",expected:JSON.stringify(e.field),messages:t})+"\n\t\t")):(e.strict?n.push("\n\t\t\t\tif (value !== "+JSON.stringify(e.value)+")\n\t\t\t"):n.push("\n\t\t\t\tif (value != "+JSON.stringify(e.value)+")\n\t\t\t"),n.push("\n\t\t\t\t"+this.makeError({type:"equalValue",actual:"value",expected:JSON.stringify(e.value),messages:t})+"\n\t\t")),n.push("\n\t\treturn value;\n\t"),{source:n.join("\n")}}function g(t){var e=t.schema;return t=t.messages,{source:"\n\t\t\tif ("+JSON.stringify(e.values||[])+".indexOf(value) === -1)\n\t\t\t\t"+this.makeError({type:"enumValue",expected:'"'+e.values.join(", ")+'"',actual:"value",messages:t})+"\n\t\t\t\n\t\t\treturn value;\n\t\t"}}function d(t){var e=t.schema;t=t.messages;var n=[],r="precise"==e.mode?F:M,a=!1;return n.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+this.makeError({type:"string",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\t"),e.empty?n.push("\n\t\t\tif (value.length === 0) return value;\n\t\t"):n.push("\n\t\t\tif (value.length === 0) {\n\t\t\t\t"+this.makeError({type:"emailEmpty",actual:"value",messages:t})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t"),e.normalize&&(a=!0,n.push("\n\t\t\tvalue = value.trim().toLowerCase();\n\t\t")),null!=e.min&&n.push("\n\t\t\tif (value.length < "+e.min+") {\n\t\t\t\t"+this.makeError({type:"emailMin",expected:e.min,actual:"value.length",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.max&&n.push("\n\t\t\tif (value.length > "+e.max+") {\n\t\t\t\t"+this.makeError({type:"emailMax",expected:e.max,actual:"value.length",messages:t})+"\n\t\t\t}\n\t\t"),n.push("\n\t\tif (!"+r.toString()+".test(value)) {\n\t\t\t"+this.makeError({type:"email",actual:"value",messages:t})+"\n\t\t}\n\n\t\treturn value;\n\t"),{sanitized:a,source:n.join("\n")}}function v(t){var e=t.schema;t=t.messages;var n=[],r=!1;return n.push("\n\t\tvar origValue = value;\n\t"),!0===e.convert&&(r=!0,n.push("\n\t\t\tif (!(value instanceof Date)) {\n\t\t\t\tvalue = new Date(value);\n\t\t\t}\n\t\t")),n.push("\n\t\tif (!(value instanceof Date) || isNaN(value.getTime()))\n\t\t\t"+this.makeError({type:"date",actual:"origValue",messages:t})+"\n\n\t\treturn value;\n\t"),{sanitized:r,source:n.join("\n")}}function y(t){var e=t.schema;t=t.messages;var n=e.currencySymbol||null,r=e.thousandSeparator||",",a=e.decimalSeparator||".",s=e.customRegex;return e=!e.symbolOptional,e="(?=.*\\d)^(-?~1|~1-?)(([0-9]\\d{0,2}(~2\\d{3})*)|0)?(\\~3\\d{1,2})?$".replace(/~1/g,n?"\\"+n+(e?"":"?"):"").replace("~2",r).replace("~3",a),(n=[]).push("\n\t\tif (!value.match("+(s||new RegExp(e))+")) {\n\t\t\t"+this.makeError({type:"currency",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\n\t\treturn value;\n\t"),{source:n.join("\n")}}function b(t,e,n){var r=[];return r.push("\n\t\t"+this.makeCustomValidator({fnName:"check",path:e,schema:t.schema,messages:t.messages,context:n,ruleIndex:t.index})+"\n\t\treturn value;\n\t"),{source:r.join("\n")}}function x(t,e,n){e=t.schema;var r=t.messages;t=t.index;var a=[],s=e.instanceOf.name?e.instanceOf.name:"<UnknowClass>";return n.customs[t]?n.customs[t].schema=e:n.customs[t]={schema:e},a.push("\n\t\tif (!(value instanceof context.customs["+t+"].schema.instanceOf))\n\t\t\t"+this.makeError({type:"classInstanceOf",actual:"value",expected:"'"+s+"'",messages:r})+"\n\t"),a.push("\n\t\treturn value;\n\t"),{source:a.join("\n")}}function E(t){var e=t.schema;t=t.messages;var n=[],r=!1;return n.push("\n\t\tvar origValue = value;\n\t"),!0===e.convert&&(r=!0,n.push('\n\t\t\tif (typeof value !== "boolean") {\n\t\t\t\tif (\n\t\t\t\tvalue === 1\n\t\t\t\t|| value === "true"\n\t\t\t\t|| value === "1"\n\t\t\t\t|| value === "on"\n\t\t\t\t) {\n\t\t\t\t\tvalue = true;\n\t\t\t\t} else if (\n\t\t\t\tvalue === 0\n\t\t\t\t|| value === "false"\n\t\t\t\t|| value === "0"\n\t\t\t\t|| value === "off"\n\t\t\t\t) {\n\t\t\t\t\tvalue = false;\n\t\t\t\t}\n\t\t\t}\n\t\t')),n.push('\n\t\tif (typeof value !== "boolean") {\n\t\t\t'+this.makeError({type:"boolean",actual:"origValue",messages:t})+"\n\t\t}\n\t\t\n\t\treturn value;\n\t"),{sanitized:r,source:n.join("\n")}}function S(t,e,n){var r=t.schema,a=t.messages;if((t=[]).push("\n\t\tif (!Array.isArray(value)) {\n\t\t\t"+this.makeError({type:"array",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tvar len = value.length;\n\t"),!1===r.empty&&t.push("\n\t\t\tif (len === 0) {\n\t\t\t\t"+this.makeError({type:"arrayEmpty",actual:"value",messages:a})+"\n\t\t\t}\n\t\t"),null!=r.min&&t.push("\n\t\t\tif (len < "+r.min+") {\n\t\t\t\t"+this.makeError({type:"arrayMin",expected:r.min,actual:"len",messages:a})+"\n\t\t\t}\n\t\t"),null!=r.max&&t.push("\n\t\t\tif (len > "+r.max+") {\n\t\t\t\t"+this.makeError({type:"arrayMax",expected:r.max,actual:"len",messages:a})+"\n\t\t\t}\n\t\t"),null!=r.length&&t.push("\n\t\t\tif (len !== "+r.length+") {\n\t\t\t\t"+this.makeError({type:"arrayLength",expected:r.length,actual:"len",messages:a})+"\n\t\t\t}\n\t\t"),null!=r.contains&&t.push("\n\t\t\tif (value.indexOf("+JSON.stringify(r.contains)+") === -1) {\n\t\t\t\t"+this.makeError({type:"arrayContains",expected:JSON.stringify(r.contains),actual:"value",messages:a})+"\n\t\t\t}\n\t\t"),!0===r.unique&&t.push("\n\t\t\tif(len > (new Set(value)).size) {\n\t\t\t\t"+this.makeError({type:"arrayUnique",expected:"Array.from(new Set(value.filter((item, index) => value.indexOf(item) !== index)))",actual:"value",messages:a})+"\n\t\t\t}\n\t\t"),null!=r.enum){var s=JSON.stringify(r.enum);t.push("\n\t\t\tfor (var i = 0; i < value.length; i++) {\n\t\t\t\tif ("+s+".indexOf(value[i]) === -1) {\n\t\t\t\t\t"+this.makeError({type:"arrayEnum",expected:'"'+r.enum.join(", ")+'"',actual:"value[i]",messages:a})+"\n\t\t\t\t}\n\t\t\t}\n\t\t")}return null!=r.items?(t.push("\n\t\t\tvar arr = value;\n\t\t\tvar parentField = field;\n\t\t\tfor (var i = 0; i < arr.length; i++) {\n\t\t\t\tvalue = arr[i];\n\t\t"),e+="[]",r=this.getRuleFromSchema(r.items),t.push(this.compileRule(r,n,e,"arr[i] = "+(n.async?"await ":"")+'context.fn[%%INDEX%%](arr[i], (parentField ? parentField : "") + "[" + i + "]", parent, errors, context)',"arr[i]")),t.push("\n\t\t\t}\n\t\t"),t.push("\n\t\treturn arr;\n\t")):t.push("\n\t\treturn value;\n\t"),{source:t.join("\n")}}function k(){var t=[];return t.push("\n\t\treturn value;\n\t"),{source:t.join("\n")}}function O(t,e,n){void 0===n&&(n={});for(var r in e){var a=e[r];(a="object"==typeof a&&!Array.isArray(a)&&null!=a&&0<Object.keys(a).length)?(t[r]=t[r]||{},O(t[r],e[r],n)):!0===n.skipIfExist&&void 0!==t[r]||(t[r]=e[r])}return t}function j(t){return t.replace(C,function(t){switch(t){case'"':case"'":case"\\":return"\\"+t;case"\n":return"\\n";case"\r":return"\\r";case"\u2028":return"\\u2028";case"\u2029":return"\\u2029"}})}function w(){throw Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}var T,_,A,I,N={required:"The '{field}' field is required.",string:"The '{field}' field must be a string.",stringEmpty:"The '{field}' field must not be empty.",stringMin:"The '{field}' field length must be greater than or equal to {expected} characters long.",stringMax:"The '{field}' field length must be less than or equal to {expected} characters long.",stringLength:"The '{field}' field length must be {expected} characters long.",stringPattern:"The '{field}' field fails to match the required pattern.",stringContains:"The '{field}' field must contain the '{expected}' text.",stringEnum:"The '{field}' field does not match any of the allowed values.",stringNumeric:"The '{field}' field must be a numeric string.",stringAlpha:"The '{field}' field must be an alphabetic string.",stringAlphanum:"The '{field}' field must be an alphanumeric string.",stringAlphadash:"The '{field}' field must be an alphadash string.",stringHex:"The '{field}' field must be a hex string.",stringSingleLine:"The '{field}' field must be a single line string.",stringBase64:"The '{field}' field must be a base64 string.",number:"The '{field}' field must be a number.",numberMin:"The '{field}' field must be greater than or equal to {expected}.",numberMax:"The '{field}' field must be less than or equal to {expected}.",numberEqual:"The '{field}' field must be equal to {expected}.",numberNotEqual:"The '{field}' field can't be equal to {expected}.",numberInteger:"The '{field}' field must be an integer.",numberPositive:"The '{field}' field must be a positive number.",numberNegative:"The '{field}' field must be a negative number.",array:"The '{field}' field must be an array.",arrayEmpty:"The '{field}' field must not be an empty array.",arrayMin:"The '{field}' field must contain at least {expected} items.",arrayMax:"The '{field}' field must contain less than or equal to {expected} items.",arrayLength:"The '{field}' field must contain {expected} items.",arrayContains:"The '{field}' field must contain the '{expected}' item.",arrayUnique:"The '{actual}' value in '{field}' field does not unique the '{expected}' values.",arrayEnum:"The '{actual}' value in '{field}' field does not match any of the '{expected}' values.",tuple:"The '{field}' field must be an array.",tupleEmpty:"The '{field}' field must not be an empty array.",tupleLength:"The '{field}' field must contain {expected} items.",boolean:"The '{field}' field must be a boolean.",currency:"The '{field}' must be a valid currency format",date:"The '{field}' field must be a Date.",dateMin:"The '{field}' field must be greater than or equal to {expected}.",dateMax:"The '{field}' field must be less than or equal to {expected}.",enumValue:"The '{field}' field value '{expected}' does not match any of the allowed values.",equalValue:"The '{field}' field value must be equal to '{expected}'.",equalField:"The '{field}' field value must be equal to '{expected}' field value.",forbidden:"The '{field}' field is forbidden.",function:"The '{field}' field must be a function.",email:"The '{field}' field must be a valid e-mail.",emailEmpty:"The '{field}' field must not be empty.",emailMin:"The '{field}' field length must be greater than or equal to {expected} characters long.",emailMax:"The '{field}' field length must be less than or equal to {expected} characters long.",luhn:"The '{field}' field must be a valid checksum luhn.",mac:"The '{field}' field must be a valid MAC address.",object:"The '{field}' must be an Object.",objectStrict:"The object '{field}' contains forbidden keys: '{actual}'.",objectMinProps:"The object '{field}' must contain at least {expected} properties.",objectMaxProps:"The object '{field}' must contain {expected} properties at most.",url:"The '{field}' field must be a valid URL.",urlEmpty:"The '{field}' field must not be empty.",uuid:"The '{field}' field must be a valid UUID.",uuidVersion:"The '{field}' field must be a valid UUID version provided.",classInstanceOf:"The '{field}' field must be an instance of the '{expected}' class.",objectID:"The '{field}' field must be an valid ObjectID"},F=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,M=/^\S+@\S+\.\S+$/,P=/^[_$a-zA-Z][_$a-zA-Z0-9]*$/,C=/["'\\\n\r\u2028\u2029]/g,L=/^-?[0-9]\d*(\.\d+)?$/,V=/^[a-zA-Z]+$/,R=/^[a-zA-Z0-9]+$/,$=/^[a-zA-Z0-9_-]+$/,q=/^[0-9a-fA-F]+$/,U=/^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+/]{3}=)?$/,D=/^https?:\/\/\S+/,z=/^([0-9a-f]{8}-[0-9a-f]{4}-[1-6][0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}|[0]{8}-[0]{4}-[0]{4}-[0]{4}-[0]{12})$/i,Y=/^((([a-f0-9][a-f0-9]+[-]){5}|([a-f0-9][a-f0-9]+[:]){5})([a-f0-9][a-f0-9])$)|(^([a-f0-9][a-f0-9][a-f0-9][a-f0-9]+[.]){2}([a-f0-9][a-f0-9][a-f0-9][a-f0-9]))$/i;try{var J=new Function("return Object.getPrototypeOf(async function(){}).constructor")()}catch(t){}return t.prototype.validate=function(t,e){return this.compile(e)(t)},t.prototype.wrapRequiredCheckSourceCode=function(t,e,n,r){var a=[],s=!0===t.schema.optional||"forbidden"===t.schema.type,i=!0===t.schema.optional||!0===t.schema.nullable||"forbidden"===t.schema.type;return null!=t.schema.default?(s=!1,!0!==t.schema.nullable&&(i=!1),"function"==typeof t.schema.default?(n.customs[t.index]||(n.customs[t.index]={}),n.customs[t.index].defaultFn=t.schema.default,t="context.customs["+t.index+"].defaultFn()"):t=JSON.stringify(t.schema.default),r="\n\t\t\t\tvalue = "+t+";\n\t\t\t\t"+r+" = value;\n\t\t\t"):r=this.makeError({type:"required",actual:"value",messages:t.messages}),a.push("\n\t\t\tif (value === undefined) { "+(s?"\n// allow undefined\n":r)+" }\n\t\t\telse if (value === null) { "+(i?"\n// allow null\n":r)+" }\n\t\t\t"+(e?"else { "+e+" }":"")+"\n\t\t"),a.join("\n")},t.prototype.compile=function(t){function n(t,e){return a.data=t,e&&e.meta&&(a.meta=e.meta),i.call(r,t,a)}if(null===t||"object"!=typeof t)throw Error("Invalid schema.");var r=this,a={index:0,async:!0===t.$$async,rules:[],fn:[],customs:{}};if(this.cache.clear(),delete t.$$async,a.async&&!J)throw Error("Asynchronous mode is not supported.");if(!0!==t.$$root)if(Array.isArray(t))t=this.getRuleFromSchema(t).schema;else{var s=Object.assign({},t);t={type:"object",strict:s.$$strict,properties:s},delete s.$$strict}s=["var errors = [];","var field;","var parent = null;"],t=this.getRuleFromSchema(t),s.push(this.compileRule(t,a,null,(a.async?"await ":"")+"context.fn[%%INDEX%%](value, field, null, errors, context);","value")),s.push("if (errors.length) {"),s.push('\n\t\t\treturn errors.map(err => {\n\t\t\t\tif (err.message)\n\t\t\t\t\terr.message = err.message\n\t\t\t\t\t\t.replace(/\\{field\\}/g, err.field || "")\n\t\t\t\t\t\t.replace(/\\{expected\\}/g, err.expected != null ? err.expected : "")\n\t\t\t\t\t\t.replace(/\\{actual\\}/g, err.actual != null ? err.actual : "");\n\n\t\t\t\treturn err;\n\t\t\t});\n\t\t'),s.push("}"),s.push("return true;"),t=s.join("\n");var i=new(a.async?J:Function)("value","context",t);if(this.opts.debug){var u=function(t){return t};"undefined"==typeof window&&(u=e),a.fn.forEach(function(t,e){return console.log(u("// Context.fn["+e+"]\n"+t.toString()))}),console.log(u("// Main check function\n"+i.toString()))}return this.cache.clear(),n.async=a.async,n},t.prototype.compileRule=function(t,e,n,r,a){var s=[],i=this.cache.get(t.schema);return i?(t=i,t.cycle=!0,t.cycleStack=[],s.push(this.wrapRequiredCheckSourceCode(t,"\n\t\t\t\tvar rule = context.rules["+t.index+"];\n\t\t\t\tif (rule.cycleStack.indexOf(value) === -1) {\n\t\t\t\t\trule.cycleStack.push(value);\n\t\t\t\t\t"+r.replace(/%%INDEX%%/g,t.index)+"\n\t\t\t\t\trule.cycleStack.pop(value);\n\t\t\t\t}\n\t\t\t",e,a))):(this.cache.set(t.schema,t),t.index=e.index,e.rules[e.index]=t,i=null!=n?n:"$$root",e.index++,n=t.ruleFunction.call(this,t,n,e),n.source=n.source.replace(/%%INDEX%%/g,t.index),n=new(e.async?J:Function)("value","field","parent","errors","context",n.source),e.fn[t.index]=n.bind(this),s.push(this.wrapRequiredCheckSourceCode(t,r.replace(/%%INDEX%%/g,t.index),e,a)),s.push(this.makeCustomValidator({vName:a,path:i,schema:t.schema,context:e,messages:t.messages,ruleIndex:t.index}))),s.join("\n")},t.prototype.getRuleFromSchema=function(t){var e=this;if("string"==typeof t)t=this.parseShortHand(t);else if(Array.isArray(t)){if(0==t.length)throw Error("Invalid schema.");(t={type:"multi",rules:t}).rules.map(function(t){return e.getRuleFromSchema(t)}).every(function(t){return 1==t.schema.optional})&&(t.optional=!0)}if(t.$$type){var n=this.getRuleFromSchema(t.$$type).schema;delete t.$$type;var r,a=Object.assign({},t);for(r in t)delete t[r];O(t,n,{skipIfExist:!0}),t.props=a}if((n=this.aliases[t.type])&&(delete t.type,t=O(t,n,{skipIfExist:!0})),!(n=this.rules[t.type]))throw Error("Invalid '"+t.type+"' type in validator schema.");return{messages:Object.assign({},this.messages,t.messages),schema:O(t,this.defaults[t.type],{skipIfExist:!0}),ruleFunction:n}},t.prototype.parseShortHand=function(t){var e=(t=t.split("|").map(function(t){return t.trim()}))[0],n=e.endsWith("[]")?this.getRuleFromSchema({type:"array",items:e.slice(0,-2)}).schema:{type:t[0]};return t.slice(1).map(function(t){var e=t.indexOf(":");if(-1!==e){var r=t.substr(0,e).trim();"true"===(t=t.substr(e+1).trim())||"false"===t?t="true"===t:Number.isNaN(Number(t))||(t=Number(t)),n[r]=t}else t.startsWith("no-")?n[t.slice(3)]=!1:n[t]=!0}),n},t.prototype.makeError=function(t){var e=t.type,n=t.field,r=t.expected,a=t.actual,s={type:'"'+e+'"',message:'"'+t.messages[e]+'"'};return s.field=n?'"'+n+'"':"field",null!=r&&(s.expected=r),null!=a&&(s.actual=a),"errors.push({ "+Object.keys(s).map(function(t){return t+": "+s[t]}).join(", ")+" });"},t.prototype.makeCustomValidator=function(t){var e=t.vName;void 0===e&&(e="value");var n=t.fnName;void 0===n&&(n="custom");var r=t.ruleIndex,a=t.path,s=t.schema,i=t.context,u=t.messages;t="rule"+r;var l="fnCustomErrors"+r;return"function"==typeof s[n]?(i.customs[r]?(i.customs[r].messages=u,i.customs[r].schema=s):i.customs[r]={messages:u,schema:s},this.opts.useNewCustomCheckerFunction?"\n \t\tconst "+t+" = context.customs["+r+"];\n\t\t\t\t\tconst "+l+" = [];\n\t\t\t\t\t"+e+" = "+(i.async?"await ":"")+t+".schema."+n+".call(this, "+e+", "+l+" , "+t+'.schema, "'+a+'", parent, context);\n\t\t\t\t\tif (Array.isArray('+l+" )) {\n \t\t"+l+" .forEach(err => errors.push(Object.assign({ message: "+t+".messages[err.type], field }, err)));\n\t\t\t\t\t}\n\t\t\t\t":(s="res_"+t,"\n\t\t\t\tconst "+t+" = context.customs["+r+"];\n\t\t\t\tconst "+s+" = "+(i.async?"await ":"")+t+".schema."+n+".call(this, "+e+", "+t+'.schema, "'+a+'", parent, context);\n\t\t\t\tif (Array.isArray('+s+")) {\n\t\t\t\t\t"+s+".forEach(err => errors.push(Object.assign({ message: "+t+".messages[err.type], field }, err)));\n\t\t\t\t}\n\t\t")):""},t.prototype.add=function(t,e){this.rules[t]=e},t.prototype.addMessage=function(t,e){this.messages[t]=e},t.prototype.alias=function(t,e){if(this.rules[t])throw Error("Alias name must not be a rule name");this.aliases[t]=e},t.prototype.plugin=function(t){if("function"!=typeof t)throw Error("Plugin fn type must be function");return t(this)},t}var g=g||{};g.scope={},g.arrayIteratorImpl=function(t){var e=0;return function(){return e<t.length?{done:!1,value:t[e++]}:{done:!0}}},g.arrayIterator=function(t){return{next:g.arrayIteratorImpl(t)}},g.ASSUME_ES5=!1,g.ASSUME_NO_NATIVE_MAP=!1,g.ASSUME_NO_NATIVE_SET=!1,g.SIMPLE_FROUND_POLYFILL=!1,g.ISOLATE_POLYFILLS=!1,g.defineProperty=g.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(t,e,n){return t==Array.prototype||t==Object.prototype?t:(t[e]=n.value,t)},g.getGlobal=function(t){t=["object"==typeof globalThis&&globalThis,t,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var e=0;e<t.length;++e){var n=t[e];if(n&&n.Math==Math)return n}throw Error("Cannot find global object")},g.global=g.getGlobal(this),g.IS_SYMBOL_NATIVE="function"==typeof Symbol&&"symbol"==typeof Symbol("x"),g.TRUST_ES6_POLYFILLS=!g.ISOLATE_POLYFILLS||g.IS_SYMBOL_NATIVE,g.polyfills={},g.propertyToPolyfillSymbol={},g.POLYFILL_PREFIX="$jscp$",g.polyfill=function(t,e,n,r){e&&(g.ISOLATE_POLYFILLS?g.polyfillIsolated(t,e,n,r):g.polyfillUnisolated(t,e,n,r))},g.polyfillUnisolated=function(t,e){var n=g.global;t=t.split(".");for(var r=0;r<t.length-1;r++){var a=t[r];a in n||(n[a]={}),n=n[a]}(e=e(r=n[t=t[t.length-1]]))!=r&&null!=e&&g.defineProperty(n,t,{configurable:!0,writable:!0,value:e})},g.polyfillIsolated=function(t,e,n){var r=t.split(".");t=1===r.length;var a=r[0];a=!t&&a in g.polyfills?g.polyfills:g.global;for(var s=0;s<r.length-1;s++){var i=r[s];i in a||(a[i]={}),a=a[i]}r=r[r.length-1],null!=(e=e(n=g.IS_SYMBOL_NATIVE&&"es6"===n?a[r]:null))&&(t?g.defineProperty(g.polyfills,r,{configurable:!0,writable:!0,value:e}):e!==n&&(g.propertyToPolyfillSymbol[r]=g.IS_SYMBOL_NATIVE?g.global.Symbol(r):g.POLYFILL_PREFIX+r,r=g.propertyToPolyfillSymbol[r],g.defineProperty(a,r,{configurable:!0,writable:!0,value:e})))},g.initSymbol=function(){},g.polyfill("Symbol",function(t){function e(t){if(this instanceof e)throw new TypeError("Symbol is not a constructor");return new n("jscomp_symbol_"+(t||"")+"_"+r++,t)}function n(t,e){this.$jscomp$symbol$id_=t,g.defineProperty(this,"description",{configurable:!0,writable:!0,value:e})}if(t)return t;n.prototype.toString=function(){return this.$jscomp$symbol$id_};var r=0;return e},"es6","es3"),g.initSymbolIterator=function(){},g.polyfill("Symbol.iterator",function(t){if(t)return t;t=Symbol("Symbol.iterator");for(var e="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),n=0;n<e.length;n++){var r=g.global[e[n]];"function"==typeof r&&"function"!=typeof r.prototype[t]&&g.defineProperty(r.prototype,t,{configurable:!0,writable:!0,value:function(){return g.iteratorPrototype(g.arrayIteratorImpl(this))}})}return t},"es6","es3"),g.initSymbolAsyncIterator=function(){},g.iteratorPrototype=function(t){return t={next:t},t[Symbol.iterator]=function(){return this},t},g.iteratorFromArray=function(t,e){t instanceof String&&(t+="");var n=0,r={next:function(){if(n<t.length){var a=n++;return{value:e(a,t[a]),done:!1}}return r.next=function(){return{done:!0,value:void 0}},r.next()}};return r[Symbol.iterator]=function(){return r},r},g.polyfill("Array.prototype.keys",function(t){return t||function(){return g.iteratorFromArray(this,function(t){return t})}},"es6","es3"),g.polyfill("Array.prototype.values",function(t){return t||function(){return g.iteratorFromArray(this,function(t,e){return e})}},"es8","es3"),g.owns=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},g.assign=g.TRUST_ES6_POLYFILLS&&"function"==typeof Object.assign?Object.assign:function(t,e){for(var n=1;n<arguments.length;n++){var r=arguments[n];if(r)for(var a in r)g.owns(r,a)&&(t[a]=r[a])}return t},g.polyfill("Object.assign",function(t){return t||g.assign},"es6","es3"),g.checkEs6ConformanceViaProxy=function(){try{var t={},e=Object.create(new g.global.Proxy(t,{get:function(n,r,a){return n==t&&"q"==r&&a==e}}));return!0===e.q}catch(t){return!1}},g.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS=!1,g.ES6_CONFORMANCE=g.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS&&g.checkEs6ConformanceViaProxy(),g.makeIterator=function(t){var e="undefined"!=typeof Symbol&&Symbol.iterator&&t[Symbol.iterator];return e?e.call(t):g.arrayIterator(t)},g.polyfill("WeakMap",function(t){function e(t){if(this.id_=(u+=Math.random()+1).toString(),t){t=g.makeIterator(t);for(var e;!(e=t.next()).done;)e=e.value,this.set(e[0],e[1])}}function n(){}function r(t){var e=typeof t;return"object"===e&&null!==t||"function"===e}function a(t){if(!g.owns(t,i)){var e=new n;g.defineProperty(t,i,{value:e})}}function s(t){var e=Object[t];e&&(Object[t]=function(t){return t instanceof n?t:(a(t),e(t))})}if(g.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS){if(t&&g.ES6_CONFORMANCE)return t}else if(function(){if(!t||!Object.seal)return!1;try{var e=Object.seal({}),n=Object.seal({}),r=new t([[e,2],[n,3]]);return 2==r.get(e)&&3==r.get(n)&&(r.delete(e),r.set(n,4),!r.has(e)&&4==r.get(n))}catch(t){return!1}}())return t;var i="$jscomp_hidden_"+Math.random();s("freeze"),s("preventExtensions"),s("seal");var u=0;return e.prototype.set=function(t,e){if(!r(t))throw Error("Invalid WeakMap key");if(a(t),!g.owns(t,i))throw Error("WeakMap key fail: "+t);return t[i][this.id_]=e,this},e.prototype.get=function(t){return r(t)&&g.owns(t,i)?t[i][this.id_]:void 0},e.prototype.has=function(t){return r(t)&&g.owns(t,i)&&g.owns(t[i],this.id_)},e.prototype.delete=function(t){return!!(r(t)&&g.owns(t,i)&&g.owns(t[i],this.id_))&&delete t[i][this.id_]},e},"es6","es3"),g.MapEntry=function(){},g.polyfill("Map",function(t){function e(){var t={};return t.previous=t.next=t.head=t}function n(t,e){var n=t.head_;return g.iteratorPrototype(function(){if(n){for(;n.head!=t.head_;)n=n.previous;for(;n.next!=n.head;)return n=n.next,{done:!1,value:e(n)};n=null}return{done:!0,value:void 0}})}function r(t,e){var n=e&&typeof e;"object"==n||"function"==n?s.has(e)?n=s.get(e):(n=""+ ++i,s.set(e,n)):n="p_"+e;var r=t.data_[n];if(r&&g.owns(t.data_,n))for(t=0;t<r.length;t++){var a=r[t];if(e!==e&&a.key!==a.key||e===a.key)return{id:n,list:r,index:t,entry:a}}return{id:n,list:r,index:-1,entry:void 0}}function a(t){if(this.data_={},this.head_=e(),this.size=0,t){t=g.makeIterator(t);for(var n;!(n=t.next()).done;)n=n.value,this.set(n[0],n[1])}}if(g.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS){if(t&&g.ES6_CONFORMANCE)return t}else if(function(){if(g.ASSUME_NO_NATIVE_MAP||!t||"function"!=typeof t||!t.prototype.entries||"function"!=typeof Object.seal)return!1;try{var e=Object.seal({x:4}),n=new t(g.makeIterator([[e,"s"]]));if("s"!=n.get(e)||1!=n.size||n.get({x:4})||n.set({x:4},"t")!=n||2!=n.size)return!1;var r=n.entries(),a=r.next();return!a.done&&a.value[0]==e&&"s"==a.value[1]&&!((a=r.next()).done||4!=a.value[0].x||"t"!=a.value[1]||!r.next().done)}catch(t){return!1}}())return t;var s=new WeakMap;a.prototype.set=function(t,e){var n=r(this,t=0===t?0:t);return n.list||(n.list=this.data_[n.id]=[]),n.entry?n.entry.value=e:(n.entry={next:this.head_,previous:this.head_.previous,head:this.head_,key:t,value:e},n.list.push(n.entry),this.head_.previous.next=n.entry,this.head_.previous=n.entry,this.size++),this},a.prototype.delete=function(t){return!(!(t=r(this,t)).entry||!t.list)&&(t.list.splice(t.index,1),t.list.length||delete this.data_[t.id],t.entry.previous.next=t.entry.next,t.entry.next.previous=t.entry.previous,t.entry.head=null,this.size--,!0)},a.prototype.clear=function(){this.data_={},this.head_=this.head_.previous=e(),this.size=0},a.prototype.has=function(t){return!!r(this,t).entry},a.prototype.get=function(t){return(t=r(this,t).entry)&&t.value},a.prototype.entries=function(){return n(this,function(t){return[t.key,t.value]})},a.prototype.keys=function(){return n(this,function(t){return t.key})},a.prototype.values=function(){return n(this,function(t){return t.value})},a.prototype.forEach=function(t,e){for(var n,r=this.entries();!(n=r.next()).done;)n=n.value,t.call(e,n[1],n[0],this)},a.prototype[Symbol.iterator]=a.prototype.entries;var i=0;return a},"es6","es3"),g.checkStringArgs=function(t,e,n){if(null==t)throw new TypeError("The 'this' value for String.prototype."+n+" must not be null or undefined");if(e instanceof RegExp)throw new TypeError("First argument to String.prototype."+n+" must not be a regular expression");return t+""},g.polyfill("String.prototype.endsWith",function(t){return t||function(t,e){var n=g.checkStringArgs(this,t,"endsWith");t+="",void 0===e&&(e=n.length),e=Math.max(0,Math.min(0|e,n.length));for(var r=t.length;0<r&&0<e;)if(n[--e]!=t[--r])return!1;return 0>=r}},"es6","es3"),g.polyfill("Number.isNaN",function(t){return t||function(t){return"number"==typeof t&&isNaN(t)}},"es6","es3"),g.polyfill("String.prototype.startsWith",function(t){return t||function(t,e){var n=g.checkStringArgs(this,t,"startsWith");t+="";var r=n.length,a=t.length;e=Math.max(0,Math.min(0|e,n.length));for(var s=0;s<a&&e<r;)if(n[e++]!=t[s++])return!1;return s>=a}},"es6","es3");var u=this;"object"==typeof exports&&"undefined"!=typeof module?module.exports=v():"function"==typeof define&&define.amd?define(v):(u=u||self,u.FastestValidator=v()); | ||
"use strict";function v(){function t(t){if(this.opts={},this.defaults={},this.messages=Object.assign({},F),this.rules={any:k,array:S,boolean:E,class:x,custom:b,currency:g,date:y,email:v,enum:d,equal:m,forbidden:h,function:p,multi:c,number:f,object:o,objectID:l,string:u,tuple:i,url:s,uuid:a,mac:r,luhn:n},this.aliases={},this.cache=new Map,t){if(j(this.opts,t),t.defaults&&j(this.defaults,t.defaults),t.messages)for(var O in t.messages)this.addMessage(O,t.messages[O]);if(t.aliases)for(var _ in t.aliases)this.alias(_,t.aliases[_]);if(t.customRules)for(var w in t.customRules)this.add(w,t.customRules[w]);if(t.plugins){if(t=t.plugins,!Array.isArray(t))throw Error("Plugins type must be array");t.forEach(this.plugin.bind(this))}this.opts.debug&&(t=function(t){return t},"undefined"==typeof window&&(t=e),this._formatter=t)}}function e(t){return T||(T=w(),A={parser:"babel",useTabs:!1,printWidth:120,trailingComma:"none",tabWidth:4,singleQuote:!1,semi:!0,bracketSpacing:!0},I=w(),N={language:"js",theme:I.fromJson({keyword:["white","bold"],built_in:"magenta",literal:"cyan",number:"magenta",regexp:"red",string:["yellow","bold"],symbol:"plain",class:"blue",attr:"plain",function:["white","bold"],title:"plain",params:"green",comment:"grey"})}),t=T.format(t,A),I.highlight(t,N)}function n(t){return t=t.messages,{source:'\n\t\t\tif (typeof value !== "string") {\n\t\t\t\t'+this.makeError({type:"string",actual:"value",messages:t})+'\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tif (typeof value !== "string")\n\t\t\t\tvalue = String(value);\n\n\t\t\tval = value.replace(/\\D+/g, "");\n\n\t\t\tvar array = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9];\n\t\t\tvar len = val ? val.length : 0,\n\t\t\t\tbit = 1,\n\t\t\t\tsum = 0;\n\t\t\twhile (len--) {\n\t\t\t\tsum += !(bit ^= 1) ? parseInt(val[len], 10) : array[val[len]];\n\t\t\t}\n\n\t\t\tif (!(sum % 10 === 0 && sum > 0)) {\n\t\t\t\t'+this.makeError({type:"luhn",actual:"value",messages:t})+"\n\t\t\t}\n\n\t\t\treturn value;\n\t\t"}}function r(t){return t=t.messages,{source:'\n\t\t\tif (typeof value !== "string") {\n\t\t\t\t'+this.makeError({type:"string",actual:"value",messages:t})+"\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tvar v = value.toLowerCase();\n\t\t\tif (!"+J.toString()+".test(v)) {\n\t\t\t\t"+this.makeError({type:"mac",actual:"value",messages:t})+"\n\t\t\t}\n\t\t\t\n\t\t\treturn value;\n\t\t"}}function a(t){var e=t.schema;t=t.messages;var n=[];return n.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+this.makeError({type:"string",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tvar val = value.toLowerCase();\n\t\tif (!"+Y.toString()+".test(val)) {\n\t\t\t"+this.makeError({type:"uuid",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tconst version = val.charAt(14) | 0;\n\t"),7>parseInt(e.version)&&n.push("\n\t\t\tif ("+e.version+" !== version) {\n\t\t\t\t"+this.makeError({type:"uuidVersion",expected:e.version,actual:"version",messages:t})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t"),n.push('\n\t\tswitch (version) {\n\t\tcase 0:\n\t\tcase 1:\n\t\tcase 2:\n\t\tcase 6:\n\t\t\tbreak;\n\t\tcase 3:\n\t\tcase 4:\n\t\tcase 5:\n\t\t\tif (["8", "9", "a", "b"].indexOf(val.charAt(19)) === -1) {\n\t\t\t\t'+this.makeError({type:"uuid",actual:"value",messages:t})+"\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t"),{source:n.join("\n")}}function s(t){var e=t.schema;t=t.messages;var n=[];return n.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+this.makeError({type:"string",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\t"),e.empty?n.push("\n\t\t\tif (value.length === 0) return value;\n\t\t"):n.push("\n\t\t\tif (value.length === 0) {\n\t\t\t\t"+this.makeError({type:"urlEmpty",actual:"value",messages:t})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t"),n.push("\n\t\tif (!"+z.toString()+".test(value)) {\n\t\t\t"+this.makeError({type:"url",actual:"value",messages:t})+"\n\t\t}\n\n\t\treturn value;\n\t"),{source:n.join("\n")}}function i(t,e,n){var r=t.schema,a=t.messages;if(t=[],null!=r.items){if(!Array.isArray(r.items))throw Error("Invalid '"+r.type+"' schema. The 'items' field must be an array.");if(0===r.items.length)throw Error("Invalid '"+r.type+"' schema. The 'items' field must not be an empty array.")}if(t.push("\n\t\tif (!Array.isArray(value)) {\n\t\t\t"+this.makeError({type:"tuple",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tvar len = value.length;\n\t"),!1===r.empty&&t.push("\n\t\t\tif (len === 0) {\n\t\t\t\t"+this.makeError({type:"tupleEmpty",actual:"value",messages:a})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t"),null!=r.items){for(t.push("\n\t\t\tif ("+r.empty+" !== false && len === 0) {\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tif (len !== "+r.items.length+") {\n\t\t\t\t"+this.makeError({type:"tupleLength",expected:r.items.length,actual:"len",messages:a})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t"),t.push("\n\t\t\tvar arr = value;\n\t\t\tvar parentField = field;\n\t\t"),a=0;a<r.items.length;a++){t.push("\n\t\t\tvalue = arr["+a+"];\n\t\t");var s=e+"["+a+"]",i=this.getRuleFromSchema(r.items[a]);t.push(this.compileRule(i,n,s,"\n\t\t\tarr["+a+"] = "+(n.async?"await ":"")+"context.fn[%%INDEX%%](arr["+a+'], (parentField ? parentField : "") + "[" + '+a+' + "]", parent, errors, context);\n\t\t',"arr["+a+"]"))}t.push("\n\t\treturn arr;\n\t")}else t.push("\n\t\treturn value;\n\t");return{source:t.join("\n")}}function u(t){var e=t.schema;t=t.messages;var n=[],r=!1;if(!0===e.convert&&(r=!0,n.push('\n\t\t\tif (typeof value !== "string") {\n\t\t\t\tvalue = String(value);\n\t\t\t}\n\t\t')),n.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+this.makeError({type:"string",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tvar origValue = value;\n\t"),e.trim&&(r=!0,n.push("\n\t\t\tvalue = value.trim();\n\t\t")),e.trimLeft&&(r=!0,n.push("\n\t\t\tvalue = value.trimLeft();\n\t\t")),e.trimRight&&(r=!0,n.push("\n\t\t\tvalue = value.trimRight();\n\t\t")),e.padStart&&(r=!0,n.push("\n\t\t\tvalue = value.padStart("+e.padStart+", "+JSON.stringify(null!=e.padChar?e.padChar:" ")+");\n\t\t")),e.padEnd&&(r=!0,n.push("\n\t\t\tvalue = value.padEnd("+e.padEnd+", "+JSON.stringify(null!=e.padChar?e.padChar:" ")+");\n\t\t")),e.lowercase&&(r=!0,n.push("\n\t\t\tvalue = value.toLowerCase();\n\t\t")),e.uppercase&&(r=!0,n.push("\n\t\t\tvalue = value.toUpperCase();\n\t\t")),e.localeLowercase&&(r=!0,n.push("\n\t\t\tvalue = value.toLocaleLowerCase();\n\t\t")),e.localeUppercase&&(r=!0,n.push("\n\t\t\tvalue = value.toLocaleUpperCase();\n\t\t")),n.push("\n\t\t\tvar len = value.length;\n\t"),!1===e.empty&&n.push("\n\t\t\tif (len === 0) {\n\t\t\t\t"+this.makeError({type:"stringEmpty",actual:"value",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.min&&n.push("\n\t\t\tif (len < "+e.min+") {\n\t\t\t\t"+this.makeError({type:"stringMin",expected:e.min,actual:"len",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.max&&n.push("\n\t\t\tif (len > "+e.max+") {\n\t\t\t\t"+this.makeError({type:"stringMax",expected:e.max,actual:"len",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.length&&n.push("\n\t\t\tif (len !== "+e.length+") {\n\t\t\t\t"+this.makeError({type:"stringLength",expected:e.length,actual:"len",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.pattern){var a=e.pattern;"string"==typeof e.pattern&&(a=new RegExp(e.pattern,e.patternFlags)),a="\n\t\t\tif (!"+a.toString()+".test(value))\n\t\t\t\t"+this.makeError({type:"stringPattern",expected:'"'+a.toString().replace(/"/g,"\\$&")+'"',actual:"origValue",messages:t})+"\n\t\t",n.push("\n\t\t\tif ("+e.empty+" === true && len === 0) {\n\t\t\t\t// Do nothing\n\t\t\t} else {\n\t\t\t\t"+a+"\n\t\t\t}\n\t\t")}return null!=e.contains&&n.push('\n\t\t\tif (value.indexOf("'+e.contains+'") === -1) {\n\t\t\t\t'+this.makeError({type:"stringContains",expected:'"'+e.contains+'"',actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.enum&&(a=JSON.stringify(e.enum),n.push("\n\t\t\tif ("+a+".indexOf(value) === -1) {\n\t\t\t\t"+this.makeError({type:"stringEnum",expected:'"'+e.enum.join(", ")+'"',actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t")),!0===e.numeric&&n.push("\n\t\t\tif (!"+V.toString()+".test(value) ) {\n\t\t\t\t"+this.makeError({type:"stringNumeric",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.alpha&&n.push("\n\t\t\tif(!"+R.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringAlpha",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.alphanum&&n.push("\n\t\t\tif(!"+$.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringAlphanum",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.alphadash&&n.push("\n\t\t\tif(!"+q.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringAlphadash",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.hex&&n.push("\n\t\t\tif(value.length % 2 !== 0 || !"+U.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringHex",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.singleLine&&n.push('\n\t\t\tif(value.includes("\\n")) {\n\t\t\t\t'+this.makeError({type:"stringSingleLine",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.base64&&n.push("\n\t\t\tif(!"+D.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringBase64",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),n.push("\n\t\treturn value;\n\t"),{sanitized:r,source:n.join("\n")}}function l(t,e,n){e=t.schema;var r=t.messages;t=t.index;var a=[];return n.customs[t]?n.customs[t].schema=e:n.customs[t]={schema:e},a.push("\n\t\tconst ObjectID = context.customs["+t+"].schema.ObjectID;\n\t\tif (!ObjectID.isValid(value)) {\n\t\t\t"+this.makeError({type:"objectID",actual:"value",messages:r})+"\n\t\t\treturn;\n\t\t}\n\t"),!0===e.convert?a.push("return new ObjectID(value)"):"hexString"===e.convert?a.push("return value.toString()"):a.push("return value"),{source:a.join("\n")}}function o(t,e,n){var r=t.schema;t=t.messages;var a=[];a.push('\n\t\tif (typeof value !== "object" || value === null || Array.isArray(value)) {\n\t\t\t'+this.makeError({type:"object",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\t");var s=r.properties||r.props;if(s){a.push("var parentObj = value;"),a.push("var parentField = field;");for(var i=Object.keys(s),u=0;u<i.length;u++){var l=i[u],o=_(l),f=C.test(o)?"."+o:"['"+o+"']",c="parentObj"+f,p=(e?e+".":"")+l;a.push("\n// Field: "+_(p)),a.push('field = parentField ? parentField + "'+f+'" : "'+o+'";'),a.push("value = "+c+";"),l=this.getRuleFromSchema(s[l]),a.push(this.compileRule(l,n,p,"\n\t\t\t\t"+c+" = "+(n.async?"await ":"")+"context.fn[%%INDEX%%](value, field, parentObj, errors, context);\n\t\t\t",c))}r.strict&&(e=Object.keys(s),a.push("\n\t\t\t\tfield = parentField;\n\t\t\t\tvar invalidProps = [];\n\t\t\t\tvar props = Object.keys(parentObj);\n\n\t\t\t\tfor (let i = 0; i < props.length; i++) {\n\t\t\t\t\tif ("+JSON.stringify(e)+".indexOf(props[i]) === -1) {\n\t\t\t\t\t\tinvalidProps.push(props[i]);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (invalidProps.length) {\n\t\t\t"),"remove"==r.strict?a.push("\n\t\t\t\t\tinvalidProps.forEach(function(field) {\n\t\t\t\t\t\tdelete parentObj[field];\n\t\t\t\t\t});\n\t\t\t\t"):a.push("\n\t\t\t\t\t"+this.makeError({type:"objectStrict",expected:'"'+e.join(", ")+'"',actual:"invalidProps.join(', ')",messages:t})+"\n\t\t\t\t"),a.push("\n\t\t\t\t}\n\t\t\t"))}return null==r.minProps&&null==r.maxProps||(r.strict?a.push("\n\t\t\t\tprops = Object.keys("+(s?"parentObj":"value")+");\n\t\t\t"):a.push("\n\t\t\t\tvar props = Object.keys("+(s?"parentObj":"value")+");\n\t\t\t\t"+(s?"field = parentField;":"")+"\n\t\t\t")),null!=r.minProps&&a.push("\n\t\t\tif (props.length < "+r.minProps+") {\n\t\t\t\t"+this.makeError({type:"objectMinProps",expected:r.minProps,actual:"props.length",messages:t})+"\n\t\t\t}\n\t\t"),null!=r.maxProps&&a.push("\n\t\t\tif (props.length > "+r.maxProps+") {\n\t\t\t\t"+this.makeError({type:"objectMaxProps",expected:r.maxProps,actual:"props.length",messages:t})+"\n\t\t\t}\n\t\t"),s?a.push("\n\t\t\treturn parentObj;\n\t\t"):a.push("\n\t\t\treturn value;\n\t\t"),{source:a.join("\n")}}function f(t){var e=t.schema;t=t.messages;var n=[];n.push("\n\t\tvar origValue = value;\n\t");var r=!1;return!0===e.convert&&(r=!0,n.push('\n\t\t\tif (typeof value !== "number") {\n\t\t\t\tvalue = Number(value);\n\t\t\t}\n\t\t')),n.push('\n\t\tif (typeof value !== "number" || isNaN(value) || !isFinite(value)) {\n\t\t\t'+this.makeError({type:"number",actual:"origValue",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\t"),null!=e.min&&n.push("\n\t\t\tif (value < "+e.min+") {\n\t\t\t\t"+this.makeError({type:"numberMin",expected:e.min,actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.max&&n.push("\n\t\t\tif (value > "+e.max+") {\n\t\t\t\t"+this.makeError({type:"numberMax",expected:e.max,actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.equal&&n.push("\n\t\t\tif (value !== "+e.equal+") {\n\t\t\t\t"+this.makeError({type:"numberEqual",expected:e.equal,actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.notEqual&&n.push("\n\t\t\tif (value === "+e.notEqual+") {\n\t\t\t\t"+this.makeError({type:"numberNotEqual",expected:e.notEqual,actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.integer&&n.push("\n\t\t\tif (value % 1 !== 0) {\n\t\t\t\t"+this.makeError({type:"numberInteger",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.positive&&n.push("\n\t\t\tif (value <= 0) {\n\t\t\t\t"+this.makeError({type:"numberPositive",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),!0===e.negative&&n.push("\n\t\t\tif (value >= 0) {\n\t\t\t\t"+this.makeError({type:"numberNegative",actual:"origValue",messages:t})+"\n\t\t\t}\n\t\t"),n.push("\n\t\treturn value;\n\t"),{sanitized:r,source:n.join("\n")}}function c(t,e,n){t=t.schema;var r=[];r.push("\n\t\tvar prevErrLen = errors.length;\n\t\tvar errBefore;\n\t\tvar hasValid = false;\n\t\tvar newVal = value;\n\t");for(var a=0;a<t.rules.length;a++){r.push("\n\t\t\tif (!hasValid) {\n\t\t\t\terrBefore = errors.length;\n\t\t");var s=this.getRuleFromSchema(t.rules[a]);r.push(this.compileRule(s,n,e,"var tmpVal = "+(n.async?"await ":"")+"context.fn[%%INDEX%%](value, field, parent, errors, context);","tmpVal")),r.push("\n\t\t\t\tif (errors.length == errBefore) {\n\t\t\t\t\thasValid = true;\n\t\t\t\t\tnewVal = tmpVal;\n\t\t\t\t}\n\t\t\t}\n\t\t")}return r.push("\n\t\tif (hasValid) {\n\t\t\terrors.length = prevErrLen;\n\t\t}\n\n\t\treturn newVal;\n\t"),{source:r.join("\n")}}function p(t){return{source:'\n\t\t\tif (typeof value !== "function")\n\t\t\t\t'+this.makeError({type:"function",actual:"value",messages:t.messages})+"\n\n\t\t\treturn value;\n\t\t"}}function h(t){var e=t.schema;t=t.messages;var n=[];return n.push("\n\t\tif (value !== null && value !== undefined) {\n\t"),e.remove?n.push("\n\t\t\treturn undefined;\n\t\t"):n.push("\n\t\t\t"+this.makeError({type:"forbidden",actual:"value",messages:t})+"\n\t\t"),n.push("\n\t\t}\n\n\t\treturn value;\n\t"),{source:n.join("\n")}}function m(t){var e=t.schema;t=t.messages;var n=[];return e.field?(e.strict?n.push('\n\t\t\t\tif (value !== parent["'+e.field+'"])\n\t\t\t'):n.push('\n\t\t\t\tif (value != parent["'+e.field+'"])\n\t\t\t'),n.push("\n\t\t\t\t"+this.makeError({type:"equalField",actual:"value",expected:JSON.stringify(e.field),messages:t})+"\n\t\t")):(e.strict?n.push("\n\t\t\t\tif (value !== "+JSON.stringify(e.value)+")\n\t\t\t"):n.push("\n\t\t\t\tif (value != "+JSON.stringify(e.value)+")\n\t\t\t"),n.push("\n\t\t\t\t"+this.makeError({type:"equalValue",actual:"value",expected:JSON.stringify(e.value),messages:t})+"\n\t\t")),n.push("\n\t\treturn value;\n\t"),{source:n.join("\n")}}function d(t){var e=t.schema;return t=t.messages,{source:"\n\t\t\tif ("+JSON.stringify(e.values||[])+".indexOf(value) === -1)\n\t\t\t\t"+this.makeError({type:"enumValue",expected:'"'+e.values.join(", ")+'"',actual:"value",messages:t})+"\n\t\t\t\n\t\t\treturn value;\n\t\t"}}function v(t){var e=t.schema;t=t.messages;var n=[],r="precise"==e.mode?M:P,a=!1;return n.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+this.makeError({type:"string",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\t"),e.empty?n.push("\n\t\t\tif (value.length === 0) return value;\n\t\t"):n.push("\n\t\t\tif (value.length === 0) {\n\t\t\t\t"+this.makeError({type:"emailEmpty",actual:"value",messages:t})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t"),e.normalize&&(a=!0,n.push("\n\t\t\tvalue = value.trim().toLowerCase();\n\t\t")),null!=e.min&&n.push("\n\t\t\tif (value.length < "+e.min+") {\n\t\t\t\t"+this.makeError({type:"emailMin",expected:e.min,actual:"value.length",messages:t})+"\n\t\t\t}\n\t\t"),null!=e.max&&n.push("\n\t\t\tif (value.length > "+e.max+") {\n\t\t\t\t"+this.makeError({type:"emailMax",expected:e.max,actual:"value.length",messages:t})+"\n\t\t\t}\n\t\t"),n.push("\n\t\tif (!"+r.toString()+".test(value)) {\n\t\t\t"+this.makeError({type:"email",actual:"value",messages:t})+"\n\t\t}\n\n\t\treturn value;\n\t"),{sanitized:a,source:n.join("\n")}}function y(t){var e=t.schema;t=t.messages;var n=[],r=!1;return n.push("\n\t\tvar origValue = value;\n\t"),!0===e.convert&&(r=!0,n.push("\n\t\t\tif (!(value instanceof Date)) {\n\t\t\t\tvalue = new Date(value);\n\t\t\t}\n\t\t")),n.push("\n\t\tif (!(value instanceof Date) || isNaN(value.getTime()))\n\t\t\t"+this.makeError({type:"date",actual:"origValue",messages:t})+"\n\n\t\treturn value;\n\t"),{sanitized:r,source:n.join("\n")}}function g(t){var e=t.schema;t=t.messages;var n=e.currencySymbol||null,r=e.thousandSeparator||",",a=e.decimalSeparator||".",s=e.customRegex;return e=!e.symbolOptional,e="(?=.*\\d)^(-?~1|~1-?)(([0-9]\\d{0,2}(~2\\d{3})*)|0)?(\\~3\\d{1,2})?$".replace(/~1/g,n?"\\"+n+(e?"":"?"):"").replace("~2",r).replace("~3",a),(n=[]).push("\n\t\tif (!value.match("+(s||new RegExp(e))+")) {\n\t\t\t"+this.makeError({type:"currency",actual:"value",messages:t})+"\n\t\t\treturn value;\n\t\t}\n\n\t\treturn value;\n\t"),{source:n.join("\n")}}function b(t,e,n){var r=[];return r.push("\n\t\t"+this.makeCustomValidator({fnName:"check",path:e,schema:t.schema,messages:t.messages,context:n,ruleIndex:t.index})+"\n\t\treturn value;\n\t"),{source:r.join("\n")}}function x(t,e,n){e=t.schema;var r=t.messages;t=t.index;var a=[],s=e.instanceOf.name?e.instanceOf.name:"<UnknowClass>";return n.customs[t]?n.customs[t].schema=e:n.customs[t]={schema:e},a.push("\n\t\tif (!(value instanceof context.customs["+t+"].schema.instanceOf))\n\t\t\t"+this.makeError({type:"classInstanceOf",actual:"value",expected:"'"+s+"'",messages:r})+"\n\t"),a.push("\n\t\treturn value;\n\t"),{source:a.join("\n")}}function E(t){var e=t.schema;t=t.messages;var n=[],r=!1;return n.push("\n\t\tvar origValue = value;\n\t"),!0===e.convert&&(r=!0,n.push('\n\t\t\tif (typeof value !== "boolean") {\n\t\t\t\tif (\n\t\t\t\tvalue === 1\n\t\t\t\t|| value === "true"\n\t\t\t\t|| value === "1"\n\t\t\t\t|| value === "on"\n\t\t\t\t) {\n\t\t\t\t\tvalue = true;\n\t\t\t\t} else if (\n\t\t\t\tvalue === 0\n\t\t\t\t|| value === "false"\n\t\t\t\t|| value === "0"\n\t\t\t\t|| value === "off"\n\t\t\t\t) {\n\t\t\t\t\tvalue = false;\n\t\t\t\t}\n\t\t\t}\n\t\t')),n.push('\n\t\tif (typeof value !== "boolean") {\n\t\t\t'+this.makeError({type:"boolean",actual:"origValue",messages:t})+"\n\t\t}\n\t\t\n\t\treturn value;\n\t"),{sanitized:r,source:n.join("\n")}}function S(t,e,n){var r=t.schema,a=t.messages;if((t=[]).push("\n\t\tif (!Array.isArray(value)) {\n\t\t\t"+this.makeError({type:"array",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tvar len = value.length;\n\t"),!1===r.empty&&t.push("\n\t\t\tif (len === 0) {\n\t\t\t\t"+this.makeError({type:"arrayEmpty",actual:"value",messages:a})+"\n\t\t\t}\n\t\t"),null!=r.min&&t.push("\n\t\t\tif (len < "+r.min+") {\n\t\t\t\t"+this.makeError({type:"arrayMin",expected:r.min,actual:"len",messages:a})+"\n\t\t\t}\n\t\t"),null!=r.max&&t.push("\n\t\t\tif (len > "+r.max+") {\n\t\t\t\t"+this.makeError({type:"arrayMax",expected:r.max,actual:"len",messages:a})+"\n\t\t\t}\n\t\t"),null!=r.length&&t.push("\n\t\t\tif (len !== "+r.length+") {\n\t\t\t\t"+this.makeError({type:"arrayLength",expected:r.length,actual:"len",messages:a})+"\n\t\t\t}\n\t\t"),null!=r.contains&&t.push("\n\t\t\tif (value.indexOf("+JSON.stringify(r.contains)+") === -1) {\n\t\t\t\t"+this.makeError({type:"arrayContains",expected:JSON.stringify(r.contains),actual:"value",messages:a})+"\n\t\t\t}\n\t\t"),!0===r.unique&&t.push("\n\t\t\tif(len > (new Set(value)).size) {\n\t\t\t\t"+this.makeError({type:"arrayUnique",expected:"Array.from(new Set(value.filter((item, index) => value.indexOf(item) !== index)))",actual:"value",messages:a})+"\n\t\t\t}\n\t\t"),null!=r.enum){var s=JSON.stringify(r.enum);t.push("\n\t\t\tfor (var i = 0; i < value.length; i++) {\n\t\t\t\tif ("+s+".indexOf(value[i]) === -1) {\n\t\t\t\t\t"+this.makeError({type:"arrayEnum",expected:'"'+r.enum.join(", ")+'"',actual:"value[i]",messages:a})+"\n\t\t\t\t}\n\t\t\t}\n\t\t")}return null!=r.items?(t.push("\n\t\t\tvar arr = value;\n\t\t\tvar parentField = field;\n\t\t\tfor (var i = 0; i < arr.length; i++) {\n\t\t\t\tvalue = arr[i];\n\t\t"),e+="[]",r=this.getRuleFromSchema(r.items),t.push(this.compileRule(r,n,e,"arr[i] = "+(n.async?"await ":"")+'context.fn[%%INDEX%%](arr[i], (parentField ? parentField : "") + "[" + i + "]", parent, errors, context)',"arr[i]")),t.push("\n\t\t\t}\n\t\t"),t.push("\n\t\treturn arr;\n\t")):t.push("\n\t\treturn value;\n\t"),{source:t.join("\n")}}function k(){var t=[];return t.push("\n\t\treturn value;\n\t"),{source:t.join("\n")}}function O(t,e,n){return t.replace(e,void 0===n||null===n?"":"function"==typeof n.toString?n:typeof n)}function j(t,e,n){void 0===n&&(n={});for(var r in e){var a=e[r];(a="object"==typeof a&&!Array.isArray(a)&&null!=a&&0<Object.keys(a).length)?(t[r]=t[r]||{},j(t[r],e[r],n)):!0===n.skipIfExist&&void 0!==t[r]||(t[r]=e[r])}return t}function _(t){return t.replace(L,function(t){switch(t){case'"':case"'":case"\\":return"\\"+t;case"\n":return"\\n";case"\r":return"\\r";case"\u2028":return"\\u2028";case"\u2029":return"\\u2029"}})}function w(){throw Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}var T,A,I,N,F={required:"The '{field}' field is required.",string:"The '{field}' field must be a string.",stringEmpty:"The '{field}' field must not be empty.",stringMin:"The '{field}' field length must be greater than or equal to {expected} characters long.",stringMax:"The '{field}' field length must be less than or equal to {expected} characters long.",stringLength:"The '{field}' field length must be {expected} characters long.",stringPattern:"The '{field}' field fails to match the required pattern.",stringContains:"The '{field}' field must contain the '{expected}' text.",stringEnum:"The '{field}' field does not match any of the allowed values.",stringNumeric:"The '{field}' field must be a numeric string.",stringAlpha:"The '{field}' field must be an alphabetic string.",stringAlphanum:"The '{field}' field must be an alphanumeric string.",stringAlphadash:"The '{field}' field must be an alphadash string.",stringHex:"The '{field}' field must be a hex string.",stringSingleLine:"The '{field}' field must be a single line string.",stringBase64:"The '{field}' field must be a base64 string.",number:"The '{field}' field must be a number.",numberMin:"The '{field}' field must be greater than or equal to {expected}.",numberMax:"The '{field}' field must be less than or equal to {expected}.",numberEqual:"The '{field}' field must be equal to {expected}.",numberNotEqual:"The '{field}' field can't be equal to {expected}.",numberInteger:"The '{field}' field must be an integer.",numberPositive:"The '{field}' field must be a positive number.",numberNegative:"The '{field}' field must be a negative number.",array:"The '{field}' field must be an array.",arrayEmpty:"The '{field}' field must not be an empty array.",arrayMin:"The '{field}' field must contain at least {expected} items.",arrayMax:"The '{field}' field must contain less than or equal to {expected} items.",arrayLength:"The '{field}' field must contain {expected} items.",arrayContains:"The '{field}' field must contain the '{expected}' item.",arrayUnique:"The '{actual}' value in '{field}' field does not unique the '{expected}' values.",arrayEnum:"The '{actual}' value in '{field}' field does not match any of the '{expected}' values.",tuple:"The '{field}' field must be an array.",tupleEmpty:"The '{field}' field must not be an empty array.",tupleLength:"The '{field}' field must contain {expected} items.",boolean:"The '{field}' field must be a boolean.",currency:"The '{field}' must be a valid currency format",date:"The '{field}' field must be a Date.",dateMin:"The '{field}' field must be greater than or equal to {expected}.",dateMax:"The '{field}' field must be less than or equal to {expected}.",enumValue:"The '{field}' field value '{expected}' does not match any of the allowed values.",equalValue:"The '{field}' field value must be equal to '{expected}'.",equalField:"The '{field}' field value must be equal to '{expected}' field value.",forbidden:"The '{field}' field is forbidden.",function:"The '{field}' field must be a function.",email:"The '{field}' field must be a valid e-mail.",emailEmpty:"The '{field}' field must not be empty.",emailMin:"The '{field}' field length must be greater than or equal to {expected} characters long.",emailMax:"The '{field}' field length must be less than or equal to {expected} characters long.",luhn:"The '{field}' field must be a valid checksum luhn.",mac:"The '{field}' field must be a valid MAC address.",object:"The '{field}' must be an Object.",objectStrict:"The object '{field}' contains forbidden keys: '{actual}'.",objectMinProps:"The object '{field}' must contain at least {expected} properties.",objectMaxProps:"The object '{field}' must contain {expected} properties at most.",url:"The '{field}' field must be a valid URL.",urlEmpty:"The '{field}' field must not be empty.",uuid:"The '{field}' field must be a valid UUID.",uuidVersion:"The '{field}' field must be a valid UUID version provided.",classInstanceOf:"The '{field}' field must be an instance of the '{expected}' class.",objectID:"The '{field}' field must be an valid ObjectID"},M=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,P=/^\S+@\S+\.\S+$/,C=/^[_$a-zA-Z][_$a-zA-Z0-9]*$/,L=/["'\\\n\r\u2028\u2029]/g,V=/^-?[0-9]\d*(\.\d+)?$/,R=/^[a-zA-Z]+$/,$=/^[a-zA-Z0-9]+$/,q=/^[a-zA-Z0-9_-]+$/,U=/^[0-9a-fA-F]+$/,D=/^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+/]{3}=)?$/,z=/^https?:\/\/\S+/,Y=/^([0-9a-f]{8}-[0-9a-f]{4}-[1-6][0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}|[0]{8}-[0]{4}-[0]{4}-[0]{4}-[0]{12})$/i,J=/^((([a-f0-9][a-f0-9]+[-]){5}|([a-f0-9][a-f0-9]+[:]){5})([a-f0-9][a-f0-9])$)|(^([a-f0-9][a-f0-9][a-f0-9][a-f0-9]+[.]){2}([a-f0-9][a-f0-9][a-f0-9][a-f0-9]))$/i;try{var X=new Function("return Object.getPrototypeOf(async function(){}).constructor")()}catch(t){}return t.prototype.validate=function(t,e){return this.compile(e)(t)},t.prototype.wrapRequiredCheckSourceCode=function(t,e,n,r){var a=[],s=!0===t.schema.optional||"forbidden"===t.schema.type,i=!0===t.schema.optional||!0===t.schema.nullable||"forbidden"===t.schema.type;return null!=t.schema.default?(s=!1,!0!==t.schema.nullable&&(i=!1),"function"==typeof t.schema.default?(n.customs[t.index]||(n.customs[t.index]={}),n.customs[t.index].defaultFn=t.schema.default,t="context.customs["+t.index+"].defaultFn()"):t=JSON.stringify(t.schema.default),r="\n\t\t\t\tvalue = "+t+";\n\t\t\t\t"+r+" = value;\n\t\t\t"):r=this.makeError({type:"required",actual:"value",messages:t.messages}),a.push("\n\t\t\tif (value === undefined) { "+(s?"\n// allow undefined\n":r)+" }\n\t\t\telse if (value === null) { "+(i?"\n// allow null\n":r)+" }\n\t\t\t"+(e?"else { "+e+" }":"")+"\n\t\t"),a.join("\n")},t.prototype.compile=function(t){function e(t,e){return r.data=t,e&&e.meta&&(r.meta=e.meta),s.call(n,t,r)}if(null===t||"object"!=typeof t)throw Error("Invalid schema.");var n=this,r={index:0,async:!0===t.$$async,rules:[],fn:[],customs:{},utils:{replace:O}};if(this.cache.clear(),delete t.$$async,r.async&&!X)throw Error("Asynchronous mode is not supported.");if(!0!==t.$$root)if(Array.isArray(t))t=this.getRuleFromSchema(t).schema;else{var a=Object.assign({},t);t={type:"object",strict:a.$$strict,properties:a},delete a.$$strict}a=["var errors = [];","var field;","var parent = null;"],t=this.getRuleFromSchema(t),a.push(this.compileRule(t,r,null,(r.async?"await ":"")+"context.fn[%%INDEX%%](value, field, null, errors, context);","value")),a.push("if (errors.length) {"),a.push("\n\t\t\treturn errors.map(err => {\n\t\t\t\tif (err.message) {\n\t\t\t\t\terr.message = context.utils.replace(err.message, /\\{field\\}/g, err.field);\n\t\t\t\t\terr.message = context.utils.replace(err.message, /\\{expected\\}/g, err.expected);\n\t\t\t\t\terr.message = context.utils.replace(err.message, /\\{actual\\}/g, err.actual);\n\t\t\t\t}\n\n\t\t\t\treturn err;\n\t\t\t});\n\t\t"),a.push("}"),a.push("return true;"),t=a.join("\n");var s=new(r.async?X:Function)("value","context",t);return this.opts.debug&&console.log(this._formatter("// Main check function\n"+s.toString())),this.cache.clear(),e.async=r.async,e},t.prototype.compileRule=function(t,e,n,r,a){var s=[],i=this.cache.get(t.schema);return i?(t=i,t.cycle=!0,t.cycleStack=[],s.push(this.wrapRequiredCheckSourceCode(t,"\n\t\t\t\tvar rule = context.rules["+t.index+"];\n\t\t\t\tif (rule.cycleStack.indexOf(value) === -1) {\n\t\t\t\t\trule.cycleStack.push(value);\n\t\t\t\t\t"+r.replace(/%%INDEX%%/g,t.index)+"\n\t\t\t\t\trule.cycleStack.pop(value);\n\t\t\t\t}\n\t\t\t",e,a))):(this.cache.set(t.schema,t),t.index=e.index,e.rules[e.index]=t,i=null!=n?n:"$$root",e.index++,n=t.ruleFunction.call(this,t,n,e),n.source=n.source.replace(/%%INDEX%%/g,t.index),n=new(e.async?X:Function)("value","field","parent","errors","context",n.source),e.fn[t.index]=n.bind(this),s.push(this.wrapRequiredCheckSourceCode(t,r.replace(/%%INDEX%%/g,t.index),e,a)),s.push(this.makeCustomValidator({vName:a,path:i,schema:t.schema,context:e,messages:t.messages,ruleIndex:t.index})),this.opts.debug&&console.log(this._formatter("// Context.fn["+t.index+"]\n"+n.toString()))),s.join("\n")},t.prototype.getRuleFromSchema=function(t){var e=this;if("string"==typeof t)t=this.parseShortHand(t);else if(Array.isArray(t)){if(0==t.length)throw Error("Invalid schema.");(t={type:"multi",rules:t}).rules.map(function(t){return e.getRuleFromSchema(t)}).every(function(t){return 1==t.schema.optional})&&(t.optional=!0)}if(t.$$type){var n=this.getRuleFromSchema(t.$$type).schema;delete t.$$type;var r,a=Object.assign({},t);for(r in t)delete t[r];j(t,n,{skipIfExist:!0}),t.props=a}if((n=this.aliases[t.type])&&(delete t.type,t=j(t,n,{skipIfExist:!0})),!(n=this.rules[t.type]))throw Error("Invalid '"+t.type+"' type in validator schema.");return{messages:Object.assign({},this.messages,t.messages),schema:j(t,this.defaults[t.type],{skipIfExist:!0}),ruleFunction:n}},t.prototype.parseShortHand=function(t){var e=(t=t.split("|").map(function(t){return t.trim()}))[0],n=e.endsWith("[]")?this.getRuleFromSchema({type:"array",items:e.slice(0,-2)}).schema:{type:t[0]};return t.slice(1).map(function(t){var e=t.indexOf(":");if(-1!==e){var r=t.substr(0,e).trim();"true"===(t=t.substr(e+1).trim())||"false"===t?t="true"===t:Number.isNaN(Number(t))||(t=Number(t)),n[r]=t}else t.startsWith("no-")?n[t.slice(3)]=!1:n[t]=!0}),n},t.prototype.makeError=function(t){var e=t.type,n=t.field,r=t.expected,a=t.actual,s={type:'"'+e+'"',message:'"'+t.messages[e]+'"'};return s.field=n?'"'+n+'"':"field",null!=r&&(s.expected=r),null!=a&&(s.actual=a),"errors.push({ "+Object.keys(s).map(function(t){return t+": "+s[t]}).join(", ")+" });"},t.prototype.makeCustomValidator=function(t){var e=t.vName;void 0===e&&(e="value");var n=t.fnName;void 0===n&&(n="custom");var r=t.ruleIndex,a=t.path,s=t.schema,i=t.context,u=t.messages;t="rule"+r;var l="fnCustomErrors"+r;return"function"==typeof s[n]?(i.customs[r]?(i.customs[r].messages=u,i.customs[r].schema=s):i.customs[r]={messages:u,schema:s},this.opts.useNewCustomCheckerFunction?"\n \t\tconst "+t+" = context.customs["+r+"];\n\t\t\t\t\tconst "+l+" = [];\n\t\t\t\t\t"+e+" = "+(i.async?"await ":"")+t+".schema."+n+".call(this, "+e+", "+l+" , "+t+'.schema, "'+a+'", parent, context);\n\t\t\t\t\tif (Array.isArray('+l+" )) {\n \t\t"+l+" .forEach(err => errors.push(Object.assign({ message: "+t+".messages[err.type], field }, err)));\n\t\t\t\t\t}\n\t\t\t\t":(s="res_"+t,"\n\t\t\t\tconst "+t+" = context.customs["+r+"];\n\t\t\t\tconst "+s+" = "+(i.async?"await ":"")+t+".schema."+n+".call(this, "+e+", "+t+'.schema, "'+a+'", parent, context);\n\t\t\t\tif (Array.isArray('+s+")) {\n\t\t\t\t\t"+s+".forEach(err => errors.push(Object.assign({ message: "+t+".messages[err.type], field }, err)));\n\t\t\t\t}\n\t\t")):""},t.prototype.add=function(t,e){this.rules[t]=e},t.prototype.addMessage=function(t,e){this.messages[t]=e},t.prototype.alias=function(t,e){if(this.rules[t])throw Error("Alias name must not be a rule name");this.aliases[t]=e},t.prototype.plugin=function(t){if("function"!=typeof t)throw Error("Plugin fn type must be function");return t(this)},t}var f=f||{};f.scope={},f.arrayIteratorImpl=function(t){var e=0;return function(){return e<t.length?{done:!1,value:t[e++]}:{done:!0}}},f.arrayIterator=function(t){return{next:f.arrayIteratorImpl(t)}},f.ASSUME_ES5=!1,f.ASSUME_NO_NATIVE_MAP=!1,f.ASSUME_NO_NATIVE_SET=!1,f.SIMPLE_FROUND_POLYFILL=!1,f.ISOLATE_POLYFILLS=!1,f.defineProperty=f.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(t,e,n){return t==Array.prototype||t==Object.prototype?t:(t[e]=n.value,t)},f.getGlobal=function(t){t=["object"==typeof globalThis&&globalThis,t,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var e=0;e<t.length;++e){var n=t[e];if(n&&n.Math==Math)return n}throw Error("Cannot find global object")},f.global=f.getGlobal(this),f.IS_SYMBOL_NATIVE="function"==typeof Symbol&&"symbol"==typeof Symbol("x"),f.TRUST_ES6_POLYFILLS=!f.ISOLATE_POLYFILLS||f.IS_SYMBOL_NATIVE,f.polyfills={},f.propertyToPolyfillSymbol={},f.POLYFILL_PREFIX="$jscp$",f.polyfill=function(t,e,n,r){e&&(f.ISOLATE_POLYFILLS?f.polyfillIsolated(t,e,n,r):f.polyfillUnisolated(t,e,n,r))},f.polyfillUnisolated=function(t,e){var n=f.global;t=t.split(".");for(var r=0;r<t.length-1;r++){var a=t[r];a in n||(n[a]={}),n=n[a]}(e=e(r=n[t=t[t.length-1]]))!=r&&null!=e&&f.defineProperty(n,t,{configurable:!0,writable:!0,value:e})},f.polyfillIsolated=function(t,e,n){var r=t.split(".");t=1===r.length;var a=r[0];a=!t&&a in f.polyfills?f.polyfills:f.global;for(var s=0;s<r.length-1;s++){var i=r[s];i in a||(a[i]={}),a=a[i]}r=r[r.length-1],null!=(e=e(n=f.IS_SYMBOL_NATIVE&&"es6"===n?a[r]:null))&&(t?f.defineProperty(f.polyfills,r,{configurable:!0,writable:!0,value:e}):e!==n&&(f.propertyToPolyfillSymbol[r]=f.IS_SYMBOL_NATIVE?f.global.Symbol(r):f.POLYFILL_PREFIX+r,r=f.propertyToPolyfillSymbol[r],f.defineProperty(a,r,{configurable:!0,writable:!0,value:e})))},f.initSymbol=function(){},f.polyfill("Symbol",function(t){function e(t){if(this instanceof e)throw new TypeError("Symbol is not a constructor");return new n("jscomp_symbol_"+(t||"")+"_"+r++,t)}function n(t,e){this.$jscomp$symbol$id_=t,f.defineProperty(this,"description",{configurable:!0,writable:!0,value:e})}if(t)return t;n.prototype.toString=function(){return this.$jscomp$symbol$id_};var r=0;return e},"es6","es3"),f.initSymbolIterator=function(){},f.polyfill("Symbol.iterator",function(t){if(t)return t;t=Symbol("Symbol.iterator");for(var e="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),n=0;n<e.length;n++){var r=f.global[e[n]];"function"==typeof r&&"function"!=typeof r.prototype[t]&&f.defineProperty(r.prototype,t,{configurable:!0,writable:!0,value:function(){return f.iteratorPrototype(f.arrayIteratorImpl(this))}})}return t},"es6","es3"),f.initSymbolAsyncIterator=function(){},f.iteratorPrototype=function(t){return t={next:t},t[Symbol.iterator]=function(){return this},t},f.iteratorFromArray=function(t,e){t instanceof String&&(t+="");var n=0,r={next:function(){if(n<t.length){var a=n++;return{value:e(a,t[a]),done:!1}}return r.next=function(){return{done:!0,value:void 0}},r.next()}};return r[Symbol.iterator]=function(){return r},r},f.polyfill("Array.prototype.keys",function(t){return t||function(){return f.iteratorFromArray(this,function(t){return t})}},"es6","es3"),f.polyfill("Array.prototype.values",function(t){return t||function(){return f.iteratorFromArray(this,function(t,e){return e})}},"es8","es3"),f.owns=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},f.assign=f.TRUST_ES6_POLYFILLS&&"function"==typeof Object.assign?Object.assign:function(t,e){for(var n=1;n<arguments.length;n++){var r=arguments[n];if(r)for(var a in r)f.owns(r,a)&&(t[a]=r[a])}return t},f.polyfill("Object.assign",function(t){return t||f.assign},"es6","es3"),f.checkEs6ConformanceViaProxy=function(){try{var t={},e=Object.create(new f.global.Proxy(t,{get:function(n,r,a){return n==t&&"q"==r&&a==e}}));return!0===e.q}catch(t){return!1}},f.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS=!1,f.ES6_CONFORMANCE=f.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS&&f.checkEs6ConformanceViaProxy(),f.makeIterator=function(t){var e="undefined"!=typeof Symbol&&Symbol.iterator&&t[Symbol.iterator];return e?e.call(t):f.arrayIterator(t)},f.polyfill("WeakMap",function(t){function e(t){if(this.id_=(u+=Math.random()+1).toString(),t){t=f.makeIterator(t);for(var e;!(e=t.next()).done;)e=e.value,this.set(e[0],e[1])}}function n(){}function r(t){var e=typeof t;return"object"===e&&null!==t||"function"===e}function a(t){if(!f.owns(t,i)){var e=new n;f.defineProperty(t,i,{value:e})}}function s(t){var e=Object[t];e&&(Object[t]=function(t){return t instanceof n?t:(a(t),e(t))})}if(f.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS){if(t&&f.ES6_CONFORMANCE)return t}else if(function(){if(!t||!Object.seal)return!1;try{var e=Object.seal({}),n=Object.seal({}),r=new t([[e,2],[n,3]]);return 2==r.get(e)&&3==r.get(n)&&(r.delete(e),r.set(n,4),!r.has(e)&&4==r.get(n))}catch(t){return!1}}())return t;var i="$jscomp_hidden_"+Math.random();s("freeze"),s("preventExtensions"),s("seal");var u=0;return e.prototype.set=function(t,e){if(!r(t))throw Error("Invalid WeakMap key");if(a(t),!f.owns(t,i))throw Error("WeakMap key fail: "+t);return t[i][this.id_]=e,this},e.prototype.get=function(t){return r(t)&&f.owns(t,i)?t[i][this.id_]:void 0},e.prototype.has=function(t){return r(t)&&f.owns(t,i)&&f.owns(t[i],this.id_)},e.prototype.delete=function(t){return!!(r(t)&&f.owns(t,i)&&f.owns(t[i],this.id_))&&delete t[i][this.id_]},e},"es6","es3"),f.MapEntry=function(){},f.polyfill("Map",function(t){function e(){var t={};return t.previous=t.next=t.head=t}function n(t,e){var n=t.head_;return f.iteratorPrototype(function(){if(n){for(;n.head!=t.head_;)n=n.previous;for(;n.next!=n.head;)return n=n.next,{done:!1,value:e(n)};n=null}return{done:!0,value:void 0}})}function r(t,e){var n=e&&typeof e;"object"==n||"function"==n?s.has(e)?n=s.get(e):(n=""+ ++i,s.set(e,n)):n="p_"+e;var r=t.data_[n];if(r&&f.owns(t.data_,n))for(t=0;t<r.length;t++){var a=r[t];if(e!==e&&a.key!==a.key||e===a.key)return{id:n,list:r,index:t,entry:a}}return{id:n,list:r,index:-1,entry:void 0}}function a(t){if(this.data_={},this.head_=e(),this.size=0,t){t=f.makeIterator(t);for(var n;!(n=t.next()).done;)n=n.value,this.set(n[0],n[1])}}if(f.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS){if(t&&f.ES6_CONFORMANCE)return t}else if(function(){if(f.ASSUME_NO_NATIVE_MAP||!t||"function"!=typeof t||!t.prototype.entries||"function"!=typeof Object.seal)return!1;try{var e=Object.seal({x:4}),n=new t(f.makeIterator([[e,"s"]]));if("s"!=n.get(e)||1!=n.size||n.get({x:4})||n.set({x:4},"t")!=n||2!=n.size)return!1;var r=n.entries(),a=r.next();return!a.done&&a.value[0]==e&&"s"==a.value[1]&&!((a=r.next()).done||4!=a.value[0].x||"t"!=a.value[1]||!r.next().done)}catch(t){return!1}}())return t;var s=new WeakMap;a.prototype.set=function(t,e){var n=r(this,t=0===t?0:t);return n.list||(n.list=this.data_[n.id]=[]),n.entry?n.entry.value=e:(n.entry={next:this.head_,previous:this.head_.previous,head:this.head_,key:t,value:e},n.list.push(n.entry),this.head_.previous.next=n.entry,this.head_.previous=n.entry,this.size++),this},a.prototype.delete=function(t){return!(!(t=r(this,t)).entry||!t.list)&&(t.list.splice(t.index,1),t.list.length||delete this.data_[t.id],t.entry.previous.next=t.entry.next,t.entry.next.previous=t.entry.previous,t.entry.head=null,this.size--,!0)},a.prototype.clear=function(){this.data_={},this.head_=this.head_.previous=e(),this.size=0},a.prototype.has=function(t){return!!r(this,t).entry},a.prototype.get=function(t){return(t=r(this,t).entry)&&t.value},a.prototype.entries=function(){return n(this,function(t){return[t.key,t.value]})},a.prototype.keys=function(){return n(this,function(t){return t.key})},a.prototype.values=function(){return n(this,function(t){return t.value})},a.prototype.forEach=function(t,e){for(var n,r=this.entries();!(n=r.next()).done;)n=n.value,t.call(e,n[1],n[0],this)},a.prototype[Symbol.iterator]=a.prototype.entries;var i=0;return a},"es6","es3"),f.checkStringArgs=function(t,e,n){if(null==t)throw new TypeError("The 'this' value for String.prototype."+n+" must not be null or undefined");if(e instanceof RegExp)throw new TypeError("First argument to String.prototype."+n+" must not be a regular expression");return t+""},f.polyfill("String.prototype.endsWith",function(t){return t||function(t,e){var n=f.checkStringArgs(this,t,"endsWith");t+="",void 0===e&&(e=n.length),e=Math.max(0,Math.min(0|e,n.length));for(var r=t.length;0<r&&0<e;)if(n[--e]!=t[--r])return!1;return 0>=r}},"es6","es3"),f.polyfill("Number.isNaN",function(t){return t||function(t){return"number"==typeof t&&isNaN(t)}},"es6","es3"),f.polyfill("String.prototype.startsWith",function(t){return t||function(t,e){var n=f.checkStringArgs(this,t,"startsWith");t+="";var r=n.length,a=t.length;e=Math.max(0,Math.min(0|e,n.length));for(var s=0;s<a&&e<r;)if(n[e++]!=t[s++])return!1;return s>=a}},"es6","es3");var u=this;"object"==typeof exports&&"undefined"!=typeof module?module.exports=v():"function"==typeof define&&define.amd?define(v):(u=u||self,u.FastestValidator=v()); |
1823
index.d.ts
@@ -1,815 +0,809 @@ | ||
declare module "fastest-validator" { | ||
export type ValidationRuleName = | ||
| "any" | ||
| "array" | ||
| "boolean" | ||
| "class" | ||
| "custom" | ||
| "date" | ||
| "email" | ||
| "enum" | ||
| "equal" | ||
| "forbidden" | ||
| "function" | ||
| "luhn" | ||
| "mac" | ||
| "multi" | ||
| "number" | ||
| "object" | ||
| "string" | ||
| "url" | ||
| "uuid" | ||
| string; | ||
/** | ||
* Validation schema definition for "any" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#any | ||
*/ | ||
export interface RuleAny extends RuleCustom { | ||
/** | ||
* Type of all possible Built-in validators names | ||
* Name of built-in validator | ||
*/ | ||
export type ValidationRuleName = | ||
| "any" | ||
| "array" | ||
| "boolean" | ||
| "class" | ||
| "custom" | ||
| "date" | ||
| "email" | ||
| "enum" | ||
| "equal" | ||
| "forbidden" | ||
| "function" | ||
| "luhn" | ||
| "mac" | ||
| "multi" | ||
| "number" | ||
| "object" | ||
| "string" | ||
| "url" | ||
| "uuid" | ||
| string; | ||
type: "any"; | ||
} | ||
/** | ||
* Validation schema definition for "array" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#array | ||
*/ | ||
export interface RuleArray<T = any> extends RuleCustom { | ||
/** | ||
* Validation schema definition for "any" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#any | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleAny extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "any"; | ||
} | ||
type: "array"; | ||
/** | ||
* Validation schema definition for "array" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#array | ||
* If true, the validator accepts an empty array []. | ||
* @default true | ||
*/ | ||
export interface RuleArray<T = any> extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "array"; | ||
/** | ||
* If true, the validator accepts an empty array []. | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
/** | ||
* Minimum count of elements | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum count of elements | ||
*/ | ||
max?: number; | ||
/** | ||
* Fixed count of elements | ||
*/ | ||
length?: number; | ||
/** | ||
* The array must contain this element too | ||
*/ | ||
contains?: T | T[]; | ||
/** | ||
* Every element must be an element of the enum array | ||
*/ | ||
enum?: T[]; | ||
/** | ||
* Validation rules that should be applied to each element of array | ||
*/ | ||
items?: ValidationRule; | ||
} | ||
empty?: boolean; | ||
/** | ||
* Minimum count of elements | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum count of elements | ||
*/ | ||
max?: number; | ||
/** | ||
* Fixed count of elements | ||
*/ | ||
length?: number; | ||
/** | ||
* The array must contain this element too | ||
*/ | ||
contains?: T | T[]; | ||
/** | ||
* Every element must be an element of the enum array | ||
*/ | ||
enum?: T[]; | ||
/** | ||
* Validation rules that should be applied to each element of array | ||
*/ | ||
items?: ValidationRule; | ||
} | ||
/** | ||
* Validation schema definition for "boolean" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#boolean | ||
*/ | ||
export interface RuleBoolean extends RuleCustom { | ||
/** | ||
* Validation schema definition for "boolean" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#boolean | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleBoolean extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "boolean"; | ||
/** | ||
* if true and the type is not Boolean, try to convert. 1, "true", "1", "on" will be true. 0, "false", "0", "off" will be false. | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
} | ||
type: "boolean"; | ||
/** | ||
* if true and the type is not Boolean, try to convert. 1, "true", "1", "on" will be true. 0, "false", "0", "off" will be false. | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "class" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#class | ||
*/ | ||
export interface RuleClass<T = any> extends RuleCustom { | ||
/** | ||
* Validation schema definition for "class" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#class | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleClass<T = any> extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "class"; | ||
/** | ||
* Checked Class | ||
*/ | ||
instanceOf?: T; | ||
} | ||
type: "class"; | ||
/** | ||
* Checked Class | ||
*/ | ||
instanceOf?: T; | ||
} | ||
/** | ||
* Validation schema definition for "date" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#date | ||
*/ | ||
export interface RuleDate extends RuleCustom { | ||
/** | ||
* Validation schema definition for "date" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#date | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleDate extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "date"; | ||
/** | ||
* if true and the type is not Date, try to convert with new Date() | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
} | ||
type: "date"; | ||
/** | ||
* if true and the type is not Date, try to convert with new Date() | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "email" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#email | ||
*/ | ||
export interface RuleEmail extends RuleCustom { | ||
/** | ||
* Validation schema definition for "email" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#email | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleEmail extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "email"; | ||
/** | ||
* If true, the validator accepts an empty string "" | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
/** | ||
* Checker method. Can be quick or precise | ||
*/ | ||
mode?: "quick" | "precise"; | ||
/** | ||
* Minimum value length | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum value length | ||
*/ | ||
max?: number; | ||
type: "email"; | ||
/** | ||
* If true, the validator accepts an empty string "" | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
/** | ||
* Checker method. Can be quick or precise | ||
*/ | ||
mode?: "quick" | "precise"; | ||
/** | ||
* Minimum value length | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum value length | ||
*/ | ||
max?: number; | ||
normalize?: boolean; | ||
} | ||
normalize?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "enum" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#enum | ||
*/ | ||
export interface RuleEnum<T = any> extends RuleCustom { | ||
/** | ||
* Validation schema definition for "enum" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#enum | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleEnum<T = any> extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "enum"; | ||
/** | ||
* The valid values | ||
*/ | ||
values: T[]; | ||
} | ||
type: "enum"; | ||
/** | ||
* The valid values | ||
*/ | ||
values: T[]; | ||
} | ||
/** | ||
* Validation schema definition for "equal" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#equal | ||
*/ | ||
export interface RuleEqual<T = any> extends RuleCustom { | ||
/** | ||
* Validation schema definition for "equal" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#equal | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleEqual<T = any> extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "equal"; | ||
/** | ||
* The valid value | ||
*/ | ||
value?: T; | ||
type: "equal"; | ||
/** | ||
* The valid value | ||
*/ | ||
value?: T; | ||
/** | ||
* Another field name | ||
*/ | ||
field?: string; | ||
/** | ||
* Another field name | ||
*/ | ||
field?: string; | ||
/** | ||
* Strict value checking. | ||
* | ||
* @type {'boolean'} | ||
* @memberof RuleEqual | ||
*/ | ||
strict?: boolean; | ||
} | ||
/** | ||
* Strict value checking. | ||
* | ||
* @type {'boolean'} | ||
* @memberof RuleEqual | ||
*/ | ||
strict?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "forbidden" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#forbidden | ||
*/ | ||
export interface RuleForbidden extends RuleCustom { | ||
/** | ||
* Validation schema definition for "forbidden" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#forbidden | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleForbidden extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "forbidden"; | ||
type: "forbidden"; | ||
/** | ||
* Removes the forbidden value. | ||
* | ||
* @type {'boolean'} | ||
* @memberof RuleForbidden | ||
*/ | ||
remove?: boolean; | ||
} | ||
/** | ||
* Removes the forbidden value. | ||
* | ||
* @type {'boolean'} | ||
* @memberof RuleForbidden | ||
*/ | ||
remove?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "function" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#function | ||
*/ | ||
export interface RuleFunction extends RuleCustom { | ||
/** | ||
* Validation schema definition for "function" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#function | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleFunction extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "function"; | ||
} | ||
type: "function"; | ||
} | ||
/** | ||
* Validation schema definition for "luhn" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#luhn | ||
*/ | ||
export interface RuleLuhn extends RuleCustom { | ||
/** | ||
* Validation schema definition for "luhn" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#luhn | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleLuhn extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "luhn"; | ||
} | ||
type: "luhn"; | ||
} | ||
/** | ||
* Validation schema definition for "mac" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#mac | ||
*/ | ||
export interface RuleMac extends RuleCustom { | ||
/** | ||
* Validation schema definition for "mac" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#mac | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleMac extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "mac"; | ||
} | ||
type: "mac"; | ||
} | ||
/** | ||
* Validation schema definition for "multi" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#multi | ||
*/ | ||
export interface RuleMulti extends RuleCustom { | ||
/** | ||
* Validation schema definition for "multi" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#multi | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleMulti extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "multi"; | ||
type: "multi"; | ||
rules: RuleCustom[] | string[]; | ||
} | ||
rules: RuleCustom[] | string[]; | ||
} | ||
/** | ||
* Validation schema definition for "number" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#number | ||
*/ | ||
export interface RuleNumber extends RuleCustom { | ||
/** | ||
* Validation schema definition for "number" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#number | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleNumber extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "number"; | ||
/** | ||
* Minimum value | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum value | ||
*/ | ||
max?: number; | ||
/** | ||
* Fixed value | ||
*/ | ||
equal?: number; | ||
/** | ||
* Can't be equal to this value | ||
*/ | ||
notEqual?: number; | ||
/** | ||
* The value must be a non-decimal value | ||
* @default false | ||
*/ | ||
integer?: boolean; | ||
/** | ||
* The value must be greater than zero | ||
* @default false | ||
*/ | ||
positive?: boolean; | ||
/** | ||
* The value must be less than zero | ||
* @default false | ||
*/ | ||
negative?: boolean; | ||
/** | ||
* if true and the type is not Number, converts with Number() | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
} | ||
type: "number"; | ||
/** | ||
* Minimum value | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum value | ||
*/ | ||
max?: number; | ||
/** | ||
* Fixed value | ||
*/ | ||
equal?: number; | ||
/** | ||
* Can't be equal to this value | ||
*/ | ||
notEqual?: number; | ||
/** | ||
* The value must be a non-decimal value | ||
* @default false | ||
*/ | ||
integer?: boolean; | ||
/** | ||
* The value must be greater than zero | ||
* @default false | ||
*/ | ||
positive?: boolean; | ||
/** | ||
* The value must be less than zero | ||
* @default false | ||
*/ | ||
negative?: boolean; | ||
/** | ||
* if true and the type is not Number, converts with Number() | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "object" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#object | ||
*/ | ||
export interface RuleObject extends RuleCustom { | ||
/** | ||
* Validation schema definition for "object" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#object | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleObject extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "object"; | ||
/** | ||
* if true any properties which are not defined on the schema will throw an error. | ||
* @default false | ||
*/ | ||
strict?: boolean; | ||
/** | ||
* List of properties that should be validated by this rule | ||
*/ | ||
properties?: ValidationSchema; | ||
props?: ValidationSchema; | ||
/** | ||
* If set to a number, will throw if the number of props is less than that number. | ||
*/ | ||
minProps?: number; | ||
/** | ||
* If set to a number, will throw if the number of props is greater than that number. | ||
*/ | ||
maxProps?: number; | ||
} | ||
type: "object"; | ||
/** | ||
* if true any properties which are not defined on the schema will throw an error. | ||
* @default false | ||
*/ | ||
strict?: boolean; | ||
/** | ||
* List of properties that should be validated by this rule | ||
*/ | ||
properties?: ValidationSchema; | ||
props?: ValidationSchema; | ||
/** | ||
* If set to a number, will throw if the number of props is less than that number. | ||
*/ | ||
minProps?: number; | ||
/** | ||
* If set to a number, will throw if the number of props is greater than that number. | ||
*/ | ||
maxProps?: number; | ||
} | ||
export interface RuleObjectID extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "objectID"; | ||
/** | ||
* To inject ObjectID dependency | ||
*/ | ||
ObjectID?: { | ||
new (id?: string | number | ObjectIdAbstract): ObjectIdAbstract; | ||
isValid(o: any): boolean; | ||
}; | ||
/** | ||
* Convert HexStringObjectID to ObjectID | ||
*/ | ||
convert?: boolean | "hexString"; | ||
} | ||
export interface RuleObjectID extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "objectID"; | ||
/** | ||
* To inject ObjectID dependency | ||
*/ | ||
ObjectID?: any; | ||
/** | ||
* Convert HexStringObjectID to ObjectID | ||
*/ | ||
convert?: boolean | "hexString"; | ||
} | ||
/** | ||
* Validation schema definition for "string" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#string | ||
*/ | ||
export interface RuleString extends RuleCustom { | ||
/** | ||
* Validation schema definition for "string" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#string | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleString extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "string"; | ||
/** | ||
* If true, the validator accepts an empty string "" | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
/** | ||
* Minimum value length | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum value length | ||
*/ | ||
max?: number; | ||
/** | ||
* Fixed value length | ||
*/ | ||
length?: number; | ||
/** | ||
* Regex pattern | ||
*/ | ||
pattern?: string | RegExp; | ||
/** | ||
* The value must contain this text | ||
*/ | ||
contains?: string[]; | ||
/** | ||
* The value must be an element of the enum array | ||
*/ | ||
enum?: string[]; | ||
/** | ||
* The value must be an alphabetic string | ||
*/ | ||
numeric?: boolean; | ||
/** | ||
* The value must be a numeric string | ||
*/ | ||
alpha?: boolean; | ||
/** | ||
* The value must be an alphanumeric string | ||
*/ | ||
alphanum?: boolean; | ||
/** | ||
* The value must be an alphabetic string that contains dashes | ||
*/ | ||
alphadash?: boolean; | ||
/** | ||
* The value must be a hex string | ||
* @default false | ||
*/ | ||
hex?: boolean; | ||
/** | ||
* The value must be a singleLine string | ||
* @default false | ||
*/ | ||
singleLine?: boolean; | ||
/** | ||
* The value must be a base64 string | ||
* @default false | ||
*/ | ||
base64?: boolean; | ||
/** | ||
* if true and the type is not a String, converts with String() | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
type: "string"; | ||
/** | ||
* If true, the validator accepts an empty string "" | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
/** | ||
* Minimum value length | ||
*/ | ||
min?: number; | ||
/** | ||
* Maximum value length | ||
*/ | ||
max?: number; | ||
/** | ||
* Fixed value length | ||
*/ | ||
length?: number; | ||
/** | ||
* Regex pattern | ||
*/ | ||
pattern?: string | RegExp; | ||
/** | ||
* The value must contain this text | ||
*/ | ||
contains?: string[]; | ||
/** | ||
* The value must be an element of the enum array | ||
*/ | ||
enum?: string[]; | ||
/** | ||
* The value must be an alphabetic string | ||
*/ | ||
numeric?: boolean; | ||
/** | ||
* The value must be a numeric string | ||
*/ | ||
alpha?: boolean; | ||
/** | ||
* The value must be an alphanumeric string | ||
*/ | ||
alphanum?: boolean; | ||
/** | ||
* The value must be an alphabetic string that contains dashes | ||
*/ | ||
alphadash?: boolean; | ||
/** | ||
* The value must be a hex string | ||
* @default false | ||
*/ | ||
hex?: boolean; | ||
/** | ||
* The value must be a singleLine string | ||
* @default false | ||
*/ | ||
singleLine?: boolean; | ||
/** | ||
* The value must be a base64 string | ||
* @default false | ||
*/ | ||
base64?: boolean; | ||
/** | ||
* if true and the type is not a String, converts with String() | ||
* @default false | ||
*/ | ||
convert?: boolean; | ||
trim?: boolean; | ||
trimLeft?: boolean; | ||
trimRight?: boolean; | ||
trim?: boolean; | ||
trimLeft?: boolean; | ||
trimRight?: boolean; | ||
padStart?: number; | ||
padEnd?: number; | ||
padChar?: string; | ||
padStart?: number; | ||
padEnd?: number; | ||
padChar?: string; | ||
lowercase?: boolean; | ||
uppercase?: boolean; | ||
localeLowercase?: boolean; | ||
localeUppercase?: boolean; | ||
} | ||
lowercase?: boolean; | ||
uppercase?: boolean; | ||
localeLowercase?: boolean; | ||
localeUppercase?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "tuple" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#array | ||
*/ | ||
export interface RuleTuple<T = any> extends RuleCustom { | ||
/** | ||
* Validation schema definition for "tuple" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#array | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleTuple<T = any> extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "tuple"; | ||
/** | ||
* Validation rules that should be applied to the corresponding element of array | ||
*/ | ||
items?: [ValidationRule, ValidationRule]; | ||
} | ||
type: "tuple"; | ||
/** | ||
* Validation rules that should be applied to the corresponding element of array | ||
*/ | ||
items?: [ValidationRule, ValidationRule]; | ||
} | ||
/** | ||
* Validation schema definition for "url" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#url | ||
*/ | ||
export interface RuleURL extends RuleCustom { | ||
/** | ||
* Validation schema definition for "url" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#url | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleURL extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "url"; | ||
/** | ||
* If true, the validator accepts an empty string "" | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
} | ||
type: "url"; | ||
/** | ||
* If true, the validator accepts an empty string "" | ||
* @default true | ||
*/ | ||
empty?: boolean; | ||
} | ||
/** | ||
* Validation schema definition for "uuid" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#uuid | ||
*/ | ||
export interface RuleUUID extends RuleCustom { | ||
/** | ||
* Validation schema definition for "uuid" built-in validator | ||
* @see https://github.com/icebob/fastest-validator#uuid | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleUUID extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "uuid"; | ||
/** | ||
* UUID version in range 0-6 | ||
*/ | ||
version?: 0 | 1 | 2 | 3 | 4 | 5 | 6; | ||
} | ||
type: "uuid"; | ||
/** | ||
* UUID version in range 0-6 | ||
*/ | ||
version?: 0 | 1 | 2 | 3 | 4 | 5 | 6; | ||
} | ||
/** | ||
* Validation schema definition for custom inline validator | ||
* @see https://github.com/icebob/fastest-validator#custom-validator | ||
*/ | ||
export interface RuleCustomInline<T = any> extends RuleCustom { | ||
/** | ||
* Validation schema definition for custom inline validator | ||
* @see https://github.com/icebob/fastest-validator#custom-validator | ||
* Name of built-in validator | ||
*/ | ||
export interface RuleCustomInline<T = any> extends RuleCustom { | ||
/** | ||
* Name of built-in validator | ||
*/ | ||
type: "custom"; | ||
/** | ||
* Custom checker function | ||
*/ | ||
check: CheckerFunction<T>; | ||
} | ||
type: "custom"; | ||
/** | ||
* Custom checker function | ||
*/ | ||
check: CheckerFunction<T>; | ||
} | ||
/** | ||
* Validation schema definition for custom validator | ||
* @see https://github.com/icebob/fastest-validator#custom-validator | ||
*/ | ||
export interface RuleCustom { | ||
/** | ||
* Validation schema definition for custom validator | ||
* @see https://github.com/icebob/fastest-validator#custom-validator | ||
* Name of custom validator that will be used in validation rules | ||
*/ | ||
export interface RuleCustom { | ||
/** | ||
* Name of custom validator that will be used in validation rules | ||
*/ | ||
type: string; | ||
/** | ||
* Every field in the schema will be required by default. If you'd like to define optional fields, set optional: true. | ||
* @default false | ||
*/ | ||
optional?: boolean; | ||
type: string; | ||
/** | ||
* Every field in the schema will be required by default. If you'd like to define optional fields, set optional: true. | ||
* @default false | ||
*/ | ||
optional?: boolean; | ||
/** | ||
* If you want disallow `undefined` value but allow `null` value, use `nullable` instead of `optional`. | ||
* @default false | ||
*/ | ||
nullable?: boolean; | ||
/** | ||
* If you want disallow `undefined` value but allow `null` value, use `nullable` instead of `optional`. | ||
* @default false | ||
*/ | ||
nullable?: boolean; | ||
/** | ||
* You can set your custom messages in the validator constructor | ||
* Sometimes the standard messages are too generic. You can customise messages per validation type per field | ||
*/ | ||
messages?: MessagesType; | ||
/** | ||
* You can set your custom messages in the validator constructor | ||
* Sometimes the standard messages are too generic. You can customise messages per validation type per field | ||
*/ | ||
messages?: MessagesType; | ||
/** | ||
* Default value | ||
*/ | ||
default?: any; | ||
/** | ||
* Default value | ||
*/ | ||
default?: any; | ||
/** | ||
* Custom checker function | ||
*/ | ||
custom?: CheckerFunction; | ||
/** | ||
* Custom checker function | ||
*/ | ||
custom?: CheckerFunction; | ||
/** | ||
* You can define any additional options for custom validators | ||
*/ | ||
[key: string]: any; | ||
} | ||
/** | ||
* You can define any additional options for custom validators | ||
*/ | ||
[key: string]: any; | ||
} | ||
/** | ||
* List of all possible keys that can be used for error message override | ||
*/ | ||
export interface BuiltInMessages { | ||
/** | ||
* List of all possible keys that can be used for error message override | ||
* The '{field}' field is required. | ||
*/ | ||
export interface BuiltInMessages { | ||
/** | ||
* The '{field}' field is required. | ||
*/ | ||
required?: string; | ||
/** | ||
* The '{field}' field must be a string. | ||
*/ | ||
string?: string; | ||
/** | ||
* The '{field}' field must not be empty. | ||
*/ | ||
stringEmpty?: string; | ||
/** | ||
* The '{field}' field length must be greater than or equal to {expected} characters long. | ||
*/ | ||
stringMin?: string; | ||
/** | ||
* The '{field}' field length must be less than or equal to {expected} characters long. | ||
*/ | ||
stringMax?: string; | ||
/** | ||
* The '{field}' field length must be {expected} characters long. | ||
*/ | ||
stringLength?: string; | ||
/** | ||
* The '{field}' field fails to match the required pattern. | ||
*/ | ||
stringPattern?: string; | ||
/** | ||
* The '{field}' field must contain the '{expected}' text. | ||
*/ | ||
stringContains?: string; | ||
/** | ||
* The '{field}' field does not match any of the allowed values. | ||
*/ | ||
stringEnum?: string; | ||
/** | ||
* The '{field}' field must be a numeric string. | ||
*/ | ||
stringNumeric?: string; | ||
/** | ||
* The '{field}' field must be an alphabetic string. | ||
*/ | ||
stringAlpha?: string; | ||
/** | ||
* The '{field}' field must be an alphanumeric string. | ||
*/ | ||
stringAlphanum?: string; | ||
/** | ||
* The '{field}' field must be an alphadash string. | ||
*/ | ||
stringAlphadash?: string; | ||
required?: string; | ||
/** | ||
* The '{field}' field must be a string. | ||
*/ | ||
string?: string; | ||
/** | ||
* The '{field}' field must not be empty. | ||
*/ | ||
stringEmpty?: string; | ||
/** | ||
* The '{field}' field length must be greater than or equal to {expected} characters long. | ||
*/ | ||
stringMin?: string; | ||
/** | ||
* The '{field}' field length must be less than or equal to {expected} characters long. | ||
*/ | ||
stringMax?: string; | ||
/** | ||
* The '{field}' field length must be {expected} characters long. | ||
*/ | ||
stringLength?: string; | ||
/** | ||
* The '{field}' field fails to match the required pattern. | ||
*/ | ||
stringPattern?: string; | ||
/** | ||
* The '{field}' field must contain the '{expected}' text. | ||
*/ | ||
stringContains?: string; | ||
/** | ||
* The '{field}' field does not match any of the allowed values. | ||
*/ | ||
stringEnum?: string; | ||
/** | ||
* The '{field}' field must be a numeric string. | ||
*/ | ||
stringNumeric?: string; | ||
/** | ||
* The '{field}' field must be an alphabetic string. | ||
*/ | ||
stringAlpha?: string; | ||
/** | ||
* The '{field}' field must be an alphanumeric string. | ||
*/ | ||
stringAlphanum?: string; | ||
/** | ||
* The '{field}' field must be an alphadash string. | ||
*/ | ||
stringAlphadash?: string; | ||
/** | ||
* The '{field}' field must be a number. | ||
*/ | ||
number?: string; | ||
/** | ||
* The '{field}' field must be greater than or equal to {expected}. | ||
*/ | ||
numberMin?: string; | ||
/** | ||
* The '{field}' field must be less than or equal to {expected}. | ||
*/ | ||
numberMax?: string; | ||
/** | ||
* The '{field}' field must be equal with {expected}. | ||
*/ | ||
numberEqual?: string; | ||
/** | ||
* The '{field}' field can't be equal with {expected}. | ||
*/ | ||
numberNotEqual?: string; | ||
/** | ||
* The '{field}' field must be an integer. | ||
*/ | ||
numberInteger?: string; | ||
/** | ||
* The '{field}' field must be a positive number. | ||
*/ | ||
numberPositive?: string; | ||
/** | ||
* The '{field}' field must be a negative number. | ||
*/ | ||
numberNegative?: string; | ||
/** | ||
* The '{field}' field must be a number. | ||
*/ | ||
number?: string; | ||
/** | ||
* The '{field}' field must be greater than or equal to {expected}. | ||
*/ | ||
numberMin?: string; | ||
/** | ||
* The '{field}' field must be less than or equal to {expected}. | ||
*/ | ||
numberMax?: string; | ||
/** | ||
* The '{field}' field must be equal with {expected}. | ||
*/ | ||
numberEqual?: string; | ||
/** | ||
* The '{field}' field can't be equal with {expected}. | ||
*/ | ||
numberNotEqual?: string; | ||
/** | ||
* The '{field}' field must be an integer. | ||
*/ | ||
numberInteger?: string; | ||
/** | ||
* The '{field}' field must be a positive number. | ||
*/ | ||
numberPositive?: string; | ||
/** | ||
* The '{field}' field must be a negative number. | ||
*/ | ||
numberNegative?: string; | ||
/** | ||
* The '{field}' field must be an array. | ||
*/ | ||
array?: string; | ||
/** | ||
* The '{field}' field must not be an empty array. | ||
*/ | ||
arrayEmpty?: string; | ||
/** | ||
* The '{field}' field must contain at least {expected} items. | ||
*/ | ||
arrayMin?: string; | ||
/** | ||
* The '{field}' field must contain less than or equal to {expected} items. | ||
*/ | ||
arrayMax?: string; | ||
/** | ||
* The '{field}' field must contain {expected} items. | ||
*/ | ||
arrayLength?: string; | ||
/** | ||
* The '{field}' field must contain the '{expected}' item. | ||
*/ | ||
arrayContains?: string; | ||
/** | ||
* The '{field} field value '{expected}' does not match any of the allowed values. | ||
*/ | ||
arrayEnum?: string; | ||
/** | ||
* The '{field}' field must be an array. | ||
*/ | ||
array?: string; | ||
/** | ||
* The '{field}' field must not be an empty array. | ||
*/ | ||
arrayEmpty?: string; | ||
/** | ||
* The '{field}' field must contain at least {expected} items. | ||
*/ | ||
arrayMin?: string; | ||
/** | ||
* The '{field}' field must contain less than or equal to {expected} items. | ||
*/ | ||
arrayMax?: string; | ||
/** | ||
* The '{field}' field must contain {expected} items. | ||
*/ | ||
arrayLength?: string; | ||
/** | ||
* The '{field}' field must contain the '{expected}' item. | ||
*/ | ||
arrayContains?: string; | ||
/** | ||
* The '{field} field value '{expected}' does not match any of the allowed values. | ||
*/ | ||
arrayEnum?: string; | ||
/** | ||
* The '{field}' field must be a boolean. | ||
*/ | ||
boolean?: string; | ||
/** | ||
* The '{field}' field must be a boolean. | ||
*/ | ||
boolean?: string; | ||
/** | ||
* The '{field}' field must be a Date. | ||
*/ | ||
date?: string; | ||
/** | ||
* The '{field}' field must be greater than or equal to {expected}. | ||
*/ | ||
dateMin?: string; | ||
/** | ||
* The '{field}' field must be less than or equal to {expected}. | ||
*/ | ||
dateMax?: string; | ||
/** | ||
* The '{field}' field must be a Date. | ||
*/ | ||
date?: string; | ||
/** | ||
* The '{field}' field must be greater than or equal to {expected}. | ||
*/ | ||
dateMin?: string; | ||
/** | ||
* The '{field}' field must be less than or equal to {expected}. | ||
*/ | ||
dateMax?: string; | ||
/** | ||
* The '{field}' field value '{expected}' does not match any of the allowed values. | ||
*/ | ||
enumValue?: string; | ||
/** | ||
* The '{field}' field value '{expected}' does not match any of the allowed values. | ||
*/ | ||
enumValue?: string; | ||
/** | ||
* The '{field}' field value must be equal to '{expected}'. | ||
*/ | ||
equalValue?: string; | ||
/** | ||
* The '{field}' field value must be equal to '{expected}' field value. | ||
*/ | ||
equalField?: string; | ||
/** | ||
* The '{field}' field value must be equal to '{expected}'. | ||
*/ | ||
equalValue?: string; | ||
/** | ||
* The '{field}' field value must be equal to '{expected}' field value. | ||
*/ | ||
equalField?: string; | ||
/** | ||
* The '{field}' field is forbidden. | ||
*/ | ||
forbidden?: string; | ||
/** | ||
* The '{field}' field is forbidden. | ||
*/ | ||
forbidden?: string; | ||
/** | ||
* The '{field}' field must be a function. | ||
*/ | ||
function?: string; | ||
/** | ||
* The '{field}' field must be a function. | ||
*/ | ||
function?: string; | ||
/** | ||
* The '{field}' field must be a valid e-mail. | ||
*/ | ||
email?: string; | ||
/** | ||
* The '{field}' field must be a valid e-mail. | ||
*/ | ||
email?: string; | ||
/** | ||
* The '{field}' field must be a valid checksum luhn. | ||
*/ | ||
luhn?: string; | ||
/** | ||
* The '{field}' field must be a valid checksum luhn. | ||
*/ | ||
luhn?: string; | ||
/** | ||
* The '{field}' field must be a valid MAC address. | ||
*/ | ||
mac?: string; | ||
/** | ||
* The '{field}' field must be a valid MAC address. | ||
*/ | ||
mac?: string; | ||
/** | ||
* The '{field}' must be an Object. | ||
*/ | ||
object?: string; | ||
/** | ||
* The object '{field}' contains forbidden keys: '{actual}'. | ||
*/ | ||
objectStrict?: string; | ||
/** | ||
* The '{field}' must be an Object. | ||
*/ | ||
object?: string; | ||
/** | ||
* The object '{field}' contains forbidden keys: '{actual}'. | ||
*/ | ||
objectStrict?: string; | ||
/** | ||
* The '{field}' field must be a valid URL. | ||
*/ | ||
url?: string; | ||
/** | ||
* The '{field}' field must be a valid URL. | ||
*/ | ||
url?: string; | ||
/** | ||
* The '{field}' field must be a valid UUID. | ||
*/ | ||
uuid?: string; | ||
/** | ||
* The '{field}' field must be a valid UUID version provided. | ||
*/ | ||
uuidVersion?: string; | ||
} | ||
/** | ||
* Type with description of custom error messages | ||
* The '{field}' field must be a valid UUID. | ||
*/ | ||
export type MessagesType = BuiltInMessages & { [key: string]: string }; | ||
uuid?: string; | ||
/** | ||
* The '{field}' field must be a valid UUID version provided. | ||
*/ | ||
uuidVersion?: string; | ||
} | ||
/** | ||
* Type with description of custom error messages | ||
*/ | ||
export type MessagesType = BuiltInMessages & { [key: string]: string }; | ||
/** | ||
* Union type of all possible built-in validators | ||
*/ | ||
export type ValidationRuleObject = | ||
| RuleAny | ||
| RuleArray | ||
| RuleBoolean | ||
| RuleClass | ||
| RuleDate | ||
| RuleEmail | ||
| RuleEqual | ||
| RuleEnum | ||
| RuleForbidden | ||
| RuleFunction | ||
| RuleLuhn | ||
| RuleMac | ||
| RuleMulti | ||
| RuleNumber | ||
| RuleObject | ||
| RuleObjectID | ||
| RuleString | ||
| RuleTuple | ||
| RuleURL | ||
| RuleUUID | ||
| RuleCustom | ||
| RuleCustomInline; | ||
/** | ||
* Description of validation rule definition for a some property | ||
*/ | ||
export type ValidationRule = | ||
| ValidationRuleObject | ||
| ValidationRuleObject[] | ||
| ValidationRuleName; | ||
/** | ||
* Definition for validation schema based on validation rules | ||
*/ | ||
export type ValidationSchema<T = any> = { | ||
/** | ||
* Union type of all possible built-in validators | ||
* Object properties which are not specified on the schema are ignored by default. | ||
* If you set the $$strict option to true any additional properties will result in an strictObject error. | ||
* @default false | ||
*/ | ||
export type ValidationRuleObject = | ||
| RuleAny | ||
| RuleArray | ||
| RuleBoolean | ||
| RuleClass | ||
| RuleDate | ||
| RuleEmail | ||
| RuleEqual | ||
| RuleEnum | ||
| RuleForbidden | ||
| RuleFunction | ||
| RuleLuhn | ||
| RuleMac | ||
| RuleMulti | ||
| RuleNumber | ||
| RuleObject | ||
| RuleObjectID | ||
| RuleString | ||
| RuleTuple | ||
| RuleURL | ||
| RuleUUID | ||
| RuleCustom | ||
| RuleCustomInline; | ||
$$strict?: boolean | "remove"; | ||
/** | ||
* Description of validation rule definition for a some property | ||
* Enable asynchronous functionality. In this case the `validate` and `compile` methods return a `Promise`. | ||
* @default false | ||
*/ | ||
export type ValidationRule = | ||
| ValidationRuleObject | ||
| ValidationRuleObject[] | ||
| ValidationRuleName; | ||
$$async?: boolean; | ||
/** | ||
* Definition for validation schema based on validation rules | ||
* Basically the validator expects that you want to validate a Javascript object. | ||
* If you want others, you can define the root level schema. | ||
* @default false | ||
*/ | ||
export type ValidationSchema<T = any> = { | ||
$$root?: boolean; | ||
} & { | ||
/** | ||
* Object properties which are not specified on the schema are ignored by default. | ||
* If you set the $$strict option to true any additional properties will result in an strictObject error. | ||
* @default false | ||
*/ | ||
$$strict?: boolean | "remove"; | ||
/** | ||
* Enable asynchronous functionality. In this case the `validate` and `compile` methods return a `Promise`. | ||
* @default false | ||
*/ | ||
$$async?: boolean; | ||
/** | ||
* Basically the validator expects that you want to validate a Javascript object. | ||
* If you want others, you can define the root level schema. | ||
* @default false | ||
*/ | ||
$$root?: boolean; | ||
} & { | ||
/** | ||
* List of validation rules for each defined field | ||
@@ -820,245 +814,238 @@ */ | ||
/** | ||
* Structure with description of validation error message | ||
*/ | ||
export interface ValidationError { | ||
/** | ||
* Structure with description of validation error message | ||
* Name of validation rule that generates this message | ||
*/ | ||
export interface ValidationError { | ||
/** | ||
* Name of validation rule that generates this message | ||
*/ | ||
type: keyof BuiltInMessages | string; | ||
/** | ||
* Field that catch validation error | ||
*/ | ||
field: string; | ||
/** | ||
* Description of current validation error | ||
*/ | ||
message?: string; | ||
/** | ||
* Expected value from validation rule | ||
*/ | ||
expected?: any; | ||
/** | ||
* Actual value received by validation rule | ||
*/ | ||
actual?: any; | ||
} | ||
type: keyof BuiltInMessages | string; | ||
/** | ||
* Field that catch validation error | ||
*/ | ||
field: string; | ||
/** | ||
* Description of current validation error | ||
*/ | ||
message?: string; | ||
/** | ||
* Expected value from validation rule | ||
*/ | ||
expected?: any; | ||
/** | ||
* Actual value received by validation rule | ||
*/ | ||
actual?: any; | ||
} | ||
/** | ||
* List of possible validator constructor options | ||
*/ | ||
export interface ValidatorConstructorOptions { | ||
debug?: boolean; | ||
/** | ||
* List of possible validator constructor options | ||
* List of possible error messages | ||
*/ | ||
export interface ValidatorConstructorOptions { | ||
debug?: boolean; | ||
/** | ||
* List of possible error messages | ||
*/ | ||
messages?: MessagesType; | ||
messages?: MessagesType; | ||
/** | ||
* using checker function v2? | ||
*/ | ||
useNewCustomCheckerFunction?: boolean; | ||
/** | ||
* using checker function v2? | ||
*/ | ||
useNewCustomCheckerFunction?: boolean; | ||
/** | ||
* Default settings for rules | ||
*/ | ||
defaults?: { | ||
[key in ValidationRuleName]: ValidationSchema; | ||
}; | ||
/** | ||
* Default settings for rules | ||
*/ | ||
defaults?: { | ||
[key in ValidationRuleName]: ValidationSchema; | ||
}; | ||
/** | ||
* For set aliases | ||
*/ | ||
aliases?: { | ||
[key: string]: ValidationRuleObject; | ||
}; | ||
/** | ||
* For set aliases | ||
*/ | ||
aliases?: { | ||
[key: string]: ValidationRuleObject; | ||
}; | ||
/** | ||
* For set custom rules. | ||
*/ | ||
customRules?: { | ||
[key: string]: CompilationFunction; | ||
}; | ||
/** | ||
* For set custom rules. | ||
*/ | ||
customRules?: { | ||
[key: string]: CompilationFunction; | ||
}; | ||
/** | ||
* For set plugins. | ||
*/ | ||
plugins?: PluginFn<any>[]; | ||
} | ||
/** | ||
* For set plugins. | ||
*/ | ||
plugins?: PluginFn<any>[]; | ||
} | ||
export interface CompilationRule { | ||
index: number; | ||
ruleFunction: CompilationFunction; | ||
schema: ValidationSchema; | ||
messages: MessagesType; | ||
} | ||
export interface CompilationRule { | ||
index: number; | ||
ruleFunction: CompilationFunction; | ||
schema: ValidationSchema; | ||
messages: MessagesType; | ||
} | ||
export interface Context { | ||
index: number; | ||
async: boolean; | ||
rules: ValidationRuleObject[]; | ||
fn: Function[]; | ||
customs: { | ||
[ruleName: string]: { schema: RuleCustom; messages: MessagesType }; | ||
}; | ||
meta?: object; | ||
} | ||
export interface Context { | ||
index: number; | ||
async: boolean; | ||
rules: ValidationRuleObject[]; | ||
fn: Function[]; | ||
customs: { | ||
[ruleName: string]: { schema: RuleCustom; messages: MessagesType }; | ||
}; | ||
meta?: object; | ||
} | ||
export interface CheckerFunctionError { | ||
type: string; | ||
expected?: unknown; | ||
actual?: unknown; | ||
field?: string; | ||
} | ||
export interface CheckerFunctionError { | ||
type: string; | ||
expected?: unknown; | ||
actual?: unknown; | ||
field?: string; | ||
} | ||
export type CheckerFunctionV1<T = unknown> = ( | ||
value: T, | ||
ruleSchema: ValidationRuleObject, | ||
path: string, | ||
parent: object | null, | ||
context: Context | ||
) => true | ValidationError[]; | ||
export type CheckerFunctionV2<T = unknown> = ( | ||
value: T, | ||
errors: CheckerFunctionError[], | ||
ruleSchema: ValidationRuleObject, | ||
path: string, | ||
parent: object | null, | ||
context: Context | ||
) => T; | ||
export type CheckerFunctionV1<T = unknown> = ( | ||
value: T, | ||
ruleSchema: ValidationRuleObject, | ||
path: string, | ||
parent: object | null, | ||
context: Context | ||
) => true | ValidationError[]; | ||
export type CheckerFunctionV2<T = unknown> = ( | ||
value: T, | ||
errors: CheckerFunctionError[], | ||
ruleSchema: ValidationRuleObject, | ||
path: string, | ||
parent: object | null, | ||
context: Context | ||
) => T; | ||
export type CheckerFunction<T = unknown> = | ||
| CheckerFunctionV1<T> | ||
| CheckerFunctionV2<T>; | ||
export type CheckerFunction<T = unknown> = | ||
| CheckerFunctionV1<T> | ||
| CheckerFunctionV2<T>; | ||
export type CompilationFunction = ( | ||
rule: CompilationRule, | ||
path: string, | ||
context: Context | ||
) => { sanitized?: boolean; source: string }; | ||
export type CompilationFunction = ( | ||
rule: CompilationRule, | ||
path: string, | ||
context: Context | ||
) => { sanitized?: boolean; source: string }; | ||
export type PluginFn<T = void> = (validator: Validator) => T; | ||
export type PluginFn<T = void> = (validator: Validator) => T; | ||
export class ObjectIdAbstract { | ||
static isValid(o: any): boolean; | ||
constructor(id?: string | number | ObjectIdAbstract); | ||
toHexString(): string; | ||
} | ||
export interface CheckFunctionOptions { | ||
meta?: object | null; | ||
} | ||
export interface CheckFunctionOptions { | ||
meta?: object | null; | ||
} | ||
export interface SyncCheckFunction { | ||
(value: any, opts?: CheckFunctionOptions): true | ValidationError[] | ||
async: false | ||
} | ||
export interface SyncCheckFunction { | ||
(value: any, opts?: CheckFunctionOptions): true | ValidationError[] | ||
async: false | ||
} | ||
export interface AsyncCheckFunction { | ||
(value: any, opts?: CheckFunctionOptions): Promise<true | ValidationError[]> | ||
async: true | ||
} | ||
export interface AsyncCheckFunction { | ||
(value: any, opts?: CheckFunctionOptions): Promise<true | ValidationError[]> | ||
async: true | ||
} | ||
export default class Validator { | ||
/** | ||
* List of possible error messages | ||
*/ | ||
messages: MessagesType; | ||
export default class Validator { | ||
/** | ||
* List of possible error messages | ||
*/ | ||
messages: MessagesType; | ||
/** | ||
* List of rules attached to current validator | ||
*/ | ||
rules: { [key: string]: ValidationRuleObject }; | ||
/** | ||
* List of rules attached to current validator | ||
*/ | ||
rules: { [key: string]: ValidationRuleObject }; | ||
/** | ||
* List of aliases attached to current validator | ||
*/ | ||
aliases: { [key: string]: ValidationRule }; | ||
/** | ||
* List of aliases attached to current validator | ||
*/ | ||
aliases: { [key: string]: ValidationRule }; | ||
/** | ||
* Constructor of validation class | ||
* @param {ValidatorConstructorOptions} opts List of possible validator constructor options | ||
*/ | ||
constructor(opts?: ValidatorConstructorOptions); | ||
/** | ||
* Constructor of validation class | ||
* @param {ValidatorConstructorOptions} opts List of possible validator constructor options | ||
*/ | ||
constructor(opts?: ValidatorConstructorOptions); | ||
/** | ||
* Register a custom validation rule in validation object | ||
* @param {string} type | ||
* @param fn | ||
*/ | ||
add(type: string, fn: CompilationFunction): void; | ||
/** | ||
* Register a custom validation rule in validation object | ||
* @param {string} type | ||
* @param fn | ||
*/ | ||
add(type: string, fn: CompilationFunction): void; | ||
/** | ||
* Add a message | ||
* | ||
* @param {String} name | ||
* @param {String} message | ||
*/ | ||
addMessage(name: string, message: string): void; | ||
/** | ||
* Add a message | ||
* | ||
* @param {String} name | ||
* @param {String} message | ||
*/ | ||
addMessage(name: string, message: string): void; | ||
/** | ||
* Register an alias in validation object | ||
* @param {string} name | ||
* @param {ValidationRuleObject} validationRule | ||
*/ | ||
alias(name: string, validationRule: ValidationRuleObject): void; | ||
/** | ||
* Register an alias in validation object | ||
* @param {string} name | ||
* @param {ValidationRuleObject} validationRule | ||
*/ | ||
alias(name: string, validationRule: ValidationRuleObject): void; | ||
/** | ||
* Add a plugin | ||
* | ||
* @param {Function} fn | ||
*/ | ||
plugin<T = void>(fn: PluginFn<T>): T; | ||
/** | ||
* Add a plugin | ||
* | ||
* @param {Function} fn | ||
*/ | ||
plugin<T = void>(fn: PluginFn<T>): T; | ||
/** | ||
* Build error message | ||
* @return {ValidationError} | ||
* @param {Object} opts | ||
* @param {String} opts.type | ||
* @param {String} opts.field | ||
* @param {any=} opts.expected | ||
* @param {any=} opts.actual | ||
* @param {MessagesType} opts.messages | ||
*/ | ||
makeError(opts: { | ||
type: keyof MessagesType; | ||
field?: string; | ||
expected?: any; | ||
actual?: any; | ||
messages: MessagesType; | ||
}): string; | ||
/** | ||
* Build error message | ||
* @return {ValidationError} | ||
* @param {Object} opts | ||
* @param {String} opts.type | ||
* @param {String} opts.field | ||
* @param {any=} opts.expected | ||
* @param {any=} opts.actual | ||
* @param {MessagesType} opts.messages | ||
*/ | ||
makeError(opts: { | ||
type: keyof MessagesType; | ||
field?: string; | ||
expected?: any; | ||
actual?: any; | ||
messages: MessagesType; | ||
}): string; | ||
/** | ||
* Compile validator functions that working up 100 times faster that native validation process | ||
* @param {ValidationSchema | ValidationSchema[]} schema Validation schema definition that should be used for validation | ||
* @return {(value: any) => (true | ValidationError[])} function that can be used next for validation of current schema | ||
*/ | ||
compile<T = any>( | ||
schema: ValidationSchema<T> | ValidationSchema<T>[] | ||
): SyncCheckFunction | AsyncCheckFunction; | ||
/** | ||
* Compile validator functions that working up 100 times faster that native validation process | ||
* @param {ValidationSchema | ValidationSchema[]} schema Validation schema definition that should be used for validation | ||
* @return {(value: any) => (true | ValidationError[])} function that can be used next for validation of current schema | ||
*/ | ||
compile<T = any>( | ||
schema: ValidationSchema<T> | ValidationSchema<T>[] | ||
): SyncCheckFunction | AsyncCheckFunction; | ||
/** | ||
* Native validation method to validate obj | ||
* @param {any} value that should be validated | ||
* @param {ValidationSchema} schema Validation schema definition that should be used for validation | ||
* @return {{true} | ValidationError[]} | ||
*/ | ||
validate( | ||
value: any, | ||
schema: ValidationSchema | ||
): true | ValidationError[] | Promise<true | ValidationError[]>; | ||
/** | ||
* Native validation method to validate obj | ||
* @param {any} value that should be validated | ||
* @param {ValidationSchema} schema Validation schema definition that should be used for validation | ||
* @return {{true} | ValidationError[]} | ||
*/ | ||
validate( | ||
value: any, | ||
schema: ValidationSchema | ||
): true | ValidationError[] | Promise<true | ValidationError[]>; | ||
/** | ||
* Get defined in validator rule | ||
* @param {ValidationRuleName | ValidationRuleName[]} name List or name of defined rule | ||
* @return {ValidationRule} | ||
*/ | ||
getRuleFromSchema( | ||
name: ValidationRuleName | ValidationRuleName[] | { [key: string]: unknown } | ||
): { | ||
messages: MessagesType; | ||
schema: ValidationSchema; | ||
ruleFunction: Function; | ||
}; | ||
} | ||
/** | ||
* Get defined in validator rule | ||
* @param {ValidationRuleName | ValidationRuleName[]} name List or name of defined rule | ||
* @return {ValidationRule} | ||
*/ | ||
getRuleFromSchema( | ||
name: ValidationRuleName | ValidationRuleName[] | { [key: string]: unknown } | ||
): { | ||
messages: MessagesType; | ||
schema: ValidationSchema; | ||
ruleFunction: Function; | ||
}; | ||
} |
@@ -8,4 +8,4 @@ "use strict"; | ||
//const flatten = require("./helpers/flatten"); | ||
const deepExtend = require("./helpers/deep-extend"); | ||
const replace = require("./helpers/replace"); | ||
@@ -82,2 +82,12 @@ function loadMessages() { | ||
} | ||
/* istanbul ignore next */ | ||
if (this.opts.debug) { | ||
let formatter = function (code) { return code; }; | ||
if (typeof window === "undefined") { | ||
formatter = require("./helpers/prettier"); | ||
} | ||
this._formatter = formatter; | ||
} | ||
} | ||
@@ -162,3 +172,6 @@ } | ||
fn: [], | ||
customs: {} | ||
customs: {}, | ||
utils: { | ||
replace, | ||
}, | ||
}; | ||
@@ -201,7 +214,7 @@ this.cache.clear(); | ||
return errors.map(err => { | ||
if (err.message) | ||
err.message = err.message | ||
.replace(/\\{field\\}/g, err.field || "") | ||
.replace(/\\{expected\\}/g, err.expected != null ? err.expected : "") | ||
.replace(/\\{actual\\}/g, err.actual != null ? err.actual : ""); | ||
if (err.message) { | ||
err.message = context.utils.replace(err.message, /\\{field\\}/g, err.field); | ||
err.message = context.utils.replace(err.message, /\\{expected\\}/g, err.expected); | ||
err.message = context.utils.replace(err.message, /\\{actual\\}/g, err.actual); | ||
} | ||
@@ -222,8 +235,3 @@ return err; | ||
if (this.opts.debug) { | ||
let formatter = function (code) { return code; }; | ||
if (typeof window === "undefined") // eslint-disable-line no-undef | ||
formatter = require("./helpers/prettier"); | ||
context.fn.forEach((fn, i) => console.log(formatter(`// Context.fn[${i}]\n` + fn.toString()))); // eslint-disable-line no-console | ||
console.log(formatter("// Main check function\n" + checkFn.toString())); // eslint-disable-line no-console | ||
console.log(this._formatter("// Main check function\n" + checkFn.toString())); // eslint-disable-line no-console | ||
} | ||
@@ -285,2 +293,7 @@ | ||
sourceCode.push(this.makeCustomValidator({vName: resVar, path: customPath, schema: rule.schema, context, messages: rule.messages, ruleIndex: rule.index})); | ||
/* istanbul ignore next */ | ||
if (this.opts.debug) { | ||
console.log(this._formatter(`// Context.fn[${rule.index}]\n` + fn.toString())); // eslint-disable-line no-console | ||
} | ||
} | ||
@@ -287,0 +300,0 @@ |
{ | ||
"name": "fastest-validator", | ||
"version": "1.11.0", | ||
"version": "1.11.1", | ||
"description": "The fastest JS validator library for NodeJS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
374
README.md
@@ -130,2 +130,3 @@ ![Photos from @ikukevk](https://user-images.githubusercontent.com/306521/30183963-9c722dca-941c-11e7-9e83-c78377ad7f9d.jpg) | ||
- *Fastify*: By using [fastify-fv](https://github.com/erfanium/fastify-fv) | ||
- *Express*: By using [fastest-express-validator](https://github.com/muturgan/fastest-express-validator) | ||
@@ -143,5 +144,7 @@ | ||
v.validate({ name: "John", age: 42 }, schema); // Valid | ||
v.validate({ name: "John" }, schema); // Valid | ||
v.validate({ age: 42 }, schema); // Fail because name is required | ||
const check = v.compile(schema); | ||
check({ name: "John", age: 42 }); // Valid | ||
check({ name: "John" }); // Valid | ||
check({ age: 42 }); // Fail because name is required | ||
``` | ||
@@ -156,8 +159,30 @@ | ||
v.validate({ age: 42 }, schema); // Valid | ||
v.validate({ age: null }, schema); // Valid | ||
v.validate({ age: undefined }, schema); // Fail because undefined is disallowed | ||
v.validate({}, schema); // Fail because undefined is disallowed | ||
const check = v.compile(schema); | ||
check({ age: 42 }); // Valid | ||
check({ age: null }); // Valid | ||
check({ age: undefined }); // Fail because undefined is disallowed | ||
check({}); // Fail because undefined is disallowed | ||
``` | ||
### Nullable and default values | ||
`null` is a valid input for nullable fields that has default value. | ||
```js | ||
const schema = { | ||
about: { type: "string", nullable: true, default: "Hi! I'm using javascript" } | ||
} | ||
const check = v.compile(schema) | ||
const object1 = { about: undefined } | ||
check(object1) // Valid | ||
object1.about // is "Hi! I'm using javascript" | ||
const object2 = { about: null } | ||
check(object2) // valid | ||
object2.about // is null | ||
check({ about: "Custom" }) // Valid | ||
``` | ||
# Strict validation | ||
@@ -172,4 +197,6 @@ Object properties which are not specified on the schema are ignored by default. If you set the `$$strict` option to `true` any additional properties will result in an `strictObject` error. | ||
v.validate({ name: "John" }, schema); // Valid | ||
v.validate({ name: "John", age: 42 }, schema); // Fail | ||
const check = v.compile(schema); | ||
check({ name: "John" }); // Valid | ||
check({ name: "John", age: 42 }); // Fail | ||
``` | ||
@@ -192,5 +219,7 @@ | ||
v.validate({ cache: true }, schema); // Valid | ||
v.validate({ cache: "redis://" }, schema); // Valid | ||
v.validate({ cache: 150 }, schema); // Fail | ||
const check = v.compile(schema); | ||
check({ cache: true }); // Valid | ||
check({ cache: "redis://" }); // Valid | ||
check({ cache: 150 }); // Fail | ||
``` | ||
@@ -210,4 +239,6 @@ | ||
v.validate("John", schema); // Valid | ||
v.validate("Al", schema); // Fail, too short. | ||
const check = v.compile(schema); | ||
check("John"); // Valid | ||
check("Al"); // Fail, too short. | ||
``` | ||
@@ -219,3 +250,3 @@ | ||
## Default values | ||
The most common sanitizer is the `default` property. With it, you can define a default value for all properties. If the property value is `null` or `undefined`, the validator set the defined default value into the property. | ||
The most common sanitizer is the `default` property. With it, you can define a default value for all properties. If the property value is `null`* or `undefined`, the validator set the defined default value into the property. | ||
@@ -229,5 +260,7 @@ **Static Default value example**: | ||
const check = v.compile(schema); | ||
const obj = {} | ||
v.validate(obj, schema); // Valid | ||
check(obj); // Valid | ||
console.log(obj); | ||
@@ -252,5 +285,7 @@ /* | ||
const check = v.compile(schema); | ||
const obj = {} | ||
v.validate(obj, schema); // Valid | ||
check(obj); // Valid | ||
console.log(obj); | ||
@@ -281,2 +316,4 @@ /* | ||
const check = v.compile(schema); | ||
check({ foo: ["bar"] }) // true | ||
@@ -346,5 +383,7 @@ ``` | ||
v.validate({ prop: true }, schema); // Valid | ||
v.validate({ prop: 100 }, schema); // Valid | ||
v.validate({ prop: "John" }, schema); // Valid | ||
const check = v.compile(schema) | ||
check({ prop: true }); // Valid | ||
check({ prop: 100 }); // Valid | ||
check({ prop: "John" }); // Valid | ||
``` | ||
@@ -360,6 +399,7 @@ | ||
} | ||
const check = v.compile(schema) | ||
v.validate({ roles: ["user"] }, schema); // Valid | ||
v.validate({ roles: [] }, schema); // Valid | ||
v.validate({ roles: "user" }, schema); // Fail | ||
check({ roles: ["user"] }); // Valid | ||
check({ roles: [] }); // Valid | ||
check({ roles: "user" }); // Fail | ||
``` | ||
@@ -374,7 +414,8 @@ | ||
} | ||
const check = v.compile(schema) | ||
v.validate({ list: [2, 4] }, schema); // Valid | ||
v.validate({ list: [1, 5, 8] }, schema); // Valid | ||
v.validate({ list: [1] }, schema); // Fail (min 2 elements) | ||
v.validate({ list: [1, -7] }, schema); // Fail (negative number) | ||
check({ list: [2, 4] }); // Valid | ||
check({ list: [1, 5, 8] }); // Valid | ||
check({ list: [1] }); // Fail (min 2 elements) | ||
check({ list: [1, -7] }); // Fail (negative number) | ||
``` | ||
@@ -393,4 +434,5 @@ | ||
} | ||
const check = v.compile(schema) | ||
v.validate({ | ||
check({ | ||
users: [ | ||
@@ -401,3 +443,3 @@ { id: 1, name: "John", status: true }, | ||
] | ||
}, schema); // Valid | ||
}); // Valid | ||
``` | ||
@@ -411,5 +453,7 @@ | ||
v.validate({ roles: ["user"] }, schema); // Valid | ||
v.validate({ roles: ["user", "admin"] }, schema); // Valid | ||
v.validate({ roles: ["guest"] }, schema); // Fail | ||
const check = v.compile(schema) | ||
check({ roles: ["user"] }); // Valid | ||
check({ roles: ["user", "admin"] }); // Valid | ||
check({ roles: ["guest"] }); // Fail | ||
``` | ||
@@ -422,7 +466,8 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ roles: ["user"] }, schema); // Valid | ||
v.validate({ roles: [{role:"user"},{role:"admin"},{role:"user"}] }, schema); // Valid | ||
v.validate({ roles: ["user", "admin", "user"] }, schema); // Fail | ||
v.validate({ roles: [1, 2, 1] }, schema); // Fail | ||
check({ roles: ["user"] }); // Valid | ||
check({ roles: [{role:"user"},{role:"admin"},{role:"user"}] }); // Valid | ||
check({ roles: ["user", "admin", "user"] }); // Fail | ||
check({ roles: [1, 2, 1] }); // Fail | ||
``` | ||
@@ -449,7 +494,8 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ status: true }, schema); // Valid | ||
v.validate({ status: false }, schema); // Valid | ||
v.validate({ status: 1 }, schema); // Fail | ||
v.validate({ status: "true" }, schema); // Fail | ||
check({ status: true }); // Valid | ||
check({ status: false }); // Valid | ||
check({ status: 1 }); // Fail | ||
check({ status: "true" }); // Fail | ||
``` | ||
@@ -463,5 +509,9 @@ ### Properties | ||
```js | ||
v.validate({ status: "true" }, { | ||
const schema = { | ||
status: { type: "boolean", convert: true} | ||
}); // Valid | ||
}; | ||
const check = v.compile(schema); | ||
check({ status: "true" }); // Valid | ||
``` | ||
@@ -476,5 +526,6 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ rawData: Buffer.from([1, 2, 3]) }, schema); // Valid | ||
v.validate({ rawData: 100 }, schema); // Fail | ||
check({ rawData: Buffer.from([1, 2, 3]) }); // Valid | ||
check({ rawData: 100 }); // Fail | ||
``` | ||
@@ -494,11 +545,13 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ money_amount: '$12.99'}, schema); // Valid | ||
v.validate({ money_amount: '$0.99'}, schema); // Valid | ||
v.validate({ money_amount: '$12,345.99'}, schema); // Valid | ||
v.validate({ money_amount: '$123,456.99'}, schema); // Valid | ||
v.validate({ money_amount: '$1234,567.99'}, schema); // Fail | ||
v.validate({ money_amount: '$1,23,456.99'}, schema); // Fail | ||
v.validate({ money_amount: '$12,34.5.99' }, schema); // Fail | ||
check({ money_amount: '$12.99'}); // Valid | ||
check({ money_amount: '$0.99'}); // Valid | ||
check({ money_amount: '$12,345.99'}); // Valid | ||
check({ money_amount: '$123,456.99'}); // Valid | ||
check({ money_amount: '$1234,567.99'}); // Fail | ||
check({ money_amount: '$1,23,456.99'}); // Fail | ||
check({ money_amount: '$12,34.5.99' }); // Fail | ||
``` | ||
@@ -522,6 +575,7 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ dob: new Date() }, schema); // Valid | ||
v.validate({ dob: new Date(1488876927958) }, schema); // Valid | ||
v.validate({ dob: 1488876927958 }, schema); // Fail | ||
check({ dob: new Date() }); // Valid | ||
check({ dob: new Date(1488876927958) }); // Valid | ||
check({ dob: 1488876927958 }); // Fail | ||
``` | ||
@@ -536,5 +590,9 @@ | ||
```js | ||
v.validate({ dob: 1488876927958 }, { | ||
const schema = { | ||
dob: { type: "date", convert: true} | ||
}); // Valid | ||
}; | ||
const check = v.compile(schema); | ||
check({ dob: 1488876927958 }, ); // Valid | ||
``` | ||
@@ -549,6 +607,8 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ email: "john.doe@gmail.com" }, schema); // Valid | ||
v.validate({ email: "james.123.45@mail.co.uk" }, schema); // Valid | ||
v.validate({ email: "abc@gmail" }, schema); // Fail | ||
check({ email: "john.doe@gmail.com" }); // Valid | ||
check({ email: "james.123.45@mail.co.uk" }); // Valid | ||
check({ email: "abc@gmail" }); // Fail | ||
``` | ||
@@ -572,6 +632,8 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ sex: "male" }, schema); // Valid | ||
v.validate({ sex: "female" }, schema); // Valid | ||
v.validate({ sex: "other" }, schema); // Fail | ||
check({ sex: "male" }); // Valid | ||
check({ sex: "female" }); // Valid | ||
check({ sex: "other" }); // Fail | ||
``` | ||
@@ -592,5 +654,6 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ agreeTerms: true }, schema); // Valid | ||
v.validate({ agreeTerms: false }, schema); // Fail | ||
check({ agreeTerms: true }); // Valid | ||
check({ agreeTerms: false }); // Fail | ||
``` | ||
@@ -604,5 +667,6 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ password: "123456", confirmPassword: "123456" }, schema); // Valid | ||
v.validate({ password: "123456", confirmPassword: "pass1234" }, schema); // Fail | ||
check({ password: "123456", confirmPassword: "123456" }); // Valid | ||
check({ password: "123456", confirmPassword: "pass1234" }); // Fail | ||
``` | ||
@@ -623,5 +687,7 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ user: "John" }, schema); // Valid | ||
v.validate({ user: "John", password: "pass1234" }, schema); // Fail | ||
check({ user: "John" }); // Valid | ||
check({ user: "John", password: "pass1234" }); // Fail | ||
``` | ||
@@ -640,3 +706,5 @@ | ||
}; | ||
const check = v.compile(schema); | ||
const obj = { | ||
@@ -647,3 +715,3 @@ user: "John", | ||
v.validate(obj, schema); // Valid | ||
check(obj); // Valid | ||
console.log(obj); | ||
@@ -665,6 +733,8 @@ /* | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ show: function() {} }, schema); // Valid | ||
v.validate({ show: Date.now }, schema); // Valid | ||
v.validate({ show: "function" }, schema); // Fail | ||
check({ show: function() {} }); // Valid | ||
check({ show: Date.now }); // Valid | ||
check({ show: "function" }); // Fail | ||
``` | ||
@@ -681,7 +751,8 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ cc: "452373989901198" }, schema); // Valid | ||
v.validate({ cc: 452373989901198 }, schema); // Valid | ||
v.validate({ cc: "4523-739-8990-1198" }, schema); // Valid | ||
v.validate({ cc: "452373989901199" }, schema); // Fail | ||
check({ cc: "452373989901198" }); // Valid | ||
check({ cc: 452373989901198 }); // Valid | ||
check({ cc: "4523-739-8990-1198" }); // Valid | ||
check({ cc: "452373989901199" }); // Fail | ||
``` | ||
@@ -696,10 +767,11 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ mac: "01:C8:95:4B:65:FE" }, schema); // Valid | ||
v.validate({ mac: "01:c8:95:4b:65:fe", schema); // Valid | ||
v.validate({ mac: "01C8.954B.65FE" }, schema); // Valid | ||
v.validate({ mac: "01c8.954b.65fe", schema); // Valid | ||
v.validate({ mac: "01-C8-95-4B-65-FE" }, schema); // Valid | ||
v.validate({ mac: "01-c8-95-4b-65-fe" }, schema); // Valid | ||
v.validate({ mac: "01C8954B65FE" }, schema); // Fail | ||
check({ mac: "01:C8:95:4B:65:FE" }); // Valid | ||
check({ mac: "01:c8:95:4b:65:fe"); // Valid | ||
check({ mac: "01C8.954B.65FE" }); // Valid | ||
check({ mac: "01c8.954b.65fe"); // Valid | ||
check({ mac: "01-C8-95-4B-65-FE" }); // Valid | ||
check({ mac: "01-c8-95-4b-65-fe" }); // Valid | ||
check({ mac: "01C8954B65FE" }); // Fail | ||
``` | ||
@@ -717,8 +789,9 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ status: true }, schema); // Valid | ||
v.validate({ status: false }, schema); // Valid | ||
v.validate({ status: 1 }, schema); // Valid | ||
v.validate({ status: 0 }, schema); // Valid | ||
v.validate({ status: "yes" }, schema); // Fail | ||
check({ status: true }); // Valid | ||
check({ status: false }); // Valid | ||
check({ status: 1 }); // Valid | ||
check({ status: 0 }); // Valid | ||
check({ status: "yes" }); // Fail | ||
``` | ||
@@ -734,8 +807,9 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ status: true }, schema); // Valid | ||
v.validate({ status: false }, schema); // Valid | ||
v.validate({ status: 1 }, schema); // Valid | ||
v.validate({ status: 0 }, schema); // Valid | ||
v.validate({ status: "yes" }, schema); // Fail | ||
check({ status: true }); // Valid | ||
check({ status: false }); // Valid | ||
check({ status: 1 }); // Valid | ||
check({ status: 0 }); // Valid | ||
check({ status: "yes" }); // Fail | ||
``` | ||
@@ -750,6 +824,7 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ age: 123 }, schema); // Valid | ||
v.validate({ age: 5.65 }, schema); // Valid | ||
v.validate({ age: "100" }, schema); // Fail | ||
check({ age: 123 }); // Valid | ||
check({ age: 5.65 }); // Valid | ||
check({ age: "100" }); // Fail | ||
``` | ||
@@ -780,4 +855,5 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ | ||
check({ | ||
address: { | ||
@@ -788,5 +864,5 @@ country: "Italy", | ||
} | ||
}, schema); // Valid | ||
}); // Valid | ||
v.validate({ | ||
check({ | ||
address: { | ||
@@ -796,5 +872,5 @@ country: "Italy", | ||
} | ||
}, schema); // Fail ("The 'address.zip' field is required!") | ||
}); // Fail ("The 'address.zip' field is required!") | ||
v.validate({ | ||
check({ | ||
address: { | ||
@@ -806,3 +882,3 @@ country: "Italy", | ||
} | ||
}, schema); // Fail ("The 'address.state' is an additional field!") | ||
}); // Fail ("The 'address.state' is an additional field!") | ||
``` | ||
@@ -818,3 +894,3 @@ | ||
```js | ||
let schema = { | ||
schema = { | ||
address: { type: "object", strict: "remove", props: { | ||
@@ -835,4 +911,5 @@ country: { type: "string" }, | ||
}; | ||
const check = v.compile(schema); | ||
v.validate(obj, schema); // Valid | ||
check(obj); // Valid | ||
console.log(obj); | ||
@@ -848,3 +925,4 @@ /* | ||
*/ | ||
``` | ||
```js | ||
schema = { | ||
@@ -861,3 +939,5 @@ address: { | ||
} | ||
const check = v.compile(schema); | ||
obj = { | ||
@@ -872,3 +952,3 @@ address: { | ||
v.validate(obj, schema); // Valid | ||
check(obj); // Valid | ||
@@ -881,3 +961,3 @@ obj = { | ||
v.validate(obj, schema); // Fail | ||
check(obj); // Fail | ||
// [ | ||
@@ -901,6 +981,7 @@ // { | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ name: "John" }, schema); // Valid | ||
v.validate({ name: "" }, schema); // Valid | ||
v.validate({ name: 123 }, schema); // Fail | ||
check({ name: "John" }); // Valid | ||
check({ name: "" }); // Valid | ||
check({ name: 123 }); // Fail | ||
``` | ||
@@ -942,2 +1023,3 @@ | ||
} | ||
const check = v.compile(schema); | ||
@@ -948,3 +1030,3 @@ const obj = { | ||
v.validate(obj, schema); // Valid | ||
check(obj); // Valid | ||
console.log(obj); | ||
@@ -964,7 +1046,8 @@ /* | ||
const schema = { list: "tuple" }; | ||
const check = v.compile(schema); | ||
v.validate({ list: [] }, schema); // Valid | ||
v.validate({ list: [1, 2] }, schema); // Valid | ||
v.validate({ list: ["RON", 100, true] }, schema); // Valid | ||
v.validate({ list: 94 }, schema); // Fail (not an array) | ||
check({ list: [] }); // Valid | ||
check({ list: [1, 2] }); // Valid | ||
check({ list: ["RON", 100, true] }); // Valid | ||
check({ list: 94 }); // Fail (not an array) | ||
``` | ||
@@ -977,6 +1060,7 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ grade: ["David", 85] }, schema); // Valid | ||
v.validate({ grade: [85, "David"] }, schema); // Fail (wrong position) | ||
v.validate({ grade: ["Cami"] }, schema); // Fail (require 2 elements) | ||
check({ grade: ["David", 85] }); // Valid | ||
check({ grade: [85, "David"] }); // Fail (wrong position) | ||
check({ grade: ["Cami"] }); // Fail (require 2 elements) | ||
``` | ||
@@ -995,6 +1079,7 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ location: ['New York', [40.7127281, -74.0060152]] }, schema); // Valid | ||
v.validate({ location: ['New York', [50.0000000, -74.0060152]] }, schema); // Fail | ||
v.validate({ location: ['New York', []] }, schema); // Fail (empty array) | ||
check({ location: ['New York', [40.7127281, -74.0060152]] }); // Valid | ||
check({ location: ['New York', [50.0000000, -74.0060152]] }); // Fail | ||
check({ location: ['New York', []] }); // Fail (empty array) | ||
``` | ||
@@ -1015,6 +1100,7 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ url: "http://google.com" }, schema); // Valid | ||
v.validate({ url: "https://github.com/icebob" }, schema); // Valid | ||
v.validate({ url: "www.facebook.com" }, schema); // Fail | ||
check({ url: "http://google.com" }); // Valid | ||
check({ url: "https://github.com/icebob" }); // Valid | ||
check({ url: "www.facebook.com" }); // Fail | ||
``` | ||
@@ -1034,7 +1120,8 @@ | ||
} | ||
const check = v.compile(schema); | ||
v.validate({ uuid: "00000000-0000-0000-0000-000000000000" }, schema); // Valid Nil UUID | ||
v.validate({ uuid: "10ba038e-48da-487b-96e8-8d3b99b6d18a" }, schema); // Valid UUIDv4 | ||
v.validate({ uuid: "9a7b330a-a736-51e5-af7f-feaf819cdc9f" }, schema); // Valid UUIDv5 | ||
v.validate({ uuid: "10ba038e-48da-487b-96e8-8d3b99b6d18a", version: 5 }, schema); // Fail | ||
check({ uuid: "00000000-0000-0000-0000-000000000000" }); // Valid Nil UUID | ||
check({ uuid: "10ba038e-48da-487b-96e8-8d3b99b6d18a" }); // Valid UUIDv4 | ||
check({ uuid: "9a7b330a-a736-51e5-af7f-feaf819cdc9f" }); // Valid UUIDv5 | ||
check({ uuid: "10ba038e-48da-487b-96e8-8d3b99b6d18a", version: 5 }); // Fail | ||
``` | ||
@@ -1057,4 +1144,4 @@ ### Properties | ||
} | ||
const check = v.compile(schema); | ||
const check = v.compile(schema); | ||
check({ id: "5f082780b00cc7401fb8e8fc" }) // ok | ||
@@ -1115,7 +1202,8 @@ check({ id: new ObjectID() }) // ok | ||
}; | ||
const check = v.compile(schema); | ||
console.log(v.validate({ name: "John", age: 20 }, schema)); | ||
console.log(check({ name: "John", age: 20 }, schema)); | ||
// Returns: true | ||
console.log(v.validate({ name: "John", age: 19 }, schema)); | ||
console.log(check({ name: "John", age: 19 }, schema)); | ||
/* Returns an array with errors: | ||
@@ -1154,7 +1242,8 @@ [{ | ||
}; | ||
const check = v.compile(schema); | ||
console.log(v.validate({ name: "John", weight: 50 }, schema)); | ||
console.log(check({ name: "John", weight: 50 }, schema)); | ||
// Returns: true | ||
console.log(v.validate({ name: "John", weight: 8 }, schema)); | ||
console.log(check({ name: "John", weight: 8 }, schema)); | ||
/* Returns an array with errors: | ||
@@ -1170,3 +1259,3 @@ [{ | ||
const o = { name: "John", weight: 110 } | ||
console.log(v.validate(o, schema)); | ||
console.log(check(o, schema)); | ||
/* Returns: true | ||
@@ -1198,7 +1287,9 @@ o.weight is 100 | ||
}; | ||
const check = v.compile(schema); | ||
console.log(v.validate({ name: "John", phone: "+36-70-123-4567" }, schema)); | ||
console.log(check({ name: "John", phone: "+36-70-123-4567" })); | ||
// Returns: true | ||
console.log(v.validate({ name: "John", phone: "36-70-123-4567" }, schema)); | ||
console.log(check({ name: "John", phone: "36-70-123-4567" })); | ||
/* Returns an array with errors: | ||
@@ -1300,3 +1391,8 @@ [{ | ||
v.validate({ name: "John" }, { name: { type: "string", min: 6 }}); | ||
const schema = { | ||
name: { type: "string", min: 6 } | ||
} | ||
const check = v.compile(schema); | ||
check({ name: "John" }); | ||
/* Returns: | ||
@@ -1338,3 +1434,5 @@ [ | ||
} | ||
v.validate({ firstname: "John", lastname: 23 }, schema ); | ||
const check = v.compile(schema); | ||
check({ firstname: "John", lastname: 23 }); | ||
/* Returns: | ||
@@ -1341,0 +1439,0 @@ [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
358834
38
4889
1535