Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastest-validator

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastest-validator - npm Package Compare versions

Comparing version 1.12.0 to 1.13.0

lib/rules/record.js

14

CHANGELOG.md

@@ -0,2 +1,16 @@

<a name="1.13.0"></a>
# 1.13.0 (2022-08-15)
## Changes
- update dev dependencies.
- update d.ts
- fixing string enum check in case of optional field. [#284](https://github.com/icebob/fastest-validator/pull/284)
- date rule add convert string to number for timestamp. [#286](https://github.com/icebob/fastest-validator/pull/286)
- fix(multi): item rule has custom checker will throw error if validate. [#290](https://github.com/icebob/fastest-validator/pull/290)
- fix backward compatibility issue. [#298](https://github.com/icebob/fastest-validator/pull/298)
- add [new `Record` rule](https://github.com/icebob/fastest-validator#record). [#300](https://github.com/icebob/fastest-validator/pull/300)
<a name="1.12.0"></a>
# 1.12.0 (2021-10-17)

@@ -3,0 +17,0 @@

25

dist/index.d.ts

@@ -20,2 +20,3 @@

| "object"
| "record"
| "string"

@@ -354,6 +355,7 @@ | "url"

/**
* if true any properties which are not defined on the schema will throw an error.
* If `true` any properties which are not defined on the schema will throw an error.<br>
* If `remove` all additional properties will be removed from the original object. It's a sanitizer, it will change the original object.
* @default false
*/
strict?: boolean;
strict?: boolean | "remove";
/**

@@ -389,2 +391,17 @@ * List of properties that should be validated by this rule

export interface RuleRecord extends RuleCustom {
/**
* Name of built-in validator
*/
type: "record";
/**
* Key validation rule
*/
key?: RuleString;
/**
* Value validation rule
*/
value?: ValidationRuleObject;
}
/**

@@ -809,2 +826,3 @@ * Validation schema definition for "string" built-in validator

| RuleObjectID
| RuleRecord
| RuleString

@@ -930,3 +948,3 @@ | RuleTuple

export interface Context {
export interface Context<DATA = any> {
index: number;

@@ -940,2 +958,3 @@ async: boolean;

meta?: object;
data: DATA;
}

@@ -942,0 +961,0 @@

@@ -119,2 +119,4 @@ (function (global, factory) {

objectID: "The '{field}' field must be an valid ObjectID",
record: "The '{field}' must be an Object."
};

@@ -180,2 +182,3 @@ messages.required;

messages.objectID;
messages.record;

@@ -351,3 +354,3 @@ /** Signature: function(value, field, parent, errors, context)

sanitized = true;
src.push("\n\t\t\tif (!(value instanceof Date)) {\n\t\t\t\tvalue = new Date(value);\n\t\t\t}\n\t\t");
src.push("\n\t\t\tif (!(value instanceof Date)) {\n\t\t\t\tvalue = new Date(value.length && !isNaN(+value) ? +value : value);\n\t\t\t}\n\t\t");
}

@@ -492,3 +495,3 @@

src.push("\n\t\tvar hasValid = false;\n\t\tvar newVal = value;\n\t\tvar checkErrors = [];\n\t");
src.push("\n\t\tvar hasValid = false;\n\t\tvar newVal = value;\n\t\tvar checkErrors = [];\n\t\tvar errorsSize = errors.length;\n\t");

@@ -500,3 +503,3 @@ for (var i = 0; i < schema.rules.length; i++) {

src.push(this.compileRule(rule, context, path, ("var tmpVal = " + (context.async ? "await " : "") + "context.fn[%%INDEX%%](value, field, parent, _errors, context);"), "tmpVal"));
src.push("\n\t\t\t\tif (_errors.length == 0) {\n\t\t\t\t\thasValid = true;\n\t\t\t\t\tnewVal = tmpVal;\n\t\t\t\t} else {\n\t\t\t\t\tArray.prototype.push.apply(checkErrors, _errors);\n\t\t\t\t}\n\t\t\t}\n\t\t");
src.push("\n\t\t\t\tif (errors.length == errorsSize && _errors.length == 0) {\n\t\t\t\t\thasValid = true;\n\t\t\t\t\tnewVal = tmpVal;\n\t\t\t\t} else {\n\t\t\t\t\tArray.prototype.push.apply(checkErrors, [].concat(_errors, errors.splice(errorsSize)));\n\t\t\t\t}\n\t\t\t}\n\t\t");
}

@@ -635,12 +638,12 @@

if (schema.strict) {
sourceCode.push("\n\t\t\t\tif (errors.length === 0) {\n\t\t\t");
var allowedProps = Object.keys(subSchema);
sourceCode.push(("\n\t\t\t\t\tfield = parentField;\n\t\t\t\t\tvar invalidProps = [];\n\t\t\t\t\tvar props = Object.keys(parentObj);\n\n\t\t\t\t\tfor (let i = 0; i < props.length; i++) {\n\t\t\t\t\t\tif (" + (JSON.stringify(allowedProps)) + ".indexOf(props[i]) === -1) {\n\t\t\t\t\t\t\tinvalidProps.push(props[i]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (invalidProps.length) {\n\t\t\t"));
if (schema.strict == "remove") {
sourceCode.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(allowedProps)) + ".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"));
if (schema.strict === "remove") {
sourceCode.push("\n\t\t\t\t\tif (errors.length === 0) {\n\t\t\t\t");
sourceCode.push("\n\t\t\t\t\t\tinvalidProps.forEach(function(field) {\n\t\t\t\t\t\t\tdelete parentObj[field];\n\t\t\t\t\t\t});\n\t\t\t\t");
sourceCode.push("\n\t\t\t\t\t}\n\t\t\t\t");
} else {
sourceCode.push(("\n\t\t\t\t\t" + (this.makeError({ type: "objectStrict", expected: "\"" + allowedProps.join(", ") + "\"", actual: "invalidProps.join(', ')", messages: messages })) + "\n\t\t\t\t"));
}
sourceCode.push("\n\t\t\t\t\t}\n\t\t\t");
sourceCode.push("\n\t\t\t\t}\n\t\t\t");

@@ -704,2 +707,37 @@ }

function patchKeyRuleMessages(rule) {
for (var type in rule.messages) {
if (type.startsWith("string")) {
rule.messages[type] = rule.messages[type].replace(" field ", " key ");
}
}
}
var record = function compileRecordRule(ref, path, context) {
var schema = ref.schema;
var messages = ref.messages;
var sourceCode = [];
sourceCode.push(("\n\t\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n\t\t\t" + (this.makeError({ type: "record", actual: "value", messages: messages })) + "\n\t\t\treturn value;\n\t\t}\n\t"));
var keyRuleName = schema.key || "string";
var valueRuleName = schema.value || "any";
sourceCode.push("\n\t\tlet tmp;\n\t\tfor (let key in value) {\n\t");
var keyRule = this.getRuleFromSchema(keyRuleName);
patchKeyRuleMessages(keyRule);
var keyInnerSource = "\n\t\ttmp = " + (context.async ? "await " : "") + "context.fn[%%INDEX%%](key, field ? field + \".\" + key : key, value, errors, context);\n\t";
sourceCode.push(this.compileRule(keyRule, context, null, keyInnerSource, "tmp"));
var valueRule = this.getRuleFromSchema(valueRuleName);
var valueInnerSource = "\n\t\ttmp = " + (context.async ? "await " : "") + "context.fn[%%INDEX%%](value[key], field ? field + \".\" + key : key, value, errors, context);\n\t";
sourceCode.push(this.compileRule(valueRule, context, (path + "[key]"), valueInnerSource, "tmp"));
sourceCode.push("\n\t\t}\n\t");
return {
source: sourceCode.join("\n")
};
};
var NUMERIC_PATTERN = /^-?[0-9]\d*(\.\d+)?$/;

@@ -779,2 +817,4 @@ var ALPHA_PATTERN = /^[a-zA-Z]+$/;

src.push(("\n\t\t\tif (len === 0) {\n\t\t\t\t" + (this.makeError({ type: "stringEmpty", actual: "value", messages: messages })) + "\n\t\t\t}\n\t\t"));
} else if (schema.empty === true) {
src.push("\n\t\t\tif (len === 0) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t");
}

@@ -799,5 +839,3 @@

var patternValidator = "\n\t\t\tif (!" + (pattern.toString()) + ".test(value))\n\t\t\t\t" + (this.makeError({ type: "stringPattern", expected: ("\"" + (pattern.toString().replace(/"/g, "\\$&")) + "\""), actual: "origValue", messages: messages })) + "\n\t\t";
src.push(("\n\t\t\tif (" + (schema.empty) + " === true && len === 0) {\n\t\t\t\t// Do nothing\n\t\t\t} else {\n\t\t\t\t" + patternValidator + "\n\t\t\t}\n\t\t"));
src.push(("\n\t\t\tif (!" + (pattern.toString()) + ".test(value)) {\n\t\t\t\t" + (this.makeError({ type: "stringPattern", expected: ("\"" + (pattern.toString().replace(/"/g, "\\$&")) + "\""), actual: "origValue", messages: messages })) + "\n\t\t\t}\n\t\t"));
}

@@ -1056,2 +1094,3 @@

objectID: objectID,
record: record,
string: string,

@@ -1058,0 +1097,0 @@ tuple: tuple,

79

dist/index.min.js

@@ -10,4 +10,6 @@ 'use strict';var g=g||{};g.scope={};g.arrayIteratorImpl=function(e){var h=0;return function(){return h<e.length?{done:!1,value:e[h++]}:{done:!0}}};g.arrayIterator=function(e){return{next:g.arrayIteratorImpl(e)}};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.FORCE_POLYFILL_PROMISE=!1;g.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION=!1;

g.iteratorPrototype=function(e){e={next:e};e[Symbol.iterator]=function(){return this};return e};g.iteratorFromArray=function(e,h){e instanceof String&&(e+="");var l=0,m=!1,t={next:function(){if(!m&&l<e.length){var w=l++;return{value:h(w,e[w]),done:!1}}m=!0;return{done:!0,value:void 0}}};t[Symbol.iterator]=function(){return t};return t};g.polyfill("Array.prototype.keys",function(e){return e?e:function(){return g.iteratorFromArray(this,function(h){return h})}},"es6","es3");
g.polyfill("Array.prototype.values",function(e){return e?e:function(){return g.iteratorFromArray(this,function(h,l){return l})}},"es8","es3");g.owns=function(e,h){return Object.prototype.hasOwnProperty.call(e,h)};g.assign=g.TRUST_ES6_POLYFILLS&&"function"==typeof Object.assign?Object.assign:function(e,h){for(var l=1;l<arguments.length;l++){var m=arguments[l];if(m)for(var t in m)g.owns(m,t)&&(e[t]=m[t])}return e};g.polyfill("Object.assign",function(e){return e||g.assign},"es6","es3");
g.checkEs6ConformanceViaProxy=function(){try{var e={},h=Object.create(new g.global.Proxy(e,{get:function(l,m,t){return l==e&&"q"==m&&t==h}}));return!0===h.q}catch(l){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(e){var h="undefined"!=typeof Symbol&&Symbol.iterator&&e[Symbol.iterator];return h?h.call(e):g.arrayIterator(e)};
g.polyfill("Array.prototype.values",function(e){return e?e:function(){return g.iteratorFromArray(this,function(h,l){return l})}},"es8","es3");g.checkStringArgs=function(e,h,l){if(null==e)throw new TypeError("The 'this' value for String.prototype."+l+" must not be null or undefined");if(h instanceof RegExp)throw new TypeError("First argument to String.prototype."+l+" must not be a regular expression");return e+""};
g.polyfill("String.prototype.startsWith",function(e){return e?e:function(h,l){var m=g.checkStringArgs(this,h,"startsWith");h+="";var t=m.length,w=h.length;l=Math.max(0,Math.min(l|0,m.length));for(var x=0;x<w&&l<t;)if(m[l++]!=h[x++])return!1;return x>=w}},"es6","es3");g.owns=function(e,h){return Object.prototype.hasOwnProperty.call(e,h)};
g.assign=g.TRUST_ES6_POLYFILLS&&"function"==typeof Object.assign?Object.assign:function(e,h){for(var l=1;l<arguments.length;l++){var m=arguments[l];if(m)for(var t in m)g.owns(m,t)&&(e[t]=m[t])}return e};g.polyfill("Object.assign",function(e){return e||g.assign},"es6","es3");g.checkEs6ConformanceViaProxy=function(){try{var e={},h=Object.create(new g.global.Proxy(e,{get:function(l,m,t){return l==e&&"q"==m&&t==h}}));return!0===h.q}catch(l){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(e){var h="undefined"!=typeof Symbol&&Symbol.iterator&&e[Symbol.iterator];return h?h.call(e):g.arrayIterator(e)};
g.polyfill("WeakMap",function(e){function h(k){this.id_=(n+=Math.random()+1).toString();if(k){k=g.makeIterator(k);for(var p;!(p=k.next()).done;)p=p.value,this.set(p[0],p[1])}}function l(){if(!e||!Object.seal)return!1;try{var k=Object.seal({}),p=Object.seal({}),u=new e([[k,2],[p,3]]);if(2!=u.get(k)||3!=u.get(p))return!1;u.delete(k);u.set(p,4);return!u.has(k)&&4==u.get(p)}catch(C){return!1}}function m(){}function t(k){var p=typeof k;return"object"===p&&null!==k||"function"===p}function w(k){if(!g.owns(k,

@@ -21,12 +23,11 @@ y)){var p=new m;g.defineProperty(k,y,{value:p})}}function x(k){if(!g.ISOLATE_POLYFILLS){var p=Object[k];p&&(Object[k]=function(u){if(u instanceof m)return u;Object.isExtensible(u)&&w(u);return p(u)})}}if(g.USE_PROXY_FOR_ES6_CONFORMANCE_CHECKS){if(e&&g.ES6_CONFORMANCE)return e}else if(l())return e;var y="$jscomp_hidden_"+Math.random();x("freeze");x("preventExtensions");x("seal");var n=0;h.prototype.set=function(k,p){if(!t(k))throw Error("Invalid WeakMap key");w(k);if(!g.owns(k,y))throw Error("WeakMap key fail: "+

m(this,n).entry)&&n.value};t.prototype.entries=function(){return l(this,function(n){return[n.key,n.value]})};t.prototype.keys=function(){return l(this,function(n){return n.key})};t.prototype.values=function(){return l(this,function(n){return n.value})};t.prototype.forEach=function(n,k){for(var p=this.entries(),u;!(u=p.next()).done;)u=u.value,n.call(k,u[1],u[0],this)};t.prototype[Symbol.iterator]=t.prototype.entries;var y=0;return t},"es6","es3");
g.checkStringArgs=function(e,h,l){if(null==e)throw new TypeError("The 'this' value for String.prototype."+l+" must not be null or undefined");if(h instanceof RegExp)throw new TypeError("First argument to String.prototype."+l+" must not be a regular expression");return e+""};
g.polyfill("String.prototype.endsWith",function(e){return e?e:function(h,l){var m=g.checkStringArgs(this,h,"endsWith");h+="";void 0===l&&(l=m.length);l=Math.max(0,Math.min(l|0,m.length));for(var t=h.length;0<t&&0<l;)if(m[--l]!=h[--t])return!1;return 0>=t}},"es6","es3");g.polyfill("Number.isNaN",function(e){return e?e:function(h){return"number"===typeof h&&isNaN(h)}},"es6","es3");
g.polyfill("String.prototype.startsWith",function(e){return e?e:function(h,l){var m=g.checkStringArgs(this,h,"startsWith");h+="";var t=m.length,w=h.length;l=Math.max(0,Math.min(l|0,m.length));for(var x=0;x<w&&l<t;)if(m[l++]!=h[x++])return!1;return x>=w}},"es6","es3");g.polyfill("Object.entries",function(e){return e?e:function(h){var l=[],m;for(m in h)g.owns(h,m)&&l.push([m,h[m]]);return l}},"es8","es3");var E=this;
function F(){function e(a){this.opts={};this.defaults={};this.messages=Object.assign({},q);this.rules={any:Q,array:R,boolean:S,class:T,custom:U,currency:V,date:W,email:X,enum:Y,equal:Z,forbidden:aa,function:C,multi:u,number:p,object:k,objectID:n,string:y,tuple:x,url:w,uuid:t,mac:m,luhn:l};this.aliases={};this.cache=new Map;if(a){B(this.opts,a);a.defaults&&B(this.defaults,a.defaults);if(a.messages)for(var b in a.messages)this.addMessage(b,a.messages[b]);if(a.aliases)for(var c in a.aliases)this.alias(c,
g.polyfill("Object.entries",function(e){return e?e:function(h){var l=[],m;for(m in h)g.owns(h,m)&&l.push([m,h[m]]);return l}},"es8","es3");var E=this;
function F(){function e(a){this.opts={};this.defaults={};this.messages=Object.assign({},q);this.rules={any:Q,array:R,boolean:S,class:T,custom:U,currency:V,date:W,email:X,enum:Y,equal:Z,forbidden:aa,function:ba,multi:C,number:u,object:p,objectID:k,record:n,string:y,tuple:x,url:w,uuid:t,mac:m,luhn:l};this.aliases={};this.cache=new Map;if(a){B(this.opts,a);a.defaults&&B(this.defaults,a.defaults);if(a.messages)for(var b in a.messages)this.addMessage(b,a.messages[b]);if(a.aliases)for(var c in a.aliases)this.alias(c,
a.aliases[c]);if(a.customRules)for(var d in a.customRules)this.add(d,a.customRules[d]);if(a.plugins){a=a.plugins;if(!Array.isArray(a))throw Error("Plugins type must be array");a.forEach(this.plugin.bind(this))}this.opts.debug&&(a=function(f){return f},"undefined"===typeof window&&(a=h),this._formatter=a)}}function h(a){G||(G=K(),L={parser:"babel",useTabs:!1,printWidth:120,trailingComma:"none",tabWidth:4,singleQuote:!1,semi:!0,bracketSpacing:!0},H=K(),M={language:"js",theme:H.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"})});a=G.format(a,L);return H.highlight(a,M)}function l(a){a.schema;a=a.messages;return{source:'\n\t\t\tif (typeof value !== "string") {\n\t\t\t\t'+this.makeError({type:"string",actual:"value",messages:a})+'\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:a})+"\n\t\t\t}\n\n\t\t\treturn value;\n\t\t"}}function m(a){a.schema;a=a.messages;return{source:'\n\t\t\tif (typeof value !== "string") {\n\t\t\t\t'+this.makeError({type:"string",actual:"value",messages:a})+"\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tvar v = value.toLowerCase();\n\t\t\tif (!"+ba.toString()+".test(v)) {\n\t\t\t\t"+this.makeError({type:"mac",actual:"value",messages:a})+"\n\t\t\t}\n\t\t\t\n\t\t\treturn value;\n\t\t"}}function t(a){var b=
a.schema;a=a.messages;var c=[];c.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+this.makeError({type:"string",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tvar val = value.toLowerCase();\n\t\tif (!"+ca.toString()+".test(val)) {\n\t\t\t"+this.makeError({type:"uuid",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tconst version = val.charAt(14) | 0;\n\t");7>parseInt(b.version)&&c.push("\n\t\t\tif ("+b.version+" !== version) {\n\t\t\t\t"+this.makeError({type:"uuidVersion",
this.makeError({type:"luhn",actual:"value",messages:a})+"\n\t\t\t}\n\n\t\t\treturn value;\n\t\t"}}function m(a){a.schema;a=a.messages;return{source:'\n\t\t\tif (typeof value !== "string") {\n\t\t\t\t'+this.makeError({type:"string",actual:"value",messages:a})+"\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tvar v = value.toLowerCase();\n\t\t\tif (!"+ca.toString()+".test(v)) {\n\t\t\t\t"+this.makeError({type:"mac",actual:"value",messages:a})+"\n\t\t\t}\n\t\t\t\n\t\t\treturn value;\n\t\t"}}function t(a){var b=
a.schema;a=a.messages;var c=[];c.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+this.makeError({type:"string",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tvar val = value.toLowerCase();\n\t\tif (!"+da.toString()+".test(val)) {\n\t\t\t"+this.makeError({type:"uuid",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tconst version = val.charAt(14) | 0;\n\t");7>parseInt(b.version)&&c.push("\n\t\t\tif ("+b.version+" !== version) {\n\t\t\t\t"+this.makeError({type:"uuidVersion",
expected:b.version,actual:"version",messages:a})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t");c.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:a})+"\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t");return{source:c.join("\n")}}function w(a){var b=a.schema;a=a.messages;var c=[];c.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+
this.makeError({type:"string",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\t");b.empty?c.push("\n\t\t\tif (value.length === 0) return value;\n\t\t"):c.push("\n\t\t\tif (value.length === 0) {\n\t\t\t\t"+this.makeError({type:"urlEmpty",actual:"value",messages:a})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t");c.push("\n\t\tif (!"+da.toString()+".test(value)) {\n\t\t\t"+this.makeError({type:"url",actual:"value",messages:a})+"\n\t\t}\n\n\t\treturn value;\n\t");return{source:c.join("\n")}}function x(a,
this.makeError({type:"string",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\t");b.empty?c.push("\n\t\t\tif (value.length === 0) return value;\n\t\t"):c.push("\n\t\t\tif (value.length === 0) {\n\t\t\t\t"+this.makeError({type:"urlEmpty",actual:"value",messages:a})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t");c.push("\n\t\tif (!"+ea.toString()+".test(value)) {\n\t\t\t"+this.makeError({type:"url",actual:"value",messages:a})+"\n\t\t}\n\n\t\treturn value;\n\t");return{source:c.join("\n")}}function x(a,
b,c){var d=a.schema,f=a.messages;a=[];if(null!=d.items){if(!Array.isArray(d.items))throw Error("Invalid '"+d.type+"' schema. The 'items' field must be an array.");if(0===d.items.length)throw Error("Invalid '"+d.type+"' schema. The 'items' field must not be an empty array.");}a.push("\n\t\tif (!Array.isArray(value)) {\n\t\t\t"+this.makeError({type:"tuple",actual:"value",messages:f})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tvar len = value.length;\n\t");!1===d.empty&&a.push("\n\t\t\tif (len === 0) {\n\t\t\t\t"+

@@ -37,26 +38,28 @@ this.makeError({type:"tupleEmpty",actual:"value",messages:f})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t");if(null!=d.items){a.push("\n\t\t\tif ("+d.empty+" !== false && len === 0) {\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tif (len !== "+d.items.length+") {\n\t\t\t\t"+this.makeError({type:"tupleLength",expected:d.items.length,actual:"len",messages:f})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t");a.push("\n\t\t\tvar arr = value;\n\t\t\tvar parentField = field;\n\t\t");for(f=0;f<d.items.length;f++){a.push("\n\t\t\tvalue = arr["+

");\n\t\t"));b.padEnd&&(d=!0,c.push("\n\t\t\tvalue = value.padEnd("+b.padEnd+", "+JSON.stringify(null!=b.padChar?b.padChar:" ")+");\n\t\t"));b.lowercase&&(d=!0,c.push("\n\t\t\tvalue = value.toLowerCase();\n\t\t"));b.uppercase&&(d=!0,c.push("\n\t\t\tvalue = value.toUpperCase();\n\t\t"));b.localeLowercase&&(d=!0,c.push("\n\t\t\tvalue = value.toLocaleLowerCase();\n\t\t"));b.localeUppercase&&(d=!0,c.push("\n\t\t\tvalue = value.toLocaleUpperCase();\n\t\t"));c.push("\n\t\t\tvar len = value.length;\n\t");
!1===b.empty&&c.push("\n\t\t\tif (len === 0) {\n\t\t\t\t"+this.makeError({type:"stringEmpty",actual:"value",messages:a})+"\n\t\t\t}\n\t\t");null!=b.min&&c.push("\n\t\t\tif (len < "+b.min+") {\n\t\t\t\t"+this.makeError({type:"stringMin",expected:b.min,actual:"len",messages:a})+"\n\t\t\t}\n\t\t");null!=b.max&&c.push("\n\t\t\tif (len > "+b.max+") {\n\t\t\t\t"+this.makeError({type:"stringMax",expected:b.max,actual:"len",messages:a})+"\n\t\t\t}\n\t\t");null!=b.length&&c.push("\n\t\t\tif (len !== "+b.length+
") {\n\t\t\t\t"+this.makeError({type:"stringLength",expected:b.length,actual:"len",messages:a})+"\n\t\t\t}\n\t\t");if(null!=b.pattern){var f=b.pattern;"string"==typeof b.pattern&&(f=new RegExp(b.pattern,b.patternFlags));f="\n\t\t\tif (!"+f.toString()+".test(value))\n\t\t\t\t"+this.makeError({type:"stringPattern",expected:'"'+f.toString().replace(/"/g,"\\$&")+'"',actual:"origValue",messages:a})+"\n\t\t";c.push("\n\t\t\tif ("+b.empty+" === true && len === 0) {\n\t\t\t\t// Do nothing\n\t\t\t} else {\n\t\t\t\t"+
f+"\n\t\t\t}\n\t\t")}null!=b.contains&&c.push('\n\t\t\tif (value.indexOf("'+b.contains+'") === -1) {\n\t\t\t\t'+this.makeError({type:"stringContains",expected:'"'+b.contains+'"',actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");null!=b.enum&&(f=JSON.stringify(b.enum),c.push("\n\t\t\tif ("+f+".indexOf(value) === -1) {\n\t\t\t\t"+this.makeError({type:"stringEnum",expected:'"'+b.enum.join(", ")+'"',actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t"));!0===b.numeric&&c.push("\n\t\t\tif (!"+ea.toString()+
".test(value) ) {\n\t\t\t\t"+this.makeError({type:"stringNumeric",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.alpha&&c.push("\n\t\t\tif(!"+fa.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringAlpha",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.alphanum&&c.push("\n\t\t\tif(!"+ha.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringAlphanum",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.alphadash&&c.push("\n\t\t\tif(!"+ia.toString()+
".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringAlphadash",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.hex&&c.push("\n\t\t\tif(value.length % 2 !== 0 || !"+ja.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringHex",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.singleLine&&c.push('\n\t\t\tif(value.includes("\\n")) {\n\t\t\t\t'+this.makeError({type:"stringSingleLine",messages:a})+"\n\t\t\t}\n\t\t");!0===b.base64&&c.push("\n\t\t\tif(!"+ka.toString()+
".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringBase64",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");c.push("\n\t\treturn value;\n\t");return{sanitized:d,source:c.join("\n")}}function n(a,b,c){b=a.schema;var d=a.messages;a=a.index;var f=[];c.customs[a]?c.customs[a].schema=b:c.customs[a]={schema:b};f.push("\n\t\tconst ObjectID = context.customs["+a+"].schema.ObjectID;\n\t\tif (!ObjectID.isValid(value)) {\n\t\t\t"+this.makeError({type:"objectID",actual:"value",messages:d})+"\n\t\t\treturn;\n\t\t}\n\t");
!0===b.convert?f.push("return new ObjectID(value)"):"hexString"===b.convert?f.push("return value.toString()"):f.push("return value");return{source:f.join("\n")}}function k(a,b,c){var d=a.schema;a=a.messages;var f=[];f.push('\n\t\tif (typeof value !== "object" || value === null || Array.isArray(value)) {\n\t\t\t'+this.makeError({type:"object",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\t");var r=d.properties||d.props;if(r){f.push("var parentObj = value;");f.push("var parentField = field;");
for(var v=Object.keys(r),z=0;z<v.length;z++){var A=v[z],D=N(A),O=la.test(D)?"."+D:"['"+D+"']",I="parentObj"+O,P=(b?b+".":"")+A;f.push("\n// Field: "+N(P));f.push('field = parentField ? parentField + "'+O+'" : "'+D+'";');f.push("value = "+I+";");A=this.getRuleFromSchema(r[A]);f.push(this.compileRule(A,c,P,"\n\t\t\t\t"+I+" = "+(c.async?"await ":"")+"context.fn[%%INDEX%%](value, field, parentObj, errors, context);\n\t\t\t",I))}d.strict&&(f.push("\n\t\t\t\tif (errors.length === 0) {\n\t\t\t"),b=Object.keys(r),
f.push("\n\t\t\t\t\tfield = parentField;\n\t\t\t\t\tvar invalidProps = [];\n\t\t\t\t\tvar props = Object.keys(parentObj);\n\n\t\t\t\t\tfor (let i = 0; i < props.length; i++) {\n\t\t\t\t\t\tif ("+JSON.stringify(b)+".indexOf(props[i]) === -1) {\n\t\t\t\t\t\t\tinvalidProps.push(props[i]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (invalidProps.length) {\n\t\t\t"),"remove"==d.strict?f.push("\n\t\t\t\t\t\tinvalidProps.forEach(function(field) {\n\t\t\t\t\t\t\tdelete parentObj[field];\n\t\t\t\t\t\t});\n\t\t\t\t"):
f.push("\n\t\t\t\t\t"+this.makeError({type:"objectStrict",expected:'"'+b.join(", ")+'"',actual:"invalidProps.join(', ')",messages:a})+"\n\t\t\t\t"),f.push("\n\t\t\t\t\t}\n\t\t\t"),f.push("\n\t\t\t\t}\n\t\t\t"))}if(null!=d.minProps||null!=d.maxProps)d.strict?f.push("\n\t\t\t\tprops = Object.keys("+(r?"parentObj":"value")+");\n\t\t\t"):f.push("\n\t\t\t\tvar props = Object.keys("+(r?"parentObj":"value")+");\n\t\t\t\t"+(r?"field = parentField;":"")+"\n\t\t\t");null!=d.minProps&&f.push("\n\t\t\tif (props.length < "+
d.minProps+") {\n\t\t\t\t"+this.makeError({type:"objectMinProps",expected:d.minProps,actual:"props.length",messages:a})+"\n\t\t\t}\n\t\t");null!=d.maxProps&&f.push("\n\t\t\tif (props.length > "+d.maxProps+") {\n\t\t\t\t"+this.makeError({type:"objectMaxProps",expected:d.maxProps,actual:"props.length",messages:a})+"\n\t\t\t}\n\t\t");r?f.push("\n\t\t\treturn parentObj;\n\t\t"):f.push("\n\t\t\treturn value;\n\t\t");return{source:f.join("\n")}}function p(a){var b=a.schema;a=a.messages;var c=[];c.push("\n\t\tvar origValue = value;\n\t");
var d=!1;!0===b.convert&&(d=!0,c.push('\n\t\t\tif (typeof value !== "number") {\n\t\t\t\tvalue = Number(value);\n\t\t\t}\n\t\t'));c.push('\n\t\tif (typeof value !== "number" || isNaN(value) || !isFinite(value)) {\n\t\t\t'+this.makeError({type:"number",actual:"origValue",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\t");null!=b.min&&c.push("\n\t\t\tif (value < "+b.min+") {\n\t\t\t\t"+this.makeError({type:"numberMin",expected:b.min,actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");null!=b.max&&c.push("\n\t\t\tif (value > "+
b.max+") {\n\t\t\t\t"+this.makeError({type:"numberMax",expected:b.max,actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");null!=b.equal&&c.push("\n\t\t\tif (value !== "+b.equal+") {\n\t\t\t\t"+this.makeError({type:"numberEqual",expected:b.equal,actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");null!=b.notEqual&&c.push("\n\t\t\tif (value === "+b.notEqual+") {\n\t\t\t\t"+this.makeError({type:"numberNotEqual",expected:b.notEqual,actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.integer&&c.push("\n\t\t\tif (value % 1 !== 0) {\n\t\t\t\t"+
this.makeError({type:"numberInteger",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.positive&&c.push("\n\t\t\tif (value <= 0) {\n\t\t\t\t"+this.makeError({type:"numberPositive",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.negative&&c.push("\n\t\t\tif (value >= 0) {\n\t\t\t\t"+this.makeError({type:"numberNegative",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");c.push("\n\t\treturn value;\n\t");return{sanitized:d,source:c.join("\n")}}function u(a,b,c){var d=a.schema;a.messages;
a=[];a.push("\n\t\tvar hasValid = false;\n\t\tvar newVal = value;\n\t\tvar checkErrors = [];\n\t");for(var f=0;f<d.rules.length;f++){a.push("\n\t\t\tif (!hasValid) {\n\t\t\t\tvar _errors = [];\n\t\t");var r=this.getRuleFromSchema(d.rules[f]);a.push(this.compileRule(r,c,b,"var tmpVal = "+(c.async?"await ":"")+"context.fn[%%INDEX%%](value, field, parent, _errors, context);","tmpVal"));a.push("\n\t\t\t\tif (_errors.length == 0) {\n\t\t\t\t\thasValid = true;\n\t\t\t\t\tnewVal = tmpVal;\n\t\t\t\t} else {\n\t\t\t\t\tArray.prototype.push.apply(checkErrors, _errors);\n\t\t\t\t}\n\t\t\t}\n\t\t")}a.push("\n\t\tif (!hasValid) {\n\t\t\tArray.prototype.push.apply(errors, checkErrors);\n\t\t}\n\n\t\treturn newVal;\n\t");
return{source:a.join("\n")}}function C(a){a.schema;return{source:'\n\t\t\tif (typeof value !== "function")\n\t\t\t\t'+this.makeError({type:"function",actual:"value",messages:a.messages})+"\n\n\t\t\treturn value;\n\t\t"}}function aa(a){var b=a.schema;a=a.messages;var c=[];c.push("\n\t\tif (value !== null && value !== undefined) {\n\t");b.remove?c.push("\n\t\t\treturn undefined;\n\t\t"):c.push("\n\t\t\t"+this.makeError({type:"forbidden",actual:"value",messages:a})+"\n\t\t");c.push("\n\t\t}\n\n\t\treturn value;\n\t");
!1===b.empty?c.push("\n\t\t\tif (len === 0) {\n\t\t\t\t"+this.makeError({type:"stringEmpty",actual:"value",messages:a})+"\n\t\t\t}\n\t\t"):!0===b.empty&&c.push("\n\t\t\tif (len === 0) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t");null!=b.min&&c.push("\n\t\t\tif (len < "+b.min+") {\n\t\t\t\t"+this.makeError({type:"stringMin",expected:b.min,actual:"len",messages:a})+"\n\t\t\t}\n\t\t");null!=b.max&&c.push("\n\t\t\tif (len > "+b.max+") {\n\t\t\t\t"+this.makeError({type:"stringMax",expected:b.max,actual:"len",
messages:a})+"\n\t\t\t}\n\t\t");null!=b.length&&c.push("\n\t\t\tif (len !== "+b.length+") {\n\t\t\t\t"+this.makeError({type:"stringLength",expected:b.length,actual:"len",messages:a})+"\n\t\t\t}\n\t\t");if(null!=b.pattern){var f=b.pattern;"string"==typeof b.pattern&&(f=new RegExp(b.pattern,b.patternFlags));c.push("\n\t\t\tif (!"+f.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringPattern",expected:'"'+f.toString().replace(/"/g,"\\$&")+'"',actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t")}null!=
b.contains&&c.push('\n\t\t\tif (value.indexOf("'+b.contains+'") === -1) {\n\t\t\t\t'+this.makeError({type:"stringContains",expected:'"'+b.contains+'"',actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");null!=b.enum&&(f=JSON.stringify(b.enum),c.push("\n\t\t\tif ("+f+".indexOf(value) === -1) {\n\t\t\t\t"+this.makeError({type:"stringEnum",expected:'"'+b.enum.join(", ")+'"',actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t"));!0===b.numeric&&c.push("\n\t\t\tif (!"+fa.toString()+".test(value) ) {\n\t\t\t\t"+
this.makeError({type:"stringNumeric",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.alpha&&c.push("\n\t\t\tif(!"+ha.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringAlpha",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.alphanum&&c.push("\n\t\t\tif(!"+ia.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringAlphanum",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.alphadash&&c.push("\n\t\t\tif(!"+ja.toString()+".test(value)) {\n\t\t\t\t"+
this.makeError({type:"stringAlphadash",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.hex&&c.push("\n\t\t\tif(value.length % 2 !== 0 || !"+ka.toString()+".test(value)) {\n\t\t\t\t"+this.makeError({type:"stringHex",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.singleLine&&c.push('\n\t\t\tif(value.includes("\\n")) {\n\t\t\t\t'+this.makeError({type:"stringSingleLine",messages:a})+"\n\t\t\t}\n\t\t");!0===b.base64&&c.push("\n\t\t\tif(!"+la.toString()+".test(value)) {\n\t\t\t\t"+
this.makeError({type:"stringBase64",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");c.push("\n\t\treturn value;\n\t");return{sanitized:d,source:c.join("\n")}}function n(a,b,c){var d=a.schema,f=[];f.push('\n\t\tif (typeof value !== "object" || value === null || Array.isArray(value)) {\n\t\t\t'+this.makeError({type:"record",actual:"value",messages:a.messages})+"\n\t\t\treturn value;\n\t\t}\n\t");a=d.key||"string";d=d.value||"any";f.push("\n\t\tlet tmp;\n\t\tfor (let key in value) {\n\t");a=this.getRuleFromSchema(a);
for(var r in a.messages)r.startsWith("string")&&(a.messages[r]=a.messages[r].replace(" field "," key "));f.push(this.compileRule(a,c,null,"\n\t\ttmp = "+(c.async?"await ":"")+'context.fn[%%INDEX%%](key, field ? field + "." + key : key, value, errors, context);\n\t',"tmp"));r=this.getRuleFromSchema(d);f.push(this.compileRule(r,c,b+"[key]","\n\t\ttmp = "+(c.async?"await ":"")+'context.fn[%%INDEX%%](value[key], field ? field + "." + key : key, value, errors, context);\n\t',"tmp"));f.push("\n\t\t}\n\t");
return{source:f.join("\n")}}function k(a,b,c){b=a.schema;var d=a.messages;a=a.index;var f=[];c.customs[a]?c.customs[a].schema=b:c.customs[a]={schema:b};f.push("\n\t\tconst ObjectID = context.customs["+a+"].schema.ObjectID;\n\t\tif (!ObjectID.isValid(value)) {\n\t\t\t"+this.makeError({type:"objectID",actual:"value",messages:d})+"\n\t\t\treturn;\n\t\t}\n\t");!0===b.convert?f.push("return new ObjectID(value)"):"hexString"===b.convert?f.push("return value.toString()"):f.push("return value");return{source:f.join("\n")}}
function p(a,b,c){var d=a.schema;a=a.messages;var f=[];f.push('\n\t\tif (typeof value !== "object" || value === null || Array.isArray(value)) {\n\t\t\t'+this.makeError({type:"object",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\t");var r=d.properties||d.props;if(r){f.push("var parentObj = value;");f.push("var parentField = field;");for(var v=Object.keys(r),z=0;z<v.length;z++){var A=v[z],D=N(A),O=ma.test(D)?"."+D:"['"+D+"']",I="parentObj"+O,P=(b?b+".":"")+A;f.push("\n// Field: "+N(P));
f.push('field = parentField ? parentField + "'+O+'" : "'+D+'";');f.push("value = "+I+";");A=this.getRuleFromSchema(r[A]);f.push(this.compileRule(A,c,P,"\n\t\t\t\t"+I+" = "+(c.async?"await ":"")+"context.fn[%%INDEX%%](value, field, parentObj, errors, context);\n\t\t\t",I))}d.strict&&(b=Object.keys(r),f.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(b)+
".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"===d.strict?(f.push("\n\t\t\t\t\tif (errors.length === 0) {\n\t\t\t\t"),f.push("\n\t\t\t\t\t\tinvalidProps.forEach(function(field) {\n\t\t\t\t\t\t\tdelete parentObj[field];\n\t\t\t\t\t\t});\n\t\t\t\t"),f.push("\n\t\t\t\t\t}\n\t\t\t\t")):f.push("\n\t\t\t\t\t"+this.makeError({type:"objectStrict",expected:'"'+b.join(", ")+'"',actual:"invalidProps.join(', ')",
messages:a})+"\n\t\t\t\t"),f.push("\n\t\t\t\t}\n\t\t\t"))}if(null!=d.minProps||null!=d.maxProps)d.strict?f.push("\n\t\t\t\tprops = Object.keys("+(r?"parentObj":"value")+");\n\t\t\t"):f.push("\n\t\t\t\tvar props = Object.keys("+(r?"parentObj":"value")+");\n\t\t\t\t"+(r?"field = parentField;":"")+"\n\t\t\t");null!=d.minProps&&f.push("\n\t\t\tif (props.length < "+d.minProps+") {\n\t\t\t\t"+this.makeError({type:"objectMinProps",expected:d.minProps,actual:"props.length",messages:a})+"\n\t\t\t}\n\t\t");
null!=d.maxProps&&f.push("\n\t\t\tif (props.length > "+d.maxProps+") {\n\t\t\t\t"+this.makeError({type:"objectMaxProps",expected:d.maxProps,actual:"props.length",messages:a})+"\n\t\t\t}\n\t\t");r?f.push("\n\t\t\treturn parentObj;\n\t\t"):f.push("\n\t\t\treturn value;\n\t\t");return{source:f.join("\n")}}function u(a){var b=a.schema;a=a.messages;var c=[];c.push("\n\t\tvar origValue = value;\n\t");var d=!1;!0===b.convert&&(d=!0,c.push('\n\t\t\tif (typeof value !== "number") {\n\t\t\t\tvalue = Number(value);\n\t\t\t}\n\t\t'));
c.push('\n\t\tif (typeof value !== "number" || isNaN(value) || !isFinite(value)) {\n\t\t\t'+this.makeError({type:"number",actual:"origValue",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\t");null!=b.min&&c.push("\n\t\t\tif (value < "+b.min+") {\n\t\t\t\t"+this.makeError({type:"numberMin",expected:b.min,actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");null!=b.max&&c.push("\n\t\t\tif (value > "+b.max+") {\n\t\t\t\t"+this.makeError({type:"numberMax",expected:b.max,actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");
null!=b.equal&&c.push("\n\t\t\tif (value !== "+b.equal+") {\n\t\t\t\t"+this.makeError({type:"numberEqual",expected:b.equal,actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");null!=b.notEqual&&c.push("\n\t\t\tif (value === "+b.notEqual+") {\n\t\t\t\t"+this.makeError({type:"numberNotEqual",expected:b.notEqual,actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.integer&&c.push("\n\t\t\tif (value % 1 !== 0) {\n\t\t\t\t"+this.makeError({type:"numberInteger",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");
!0===b.positive&&c.push("\n\t\t\tif (value <= 0) {\n\t\t\t\t"+this.makeError({type:"numberPositive",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");!0===b.negative&&c.push("\n\t\t\tif (value >= 0) {\n\t\t\t\t"+this.makeError({type:"numberNegative",actual:"origValue",messages:a})+"\n\t\t\t}\n\t\t");c.push("\n\t\treturn value;\n\t");return{sanitized:d,source:c.join("\n")}}function C(a,b,c){var d=a.schema;a.messages;a=[];a.push("\n\t\tvar hasValid = false;\n\t\tvar newVal = value;\n\t\tvar checkErrors = [];\n\t\tvar errorsSize = errors.length;\n\t");
for(var f=0;f<d.rules.length;f++){a.push("\n\t\t\tif (!hasValid) {\n\t\t\t\tvar _errors = [];\n\t\t");var r=this.getRuleFromSchema(d.rules[f]);a.push(this.compileRule(r,c,b,"var tmpVal = "+(c.async?"await ":"")+"context.fn[%%INDEX%%](value, field, parent, _errors, context);","tmpVal"));a.push("\n\t\t\t\tif (errors.length == errorsSize && _errors.length == 0) {\n\t\t\t\t\thasValid = true;\n\t\t\t\t\tnewVal = tmpVal;\n\t\t\t\t} else {\n\t\t\t\t\tArray.prototype.push.apply(checkErrors, [].concat(_errors, errors.splice(errorsSize)));\n\t\t\t\t}\n\t\t\t}\n\t\t")}a.push("\n\t\tif (!hasValid) {\n\t\t\tArray.prototype.push.apply(errors, checkErrors);\n\t\t}\n\n\t\treturn newVal;\n\t");
return{source:a.join("\n")}}function ba(a){a.schema;return{source:'\n\t\t\tif (typeof value !== "function")\n\t\t\t\t'+this.makeError({type:"function",actual:"value",messages:a.messages})+"\n\n\t\t\treturn value;\n\t\t"}}function aa(a){var b=a.schema;a=a.messages;var c=[];c.push("\n\t\tif (value !== null && value !== undefined) {\n\t");b.remove?c.push("\n\t\t\treturn undefined;\n\t\t"):c.push("\n\t\t\t"+this.makeError({type:"forbidden",actual:"value",messages:a})+"\n\t\t");c.push("\n\t\t}\n\n\t\treturn value;\n\t");
return{source:c.join("\n")}}function Z(a){var b=a.schema;a=a.messages;var c=[];b.field?(b.strict?c.push('\n\t\t\t\tif (value !== parent["'+b.field+'"])\n\t\t\t'):c.push('\n\t\t\t\tif (value != parent["'+b.field+'"])\n\t\t\t'),c.push("\n\t\t\t\t"+this.makeError({type:"equalField",actual:"value",expected:JSON.stringify(b.field),messages:a})+"\n\t\t")):(b.strict?c.push("\n\t\t\t\tif (value !== "+JSON.stringify(b.value)+")\n\t\t\t"):c.push("\n\t\t\t\tif (value != "+JSON.stringify(b.value)+")\n\t\t\t"),
c.push("\n\t\t\t\t"+this.makeError({type:"equalValue",actual:"value",expected:JSON.stringify(b.value),messages:a})+"\n\t\t"));c.push("\n\t\treturn value;\n\t");return{source:c.join("\n")}}function Y(a){var b=a.schema;a=a.messages;return{source:"\n\t\t\tif ("+JSON.stringify(b.values||[])+".indexOf(value) === -1)\n\t\t\t\t"+this.makeError({type:"enumValue",expected:'"'+b.values.join(", ")+'"',actual:"value",messages:a})+"\n\t\t\t\n\t\t\treturn value;\n\t\t"}}function X(a){var b=a.schema;a=a.messages;
var c=[],d="precise"==b.mode?ma:na,f=!1;c.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+this.makeError({type:"string",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\t");b.empty?c.push("\n\t\t\tif (value.length === 0) return value;\n\t\t"):c.push("\n\t\t\tif (value.length === 0) {\n\t\t\t\t"+this.makeError({type:"emailEmpty",actual:"value",messages:a})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t");b.normalize&&(f=!0,c.push("\n\t\t\tvalue = value.trim().toLowerCase();\n\t\t"));null!=
var c=[],d="precise"==b.mode?na:oa,f=!1;c.push('\n\t\tif (typeof value !== "string") {\n\t\t\t'+this.makeError({type:"string",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\t");b.empty?c.push("\n\t\t\tif (value.length === 0) return value;\n\t\t"):c.push("\n\t\t\tif (value.length === 0) {\n\t\t\t\t"+this.makeError({type:"emailEmpty",actual:"value",messages:a})+"\n\t\t\t\treturn value;\n\t\t\t}\n\t\t");b.normalize&&(f=!0,c.push("\n\t\t\tvalue = value.trim().toLowerCase();\n\t\t"));null!=
b.min&&c.push("\n\t\t\tif (value.length < "+b.min+") {\n\t\t\t\t"+this.makeError({type:"emailMin",expected:b.min,actual:"value.length",messages:a})+"\n\t\t\t}\n\t\t");null!=b.max&&c.push("\n\t\t\tif (value.length > "+b.max+") {\n\t\t\t\t"+this.makeError({type:"emailMax",expected:b.max,actual:"value.length",messages:a})+"\n\t\t\t}\n\t\t");c.push("\n\t\tif (!"+d.toString()+".test(value)) {\n\t\t\t"+this.makeError({type:"email",actual:"value",messages:a})+"\n\t\t}\n\n\t\treturn value;\n\t");return{sanitized:f,
source:c.join("\n")}}function W(a){var b=a.schema;a=a.messages;var c=[],d=!1;c.push("\n\t\tvar origValue = value;\n\t");!0===b.convert&&(d=!0,c.push("\n\t\t\tif (!(value instanceof Date)) {\n\t\t\t\tvalue = new Date(value);\n\t\t\t}\n\t\t"));c.push("\n\t\tif (!(value instanceof Date) || isNaN(value.getTime()))\n\t\t\t"+this.makeError({type:"date",actual:"origValue",messages:a})+"\n\n\t\treturn value;\n\t");return{sanitized:d,source:c.join("\n")}}function V(a){var b=a.schema;a=a.messages;var c=b.currencySymbol||
null,d=b.thousandSeparator||",",f=b.decimalSeparator||".",r=b.customRegex;b=!b.symbolOptional;b="(?=.*\\d)^(-?~1|~1-?)(([0-9]\\d{0,2}(~2\\d{3})*)|0)?(\\~3\\d{1,2})?$".replace(/~1/g,c?"\\"+c+(b?"":"?"):"").replace("~2",d).replace("~3",f);c=[];c.push("\n\t\tif (!value.match("+(r||new RegExp(b))+")) {\n\t\t\t"+this.makeError({type:"currency",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\n\t\treturn value;\n\t");return{source:c.join("\n")}}function U(a,b,c){var d=[];d.push("\n\t\t"+this.makeCustomValidator({fnName:"check",
path:b,schema:a.schema,messages:a.messages,context:c,ruleIndex:a.index})+"\n\t\treturn value;\n\t");return{source:d.join("\n")}}function T(a,b,c){b=a.schema;var d=a.messages;a=a.index;var f=[],r=b.instanceOf.name?b.instanceOf.name:"<UnknowClass>";c.customs[a]?c.customs[a].schema=b:c.customs[a]={schema:b};f.push("\n\t\tif (!(value instanceof context.customs["+a+"].schema.instanceOf))\n\t\t\t"+this.makeError({type:"classInstanceOf",actual:"value",expected:"'"+r+"'",messages:d})+"\n\t");f.push("\n\t\treturn value;\n\t");
return{source:f.join("\n")}}function S(a){var b=a.schema;a=a.messages;var c=[],d=!1;c.push("\n\t\tvar origValue = value;\n\t");!0===b.convert&&(d=!0,c.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'));
source:c.join("\n")}}function W(a){var b=a.schema;a=a.messages;var c=[],d=!1;c.push("\n\t\tvar origValue = value;\n\t");!0===b.convert&&(d=!0,c.push("\n\t\t\tif (!(value instanceof Date)) {\n\t\t\t\tvalue = new Date(value.length && !isNaN(+value) ? +value : value);\n\t\t\t}\n\t\t"));c.push("\n\t\tif (!(value instanceof Date) || isNaN(value.getTime()))\n\t\t\t"+this.makeError({type:"date",actual:"origValue",messages:a})+"\n\n\t\treturn value;\n\t");return{sanitized:d,source:c.join("\n")}}function V(a){var b=
a.schema;a=a.messages;var c=b.currencySymbol||null,d=b.thousandSeparator||",",f=b.decimalSeparator||".",r=b.customRegex;b=!b.symbolOptional;b="(?=.*\\d)^(-?~1|~1-?)(([0-9]\\d{0,2}(~2\\d{3})*)|0)?(\\~3\\d{1,2})?$".replace(/~1/g,c?"\\"+c+(b?"":"?"):"").replace("~2",d).replace("~3",f);c=[];c.push("\n\t\tif (!value.match("+(r||new RegExp(b))+")) {\n\t\t\t"+this.makeError({type:"currency",actual:"value",messages:a})+"\n\t\t\treturn value;\n\t\t}\n\n\t\treturn value;\n\t");return{source:c.join("\n")}}function U(a,
b,c){var d=[];d.push("\n\t\t"+this.makeCustomValidator({fnName:"check",path:b,schema:a.schema,messages:a.messages,context:c,ruleIndex:a.index})+"\n\t\treturn value;\n\t");return{source:d.join("\n")}}function T(a,b,c){b=a.schema;var d=a.messages;a=a.index;var f=[],r=b.instanceOf.name?b.instanceOf.name:"<UnknowClass>";c.customs[a]?c.customs[a].schema=b:c.customs[a]={schema:b};f.push("\n\t\tif (!(value instanceof context.customs["+a+"].schema.instanceOf))\n\t\t\t"+this.makeError({type:"classInstanceOf",
actual:"value",expected:"'"+r+"'",messages:d})+"\n\t");f.push("\n\t\treturn value;\n\t");return{source:f.join("\n")}}function S(a){var b=a.schema;a=a.messages;var c=[],d=!1;c.push("\n\t\tvar origValue = value;\n\t");!0===b.convert&&(d=!0,c.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'));
c.push('\n\t\tif (typeof value !== "boolean") {\n\t\t\t'+this.makeError({type:"boolean",actual:"origValue",messages:a})+"\n\t\t}\n\t\t\n\t\treturn value;\n\t");return{sanitized:d,source:c.join("\n")}}function R(a,b,c){var d=a.schema,f=a.messages;a=[];a.push("\n\t\tif (!Array.isArray(value)) {\n\t\t\t"+this.makeError({type:"array",actual:"value",messages:f})+"\n\t\t\treturn value;\n\t\t}\n\n\t\tvar len = value.length;\n\t");!1===d.empty&&a.push("\n\t\t\tif (len === 0) {\n\t\t\t\t"+this.makeError({type:"arrayEmpty",

@@ -66,4 +69,4 @@ actual:"value",messages:f})+"\n\t\t\t}\n\t\t");null!=d.min&&a.push("\n\t\t\tif (len < "+d.min+") {\n\t\t\t\t"+this.makeError({type:"arrayMin",expected:d.min,actual:"len",messages:f})+"\n\t\t\t}\n\t\t");null!=d.max&&a.push("\n\t\t\tif (len > "+d.max+") {\n\t\t\t\t"+this.makeError({type:"arrayMax",expected:d.max,actual:"len",messages:f})+"\n\t\t\t}\n\t\t");null!=d.length&&a.push("\n\t\t\tif (len !== "+d.length+") {\n\t\t\t\t"+this.makeError({type:"arrayLength",expected:d.length,actual:"len",messages:f})+

d.enum){var r=JSON.stringify(d.enum);a.push("\n\t\t\tfor (var i = 0; i < value.length; i++) {\n\t\t\t\tif ("+r+".indexOf(value[i]) === -1) {\n\t\t\t\t\t"+this.makeError({type:"arrayEnum",expected:'"'+d.enum.join(", ")+'"',actual:"value[i]",messages:f})+"\n\t\t\t\t}\n\t\t\t}\n\t\t")}null!=d.items?(a.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"),b+="[]",d=this.getRuleFromSchema(d.items),a.push(this.compileRule(d,
c,b,"arr[i] = "+(c.async?"await ":"")+'context.fn[%%INDEX%%](arr[i], (parentField ? parentField : "") + "[" + i + "]", parent, errors, context)',"arr[i]")),a.push("\n\t\t\t}\n\t\t"),a.push("\n\t\treturn arr;\n\t")):a.push("\n\t\treturn value;\n\t");return{source:a.join("\n")}}function Q(){var a=[];a.push("\n\t\treturn value;\n\t");return{source:a.join("\n")}}function oa(a,b,c){return a.replace(b,void 0===c||null===c?"":"function"===typeof c.toString?c:typeof c)}function B(a,b,c){void 0===c&&(c={});
for(var d in b){var f=b[d];f="object"!==typeof f||Array.isArray(f)||null==f?!1:0<Object.keys(f).length;if(f)a[d]=a[d]||{},B(a[d],b[d],c);else if(!0!==c.skipIfExist||void 0===a[d])a[d]=b[d]}return a}function N(a){return a.replace(pa,function(b){switch(b){case '"':case "'":case "\\":return"\\"+b;case "\n":return"\\n";case "\r":return"\\r";case "\u2028":return"\\u2028";case "\u2029":return"\\u2029"}})}function K(){throw Error("Dynamic requires are not currently supported by rollup-plugin-commonjs");
c,b,"arr[i] = "+(c.async?"await ":"")+'context.fn[%%INDEX%%](arr[i], (parentField ? parentField : "") + "[" + i + "]", parent, errors, context)',"arr[i]")),a.push("\n\t\t\t}\n\t\t"),a.push("\n\t\treturn arr;\n\t")):a.push("\n\t\treturn value;\n\t");return{source:a.join("\n")}}function Q(){var a=[];a.push("\n\t\treturn value;\n\t");return{source:a.join("\n")}}function pa(a,b,c){return a.replace(b,void 0===c||null===c?"":"function"===typeof c.toString?c:typeof c)}function B(a,b,c){void 0===c&&(c={});
for(var d in b){var f=b[d];f="object"!==typeof f||Array.isArray(f)||null==f?!1:0<Object.keys(f).length;if(f)a[d]=a[d]||{},B(a[d],b[d],c);else if(!0!==c.skipIfExist||void 0===a[d])a[d]=b[d]}return a}function N(a){return a.replace(qa,function(b){switch(b){case '"':case "'":case "\\":return"\\"+b;case "\n":return"\\n";case "\r":return"\\r";case "\u2028":return"\\u2028";case "\u2029":return"\\u2029"}})}function K(){throw Error("Dynamic requires are not currently supported by rollup-plugin-commonjs");
}var q={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.",

@@ -76,9 +79,9 @@ 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.",

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"};q.required;q.string;q.stringEmpty;q.stringMin;q.stringMax;q.stringLength;q.stringPattern;q.stringContains;q.stringEnum;q.stringNumeric;q.stringAlpha;q.stringAlphanum;q.stringAlphadash;q.stringHex;q.stringSingleLine;q.stringBase64;q.number;q.numberMin;q.numberMax;q.numberEqual;q.numberNotEqual;
q.numberInteger;q.numberPositive;q.numberNegative;q.array;q.arrayEmpty;q.arrayMin;q.arrayMax;q.arrayLength;q.arrayContains;q.arrayUnique;q.arrayEnum;q.tuple;q.tupleEmpty;q.tupleLength;q.currency;q.date;q.dateMin;q.dateMax;q.enumValue;q.equalValue;q.equalField;q.forbidden;q.email;q.emailEmpty;q.emailMin;q.emailMax;q.luhn;q.mac;q.object;q.objectStrict;q.objectMinProps;q.objectMaxProps;q.url;q.urlEmpty;q.uuid;q.uuidVersion;q.classInstanceOf;q.objectID;var ma=/^(([^<>()[\]\\.,;:\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,}))$/,
na=/^\S+@\S+\.\S+$/,la=/^[_$a-zA-Z][_$a-zA-Z0-9]*$/,pa=/["'\\\n\r\u2028\u2029]/g,ea=/^-?[0-9]\d*(\.\d+)?$/,fa=/^[a-zA-Z]+$/,ha=/^[a-zA-Z0-9]+$/,ia=/^[a-zA-Z0-9_-]+$/,ja=/^[0-9a-fA-F]+$/,ka=/^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+/]{3}=)?$/,da=/^https?:\/\/\S+/,ca=/^([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,ba=/^((([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,
G,L,H,M;try{var J=(new Function("return Object.getPrototypeOf(async function(){}).constructor"))()}catch(a){}e.prototype.validate=function(a,b){return this.compile(b)(a)};e.prototype.wrapRequiredCheckSourceCode=function(a,b,c,d){var f=[],r=!0===a.schema.optional||"forbidden"===a.schema.type,v=!0===a.schema.optional||!0===a.schema.nullable||"forbidden"===a.schema.type;null!=a.schema.default?(r=!1,!0!==a.schema.nullable&&(v=!1),"function"===typeof a.schema.default?(c.customs[a.index]||(c.customs[a.index]=
{}),c.customs[a.index].defaultFn=a.schema.default,a="context.customs["+a.index+"].defaultFn.call(this, context.rules["+a.index+"].schema, field, parent, context)"):a=JSON.stringify(a.schema.default),d="\n\t\t\t\tvalue = "+a+";\n\t\t\t\t"+d+" = value;\n\t\t\t"):d=this.makeError({type:"required",actual:"value",messages:a.messages});f.push("\n\t\t\tif (value === undefined) { "+((r?"\n// allow undefined\n":d)+" }\n\t\t\telse if (value === null) { ")+((v?"\n// allow null\n":d)+" }\n\t\t\t")+(b?"else { "+
b+" }":"")+"\n\t\t");return f.join("\n")};e.prototype.compile=function(a){function b(v,z){d.data=v;z&&z.meta&&(d.meta=z.meta);return r.call(c,v,d)}if(null===a||"object"!==typeof a)throw Error("Invalid schema.");var c=this,d={index:0,async:!0===a.$$async,rules:[],fn:[],customs:{},utils:{replace:oa}};this.cache.clear();delete a.$$async;if(d.async&&!J)throw Error("Asynchronous mode is not supported.");if(!0!==a.$$root)if(Array.isArray(a))a=this.getRuleFromSchema(a).schema;else{var f=Object.assign({},
a);a={type:"object",strict:f.$$strict,properties:f};delete f.$$strict}f=["var errors = [];","var field;","var parent = null;"];a=this.getRuleFromSchema(a);f.push(this.compileRule(a,d,null,(d.async?"await ":"")+"context.fn[%%INDEX%%](value, field, null, errors, context);","value"));f.push("if (errors.length) {");f.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");
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",record:"The '{field}' must be an Object."};q.required;q.string;q.stringEmpty;q.stringMin;q.stringMax;q.stringLength;q.stringPattern;q.stringContains;q.stringEnum;q.stringNumeric;q.stringAlpha;q.stringAlphanum;q.stringAlphadash;q.stringHex;q.stringSingleLine;q.stringBase64;q.number;q.numberMin;
q.numberMax;q.numberEqual;q.numberNotEqual;q.numberInteger;q.numberPositive;q.numberNegative;q.array;q.arrayEmpty;q.arrayMin;q.arrayMax;q.arrayLength;q.arrayContains;q.arrayUnique;q.arrayEnum;q.tuple;q.tupleEmpty;q.tupleLength;q.currency;q.date;q.dateMin;q.dateMax;q.enumValue;q.equalValue;q.equalField;q.forbidden;q.email;q.emailEmpty;q.emailMin;q.emailMax;q.luhn;q.mac;q.object;q.objectStrict;q.objectMinProps;q.objectMaxProps;q.url;q.urlEmpty;q.uuid;q.uuidVersion;q.classInstanceOf;q.objectID;q.record;
var na=/^(([^<>()[\]\\.,;:\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,}))$/,oa=/^\S+@\S+\.\S+$/,ma=/^[_$a-zA-Z][_$a-zA-Z0-9]*$/,qa=/["'\\\n\r\u2028\u2029]/g,fa=/^-?[0-9]\d*(\.\d+)?$/,ha=/^[a-zA-Z]+$/,ia=/^[a-zA-Z0-9]+$/,ja=/^[a-zA-Z0-9_-]+$/,ka=/^[0-9a-fA-F]+$/,la=/^(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+/]{3}=)?$/,ea=/^https?:\/\/\S+/,da=/^([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,
ca=/^((([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,G,L,H,M;try{var J=(new Function("return Object.getPrototypeOf(async function(){}).constructor"))()}catch(a){}e.prototype.validate=function(a,b){return this.compile(b)(a)};e.prototype.wrapRequiredCheckSourceCode=function(a,b,c,d){var f=[],r=!0===a.schema.optional||"forbidden"===a.schema.type,v=!0===a.schema.optional||!0===a.schema.nullable||
"forbidden"===a.schema.type;null!=a.schema.default?(r=!1,!0!==a.schema.nullable&&(v=!1),"function"===typeof a.schema.default?(c.customs[a.index]||(c.customs[a.index]={}),c.customs[a.index].defaultFn=a.schema.default,a="context.customs["+a.index+"].defaultFn.call(this, context.rules["+a.index+"].schema, field, parent, context)"):a=JSON.stringify(a.schema.default),d="\n\t\t\t\tvalue = "+a+";\n\t\t\t\t"+d+" = value;\n\t\t\t"):d=this.makeError({type:"required",actual:"value",messages:a.messages});f.push("\n\t\t\tif (value === undefined) { "+
((r?"\n// allow undefined\n":d)+" }\n\t\t\telse if (value === null) { ")+((v?"\n// allow null\n":d)+" }\n\t\t\t")+(b?"else { "+b+" }":"")+"\n\t\t");return f.join("\n")};e.prototype.compile=function(a){function b(v,z){d.data=v;z&&z.meta&&(d.meta=z.meta);return r.call(c,v,d)}if(null===a||"object"!==typeof a)throw Error("Invalid schema.");var c=this,d={index:0,async:!0===a.$$async,rules:[],fn:[],customs:{},utils:{replace:pa}};this.cache.clear();delete a.$$async;if(d.async&&!J)throw Error("Asynchronous mode is not supported.");
if(!0!==a.$$root)if(Array.isArray(a))a=this.getRuleFromSchema(a).schema;else{var f=Object.assign({},a);a={type:"object",strict:f.$$strict,properties:f};delete f.$$strict}f=["var errors = [];","var field;","var parent = null;"];a=this.getRuleFromSchema(a);f.push(this.compileRule(a,d,null,(d.async?"await ":"")+"context.fn[%%INDEX%%](value, field, null, errors, context);","value"));f.push("if (errors.length) {");f.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");
f.push("}");f.push("return true;");a=f.join("\n");var r=new (d.async?J:Function)("value","context",a);this.opts.debug&&console.log(this._formatter("// Main check function\n"+r.toString()));this.cache.clear();b.async=d.async;return b};e.prototype.compileRule=function(a,b,c,d,f){var r=[],v=this.cache.get(a.schema);v?(a=v,a.cycle=!0,a.cycleStack=[],r.push(this.wrapRequiredCheckSourceCode(a,"\n\t\t\t\tvar rule = context.rules["+a.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"+

@@ -85,0 +88,0 @@ d.replace(/%%INDEX%%/g,a.index)+"\n\t\t\t\t\trule.cycleStack.pop(value);\n\t\t\t\t}\n\t\t\t",b,f))):(this.cache.set(a.schema,a),a.index=b.index,b.rules[b.index]=a,v=null!=c?c:"$$root",b.index++,c=a.ruleFunction.call(this,a,c,b),c.source=c.source.replace(/%%INDEX%%/g,a.index),c=new (b.async?J:Function)("value","field","parent","errors","context",c.source),b.fn[a.index]=c.bind(this),r.push(this.wrapRequiredCheckSourceCode(a,d.replace(/%%INDEX%%/g,a.index),b,f)),r.push(this.makeCustomValidator({vName:f,

@@ -20,2 +20,3 @@

| "object"
| "record"
| "string"

@@ -354,6 +355,7 @@ | "url"

/**
* if true any properties which are not defined on the schema will throw an error.
* If `true` any properties which are not defined on the schema will throw an error.<br>
* If `remove` all additional properties will be removed from the original object. It's a sanitizer, it will change the original object.
* @default false
*/
strict?: boolean;
strict?: boolean | "remove";
/**

@@ -389,2 +391,17 @@ * List of properties that should be validated by this rule

export interface RuleRecord extends RuleCustom {
/**
* Name of built-in validator
*/
type: "record";
/**
* Key validation rule
*/
key?: RuleString;
/**
* Value validation rule
*/
value?: ValidationRuleObject;
}
/**

@@ -809,2 +826,3 @@ * Validation schema definition for "string" built-in validator

| RuleObjectID
| RuleRecord
| RuleString

@@ -930,3 +948,3 @@ | RuleTuple

export interface Context {
export interface Context<DATA = any> {
index: number;

@@ -940,2 +958,3 @@ async: boolean;

meta?: object;
data: DATA;
}

@@ -942,0 +961,0 @@

@@ -84,2 +84,4 @@ "use strict";

objectID: "The '{field}' field must be an valid ObjectID",
record: "The '{field}' must be an Object."
};

@@ -17,3 +17,3 @@ "use strict";

if (!(value instanceof Date)) {
value = new Date(value);
value = new Date(value.length && !isNaN(+value) ? +value : value);
}

@@ -20,0 +20,0 @@ `);

@@ -12,2 +12,3 @@ "use strict";

var checkErrors = [];
var errorsSize = errors.length;
`);

@@ -24,7 +25,7 @@

src.push(`
if (_errors.length == 0) {
if (errors.length == errorsSize && _errors.length == 0) {
hasValid = true;
newVal = tmpVal;
} else {
Array.prototype.push.apply(checkErrors, _errors);
Array.prototype.push.apply(checkErrors, [].concat(_errors, errors.splice(errorsSize)));
}

@@ -31,0 +32,0 @@ }

@@ -72,21 +72,21 @@ "use strict";

if (schema.strict) {
sourceCode.push(`
if (errors.length === 0) {
`);
const allowedProps = Object.keys(subSchema);
sourceCode.push(`
field = parentField;
var invalidProps = [];
var props = Object.keys(parentObj);
field = parentField;
var invalidProps = [];
var props = Object.keys(parentObj);
for (let i = 0; i < props.length; i++) {
if (${JSON.stringify(allowedProps)}.indexOf(props[i]) === -1) {
invalidProps.push(props[i]);
}
for (let i = 0; i < props.length; i++) {
if (${JSON.stringify(allowedProps)}.indexOf(props[i]) === -1) {
invalidProps.push(props[i]);
}
if (invalidProps.length) {
}
if (invalidProps.length) {
`);
if (schema.strict == "remove") {
if (schema.strict === "remove") {
sourceCode.push(`
if (errors.length === 0) {
`);
sourceCode.push(`
invalidProps.forEach(function(field) {

@@ -96,2 +96,5 @@ delete parentObj[field];

`);
sourceCode.push(`
}
`);
} else {

@@ -103,5 +106,2 @@ sourceCode.push(`

sourceCode.push(`
}
`);
sourceCode.push(`
}

@@ -108,0 +108,0 @@ `);

@@ -109,2 +109,8 @@ "use strict";

`);
} else if (schema.empty === true) {
src.push(`
if (len === 0) {
return value;
}
`);
}

@@ -141,12 +147,5 @@

const patternValidator = `
if (!${pattern.toString()}.test(value))
src.push(`
if (!${pattern.toString()}.test(value)) {
${this.makeError({ type: "stringPattern", expected: `"${pattern.toString().replace(/"/g, "\\$&")}"`, actual: "origValue", messages })}
`;
src.push(`
if (${schema.empty} === true && len === 0) {
// Do nothing
} else {
${patternValidator}
}

@@ -153,0 +152,0 @@ `);

@@ -33,2 +33,3 @@ "use strict";

objectID: require("./rules/objectID"),
record: require("./rules/record"),
string: require("./rules/string"),

@@ -35,0 +36,0 @@ tuple: require("./rules/tuple"),

{
"name": "fastest-validator",
"version": "1.12.0",
"version": "1.13.0",
"description": "The fastest JS validator library for NodeJS",

@@ -52,10 +52,10 @@ "main": "index.js",

"coveralls": "^3.1.1",
"eslint": "^8.0.1",
"eslint": "^8.22.0",
"jest": "^27.2.5",
"jest-cli": "^27.2.5",
"mongodb": "^4.1.3",
"nodemon": "^2.0.13",
"npm-check": "^5.9.0",
"prettier": "^2.4.1",
"rollup": "^2.58.0",
"mongodb": "^4.8.1",
"nodemon": "^2.0.19",
"npm-check": "^6.0.1",
"prettier": "^2.7.1",
"rollup": "^2.78.0",
"rollup-plugin-buble": "^0.19.8",

@@ -66,5 +66,5 @@ "rollup-plugin-commonjs": "^10.1.0",

"ts-jest": "^27.0.7",
"ts-node": "^10.3.0",
"tsd": "^0.18.0",
"typescript": "^4.4.4"
"ts-node": "^10.9.1",
"tsd": "^0.22.0",
"typescript": "^4.7.4"
},

@@ -71,0 +71,0 @@ "jest": {

@@ -931,2 +931,26 @@ ![Photos from @ikukevk](https://user-images.githubusercontent.com/306521/30183963-9c722dca-941c-11e7-9e83-c78377ad7f9d.jpg)

## `record`
This validator allows to check an object with arbitrary keys.
```js
const schema = {
surnameGroups: {
type: 'record',
key: { type: 'string', alpha: true },
value: { type: 'array', items: 'string' }
}
};
const check = v.compile(schema);
check({ surnameGroups: { Doe: ['Jane', 'John'], Williams: ['Bill'] } }); // Valid
check({ surnameGroups: { Doe1: ['Jane', 'John'] } }); // Fail
check({ surnameGroups: { Doe: [1, 'Jane'] } }); // Fail
```
### Properties
Property | Default | Description
-------- |----------| -----------
`key` | `string` | Key validation rule (It is reasonable to use only the `string` rule).
`value` | `any` | Value validation rule.
## `string`

@@ -933,0 +957,0 @@ This is a `String` validator.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc