!function(e,r){"object"==typeofexports&&"undefined"!=typeofmodule?module.exports=r():"function"==typeofdefine&&define.amd?define(r):(e="undefined"!=typeofglobalThis?globalThis:e||self).AsyncValidator=r()}(this,(function(){"use strict";vare=function(r,n){returne=Object.setPrototypeOf||{__proto__:[]}instanceofArray&&function(e,r){e.__proto__=r}||function(e,r){for(varninr)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])},e(r,n)};varr=function(){returnr=Object.assign||function(e){for(varr,n=1,t=arguments.length;n<t;n++)for(variinr=arguments[n])Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i]);returne},r.apply(this,arguments)};functionn(e,r){varn="function"==typeofSymbol&&e[Symbol.iterator];if(!n)returne;vart,i,a=n.call(e),o=[];try{for(;(void0===r||r-->0)&&!(t=a.next()).done;)o.push(t.value)}catch(e){i={error:e}}finally{try{t&&!t.done&&(n=a.return)&&n.call(a)}finally{if(i)throwi.error}}returno}functiont(e,r,n){if(n||2===arguments.length)for(vart,i=0,a=r.length;i<a;i++)!t&&iinr||(t||(t=Array.prototype.slice.call(r,0,i)),t[i]=r[i]);returne.concat(t||Array.prototype.slice.call(r))}vari=/%[sdj%]/g,a=function(){};functiono(e){if(!e||!e.length)returnnull;varr={};returne.forEach((function(e){varn=e.field;r[n]=r[n]||[],r[n].push(e)})),r}functionu(e){for(varr=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];vart=0,a=r.length;if("function"==typeofe)returne.apply(null,r);if("string"==typeofe){varo=e.replace(i,(function(e){if("%%"===e)return"%";if(t>=a)returne;switch(e){case"%s":returnString(r[t++]);case"%d":returnNumber(r[t++]);case"%j":try{returnJSON.stringify(r[t++])}catch(e){return"[Circular]"}break;default:returne}}));returno}returne}functions(e,r){returnnull==e||(!("array"!==r||!Array.isArray(e)||e.length)||!(!function(e){return"string"===e||"url"===e||"hex"===e||"email"===e||"date"===e||"pattern"===e}(r)||"string"!=typeofe||e))}functionc(e,r,n){vart=0,i=e.length;!functiona(o){if(o&&o.length)n(o);else{varu=t;t+=1,u<i?r(e[u],a):n([])}}([])}"undefined"!=typeofprocess&&process.env&&"production"!==process.env.NODE_ENV&&"undefined"!=typeofwindow&&"undefined"!=typeofdocument&&(a=function(e,r){"undefined"!=typeofconsole&&console.warn&&"undefined"==typeofASYNC_VALIDATOR_NO_WARNING&&r.every((function(e){return"string"==typeofe}))&&console.warn(e,r)});varf=function(r){functionn(e,n){vart=r.call(this,"Async Validation Error")||this;returnt.errors=e,t.fields=n,t}returnfunction(r,n){if("function"!=typeofn&&null!==n)thrownewTypeError("Class extends value "+String(n)+" is not a constructor or null");functiont(){this.constructor=r}e(r,n),r.prototype=null===n?Object.create(n):(t.prototype=n.prototype,newt)}(n,r),n}(Error);functionl(e,r,i,a,u){if(r.first){vars=newPromise((function(r,s){varl=function(e){varr=[];returnObject.keys(e).forEach((function(i){r.push.apply(r,t([],n(e[i]||[]),!1))})),r}(e);c(l,i,(function(e){returna(e),e.length?s(newf(e,o(e))):r(u)}))}));returns.catch((function(e){returne})),s}varl=!0===r.firstFields?Object.keys(e):r.firstFields||[],d=Object.keys(e),p=d.length,y=0,g=[],h=newPromise((function(r,s){varh=function(e){if(g.push.apply(g,e),++y===p)returna(g),g.length?s(newf(g,o(g))):r(u)};d.length||(a(g),r(u)),d.forEach((function(r){vara=e[r];-1!==l.indexOf(r)?c(a,i,h):function(e,r,i){vara=[],o=0,u=e.length;functions(e){a.push.apply(a,t([],n(e||[]),!1)),++o===u&&i(a)}e.forEach((function(e){r(e,s)}))}(a,i,h)}))}));returnh.catch((function(e){returne})),h}functiond(e,r){returnfunction(n){vart,i;returnt=e.fullFields?function(e,r){for(varn=e,t=0;t<r.length;t++){if(null==n)returnn;n=n[r[t]]}returnn}(r,e.fullFields):r[n.field||e.fullField],(i=n)&&void0!==i.message?(n.field=n.field||e.fullField,n.fieldValue=t,n):{message:"function"==typeofn?n():n,fieldValue:t,field:n.field||e.fullField}}}functionp(e,n){if(n)for(vartinn)if(n.hasOwnProperty(t)){vari=n[t];"object"==typeofi&&"object"==typeofe[t]?e[t]=r(r({},e[t]),i):e[t]=i}returne}vary,g=function(e,r,n,t,i,a){!e.required||n.hasOwnProperty(e.field)&&!s(r,a||e.type)||t.push(u(i.messages.required,e.fullField))},h=/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/,m=/^#?([a-f0-9]{6}|[a-f0-9]{3})$/i,v={integer:function(e){returnv.number(e)&&parseInt(e,10)===e},float:function(e){returnv.number(e)&&!v.integer(e)},array:function(e){returnArray.isArray(e)},regexp:function(e){if(einstanceofRegExp)return!0;try{return!!newRegExp(e)}catch(e){return!1}},date:function(e){return"function"==typeofe.getTime&&"function"==typeofe.getMonth&&"function"==typeofe.getYear&&!isNaN(e.getTime())},number:function(e){return!isNaN(e)&&"number"==typeofe},object:function(e){return"object"==typeofe&&!v.array(e)},method:function(e){return"function"==typeofe},email:function(e){return"string"==typeofe&&e.length<=320&&!!e.match(h)},url:function(e){return"string"==typeofe&&e.length<=2048&&!!e.match(function(){if(y)returny;vare="[a-fA-F\\d:]",r=function(r){returnr&&r.includeBoundaries?"(?:(?<=\\s|^)(?=".concat(e,")|(?<=").concat(e,")(?=\\s|$))"):""},n="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",t="[a-fA-F\\d]{1,4}",i="\n(?:\n(?:".concat(t,":){7}(?:").concat(t,"|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8\n(?:").concat(t,":){6}(?:").concat(n,"|:").concat(t,"|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4\n(?:").concat(t,":){5}(?::").concat(n,"|(?::").concat(t,"){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4\n(?:").concat(t,":){4}(?:(?::").concat(t,"){0,1}:").concat(n,"|(?::").concat(t,"){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4\n(?:").concat(t,":){3}(?:(?::").concat(t,"){0,2}:").concat(n,"|(?::").concat(t,"){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4\n(?:").concat(t,":){2}(?:(?::").concat(t,"){0,3}:").concat(n,"|(?::").concat(t,"){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4\n(?:").concat(t,":){1}(?:(?::").concat(t,"){0,4}:").concat(n,"|(?::").concat(t,"){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4\n(?::(?:(?::").concat(t,"){0,5}:").concat(n,"|(?::").concat(t,"){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4\n)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1\n").replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),a=newRegExp("(?:^".concat(n,"$)|(?:^").concat(i,"$)")),o=newRegExp("^".concat(n,"$")),u=newRegExp("^".concat(i,"$")),s=function(e){returne&&e.exact?a:newRegExp("(?:".concat(r(e)).concat(n).concat(r(e),")|(?:").concat(r(e)).concat(i).concat(r(e),")"),"g")};s.v4=function(e){returne&&e.exact?o:newRegExp("".concat(r(e)).concat(n).concat(r(e)),"g")},s.v6=function(e){returne&&e.exact?u:newRegExp("".concat(r(e)).concat(i).concat(r(e)),"g")};varc=s.v4().source,f=s.v6().source,l="(?:".concat("(?:(?:[a-z]+:)?//)","|www\\.)").concat("(?:\\S+(?::\\S*)?@)?","(?:localhost|").concat(c,"|").concat(f,"|").concat("(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)").concat("(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*").concat("(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))",")").concat("(?::\\d{2,5})?").concat('(?:[/?#][^\\s"]*)?');returny=newRegExp("(?:^".concat(l,"$)"),"i")}())},hex:function(e){return"string"==typeofe&&!!e.match(m)}},q={required:g,whitespace:function(e,r,n,t,i){(/^\s+$/.test(r)||""===r)&&t.push(u(i.messages.whitespace,e.fullField))},type:function(e,r,n,t,i){if(e.required&&void0===r)g(e,r,n,t,i);else{vara=e.type;["integer","float","array","regexp","object","method","email","number","date","url","hex"].indexOf(a)>-1?v[a](r)||t.push(u(i.messages.types[a],e.fullField,e.type)):a&&typeofr!==e.type&&t.push(u(i.messages.types[a],e.fullField,e.type))}},range:function(e,r,n,t,i){vara="number"==typeofe.len,o="number"==typeofe.min,s="number"==typeofe.max,c=r,f=null,l="number"==typeofr,d="string"==typeofr,p=Array.isArray(r);if(l?f="number":d?f="string":p&&(f="array"),!f)return!1;p&&(c=r.length),d&&(c=r.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,"_").length),a?c!==e.len&&t.push(u(i.messages[f].len,e.fullField,e.len)):o&&!s&&c<e.min?t.push(u(i.messages[f].min,e.fullField,e.min)):s&&!o&&c>e.max?t.push(u(i.messages[f].max,e.fullField,e.max)):o&&s&&(c<e.min||c>e.max)&&t.push(u(i.messages[f].range,e.fullField,e.min,e.max))},enum:function(e,r,n,t,i){e.enum=Array.isArray(e.enum)?e.enum:[],-1===e.enum.indexOf(r)&&t.push(u(i.messages.enum,e.fullField,e.enum.join(", ")))},pattern:function(e,r,n,t,i){if(e.pattern)if(e.patterninstanceofRegExp)e.pattern.lastIndex=0,e.pattern.test(r)||t.push(u(i.messages.pattern.mismatch,e.fullField,r,e.pattern));elseif("string"==typeofe.pattern){newRegExp(e.pattern).test(r)||t.push(u(i.messages.pattern.mismatch,e.fullField,r,e.pattern))}}},b=function(e,r,n,t,i){vara=e.type,o=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(s(r,a)&&!e.required)returnn();q.required(e,r,t,o,i,a),s(r,a)||q.type(e,r,t,o,i)}n(o)},w={string:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(s(r,"string")&&!e.required)returnn();q.required(e,r,t,a,i,"string"),s(r,"string")||(q.type(e,r,t,a,i),q.range(e,r,t,a,i),q.pattern(e,r,t,a,i),!0===e.whitespace&&q.whitespace(e,r,t,a,i))}n(a)},method:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(s(r)&&!e.required)returnn();q.required(e,r,t,a,i),void0!==r&&q.type(e,r,t,a,i)}n(a)},number:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(""===r&&(r=void0),s(r)&&!e.required)returnn();q.required(e,r,t,a,i),void0!==r&&(q.type(e,r,t,a,i),q.range(e,r,t,a,i))}n(a)},boolean:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(s(r)&&!e.required)returnn();q.required(e,r,t,a,i),void0!==r&&q.type(e,r,t,a,i)}n(a)},regexp:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(s(r)&&!e.required)returnn();q.required(e,r,t,a,i),s(r)||q.type(e,r,t,a,i)}n(a)},integer:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(s(r)&&!e.required)returnn();q.required(e,r,t,a,i),void0!==r&&(q.type(e,r,t,a,i),q.range(e,r,t,a,i))}n(a)},float:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(s(r)&&!e.required)returnn();q.required(e,r,t,a,i),void0!==r&&(q.type(e,r,t,a,i),q.range(e,r,t,a,i))}n(a)},array:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(null==r&&!e.required)returnn();q.required(e,r,t,a,i,"array"),null!=r&&(q.type(e,r,t,a,i),q.range(e,r,t,a,i))}n(a)},object:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(s(r)&&!e.required)returnn();q.required(e,r,t,a,i),void0!==r&&q.type(e,r,t,a,i)}n(a)},enum:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(s(r)&&!e.required)returnn();q.required(e,r,t,a,i),void0!==r&&q.enum(e,r,t,a,i)}n(a)},pattern:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(s(r,"string")&&!e.required)returnn();q.required(e,r,t,a,i),s(r,"string")||q.pattern(e,r,t,a,i)}n(a)},date:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(s(r,"date")&&!e.required)returnn();if(q.required(e,r,t,a,i),!s(r,"date")){varo=void0;o=rinstanceofDate?r:newDate(r),q.type(e,o,t,a,i),o&&q.range(e,o.getTime(),t,a,i)}}n(a)},url:b,hex:b,email:b,required:function(e,r,n,t,i){vara=[],o=Array.isArray(r)?"array":typeofr;q.required(e,r,t,a,i,o),n(a)},any:function(e,r,n,t,i){vara=[];if(e.required||!e.required&&t.hasOwnProperty(e.field)){if(s(r)&&!e.required)returnn();q.required(e,r,t,a,i)}n(a)}};functionF(){return{default:"Validation error on field %s",required:"%s is required",enum:"%s must be one of %s",whitespace:"%s cannot be empty",date:{format:"%s date %s is invalid for format %s",parse:"%s date could not be parsed, %s is invalid ",invalid:"%s date %s is invalid"},types:{string:"%s is not a %s",method:"%s is not a %s (function)",array:"%s is not an %s",object:"%s is not an %s",number:"%s is not a %s",date:"%s is not a %s",boolean:"%s is not a %s",integer:"%s is not an %s",float:"%s is not a %s",regexp:"%s is not a valid %s",email:"%s is not a valid %s",url:"%s is not a valid %s",hex:"%s is not a valid %s"},string:{len:"%s must be exactly %s characters",min:"%s must be at least %s characters",max:"%s cannot be longer than %s characters",range:"%s must be between %s and %s characters"},number:{len:"%s must equal %s",min:"%s cannot be less than %s",max:"%s cannot be greater than %s",range:"%s must be between %s and %s"},array:{len:"%s must be exactly %s in length",min:"%s cannot be less than %s in length",max:"%s cannot be greater than %s in length",range:"%s must be between %s and %s in length"},pattern:{mismatch:"%s value %s does not match pattern %s"},clone:function(){vare=JSON.parse(JSON.stringify(this));returne.clone=this.clone,e}}}varx=F(),O=function(){functione(e){this.rules=null,this._messages=x,this.define(e)}returne.prototype.define=function(e){varr=this;if(!e)thrownewError("Cannot configure a schema with no rules");if("object"!=typeofe||Array.isArray(e))thrownewError("Rules must be an object");this.rules={},Object.keys(e).forEach((function(n){vart=e[n];r.rules[n]=Array.isArray(t)?t:[t]}))},e.prototype.messages=function(e){returne&&(this._messages=p(F(),e)),this._messages},e.prototype.validate=function(i,a,s){varc=this;void0===a&&(a={}),void0===s&&(s=function(){});varf=i,y=a,g=s;if("function"==typeofy&&(g=y,y={}),!this.rules||0===Object.keys(this.rules).length)returng&&g(null,f),Promise.resolve(f);if(y.messages){varh=this.messages();h===x&&(h=F()),p(h,y.messages),y.messages=h}elsey.messages=this.messages();varm={};(y.keys||Object.keys(this.rules)).forEach((function(e){varn=c.rules[e],t=f[e];n.forEach((function(n){vara=n;"function"==typeofa.transform&&(f===i&&(f=r({},f)),t=f[e]=a.transform(t)),(a="function"==typeofa?{validator:a}:r({},a)).validator=c.getValidationMethod(a),a.validator&&(a.field=e,a.fullField=a.fullField||e,a.type=c.getType(a),m[e]=m[e]||[],m[e].push({rule:a,value:t,source:f,field:e}))}))}));varv={};returnl(m,y,(function(i,a){varo,s,c=i.rule,l=!("object"!==c.type&&"array"!==c.type||"object"!=typeofc.fields&&"object"!=typeofc.defaultField);functionp(e,i){returnr(r({},i),{fullField:"".concat(c.fullField,".").concat(e),fullFields:c.fullFields?t(t([],n(c.fullFields),!1),[e],!1):[e]})}functiong(o){void0===o&&(o=[]);vars=Array.isArray(o)?o:[o];!y.suppressWarning&&s.length&&e.warning("async-validator:",s),s.length&&void0!==c.message&&(s=[].concat(c.message));varg=s.map(d(c,f));if(y.first&&g.length)returnv[c.field]=1,a(g);if(l){if(c.required&&!i.value)returnvoid0!==c.message?g=[].concat(c.message).map(d(c,f)):y.error&&(g=[y.error(c,u(y.messages.required,c.field))]),a(g);varh={};c.defaultField&&Object.keys(i.value).map((function(e){h[e]=c.defaultField})),h=r(r({},h),i.rule.fields);varm={};Object.keys(h).forEach((function(e){varr=h[e],n=Array.isArray(r)?r:[r];m[e]=n.map(p.bind(null,e))}));varq=newe(m);q.messages(y.messages),i.rule.options&&(i.rule.options.messages=y.messages,i.rule.options.error=y.error),q.validate(i.value,i.rule.options||y,(function(e){varr=[];g&&g.length&&r.push.apply(r,t([],n(g),!1)),e&&e.length&&r.push.apply(r,t([],n(e),!1)),a(r.length?r:null)}))}elsea(g)}if(l=l&&(c.required||!c.required&&i.value),c.field=i.field,c.asyncValidator)s=c.asyncValidator(c,i.value,g,i.source,y);elseif(c.validator){try{s=c.validator(c,i.value,g,i.source,y)}catch(e){null===(o=console.error)||void0===o||o.call(console,e),y.suppressValidatorError||setTimeout((function(){throwe}),0),g(e.message)}!0===s?g():!1===s?g("function"==typeofc.message?c.message(c.fullField||c.field):c.message||"".concat(c.fullField||c.field," fails")):sinstanceofArray?g(s):sinstanceofError&&g(s.message)}s&&s.then&&s.then((function(){returng()}),(function(e){returng(e)}))}),(function(e){!function(e){for(varr,i=[],a={},u=0;u<e.length;u++)r=e[u],Array.isArray(r)?i=i.concat.apply(i,t([],n(r),!1)):i.push(r);i.length?(a=o(i),g(i,a)):g(null,f)}(e)}),f)},e.prototype.getType=function(e){if(void0===e.type&&e.patterninstanceofRegExp&&(e.type="pattern"),"function"!=typeofe.validator&&e.type&&!w.hasOwnProperty(e.type))thrownewError(u("Unknown rule type %s",e.type));returne.type||"string"},e.prototype.getValidationMethod=function(e){if("function"==typeofe.validator)returne.validator;varr=Object.keys(e),n=r.indexOf("message");return-1!==n&&r.splice(n,1),1===r.length&&"required"===r[0]?w.required:w[this.getType(e)]||void0},e.register=function(e,r){if("function"!=typeofr)thrownewError("Cannot register a validator by type, validator is not a function");w[e]=r},e.warning=a,e.messages=x,e.validators=w,e}();returnO}));