function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},e.apply(this,arguments)}function t(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,r(e,t)}function n(e){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},n(e)}function r(e,t){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},r(e,t)}function i(){if(typeof Reflect>`u`||!Reflect.construct||Reflect.construct.sham)return!1;if(typeof Proxy==`function`)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch{return!1}}function a(e,t,n){return a=i()?Reflect.construct.bind():function(e,t,n){var i=[null];i.push.apply(i,t);var a=new(Function.bind.apply(e,i));return n&&r(a,n.prototype),a},a.apply(null,arguments)}function o(e){return Function.toString.call(e).indexOf(`[native code]`)!==-1}function s(e){var t=typeof Map==`function`?new Map:void 0;return s=function(e){if(e===null||!o(e))return e;if(typeof e!=`function`)throw TypeError(`Super expression must either be null or a function`);if(t!==void 0){if(t.has(e))return t.get(e);t.set(e,i)}function i(){return a(e,arguments,n(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),r(i,e)},s(e)}var c=/%[sdj%]/g,l=function(){};function u(e){if(!e||!e.length)return null;var t={};return e.forEach(function(e){var n=e.field;t[n]=t[n]||[],t[n].push(e)}),t}function d(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var i=0,a=n.length;return typeof e==`function`?e.apply(null,n):typeof e==`string`?e.replace(c,function(e){if(e===`%%`)return`%`;if(i>=a)return e;switch(e){case`%s`:return String(n[i++]);case`%d`:return Number(n[i++]);case`%j`:try{return JSON.stringify(n[i++])}catch{return`[Circular]`}break;default:return e}}):e}function f(e){return e===`string`||e===`url`||e===`hex`||e===`email`||e===`date`||e===`pattern`}function p(e,t){return!!(e==null||t===`array`&&Array.isArray(e)&&!e.length||f(t)&&typeof e==`string`&&!e)}function m(e,t,n){var r=[],i=0,a=e.length;function o(e){r.push.apply(r,e||[]),i++,i===a&&n(r)}e.forEach(function(e){t(e,o)})}function h(e,t,n){var r=0,i=e.length;function a(o){if(o&&o.length){n(o);return}var s=r;r+=1,s<i?t(e[s],a):n([])}a([])}function g(e){var t=[];return Object.keys(e).forEach(function(n){t.push.apply(t,e[n]||[])}),t}var _=function(e){t(n,e);function n(t,n){var r=e.call(this,`Async Validation Error`)||this;return r.errors=t,r.fields=n,r}return n}(s(Error));function v(e,t,n,r,i){if(t.first){var a=new Promise(function(t,a){h(g(e),n,function(e){return r(e),e.length?a(new _(e,u(e))):t(i)})});return a.catch(function(e){return e}),a}var o=t.firstFields===!0?Object.keys(e):t.firstFields||[],s=Object.keys(e),c=s.length,l=0,d=[],f=new Promise(function(t,a){var f=function(e){if(d.push.apply(d,e),l++,l===c)return r(d),d.length?a(new _(d,u(d))):t(i)};s.length||(r(d),t(i)),s.forEach(function(t){var r=e[t];o.indexOf(t)===-1?m(r,n,f):h(r,n,f)})});return f.catch(function(e){return e}),f}function y(e){return!!(e&&e.message!==void 0)}function b(e,t){for(var n=e,r=0;r<t.length;r++){if(n==null)return n;n=n[t[r]]}return n}function x(e,t){return function(n){var r=e.fullFields?b(t,e.fullFields):t[n.field||e.fullField];return y(n)?(n.field=n.field||e.fullField,n.fieldValue=r,n):{message:typeof n==`function`?n():n,fieldValue:r,field:n.field||e.fullField}}}function S(t,n){if(n){for(var r in n)if(n.hasOwnProperty(r)){var i=n[r];typeof i==`object`&&typeof t[r]==`object`?t[r]=e({},t[r],i):t[r]=i}}return t}var C=function(e,t,n,r,i,a){e.required&&(!n.hasOwnProperty(e.field)||p(t,a||e.type))&&r.push(d(i.messages.required,e.fullField))},w=function(e,t,n,r,i){(/^\s+$/.test(t)||t===``)&&r.push(d(i.messages.whitespace,e.fullField))},T,E=(function(){if(T)return T;var e=`[a-fA-F\\d:]`,t=function(t){return t&&t.includeBoundaries?`(?:(?<=\\s|^)(?=`+e+`)|(?<=`+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}`,r=`[a-fA-F\\d]{1,4}`,i=(`
(?:
(?:`+r+`:){7}(?:`+r+`|:)|                                    // 1:2:3:4:5:6:7::  1:2:3:4:5:6:7:8
(?:`+r+`:){6}(?:`+n+`|:`+r+`|:)|                             // 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
(?:`+r+`:){5}(?::`+n+`|(?::`+r+`){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
(?:`+r+`:){4}(?:(?::`+r+`){0,1}:`+n+`|(?::`+r+`){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
(?:`+r+`:){3}(?:(?::`+r+`){0,2}:`+n+`|(?::`+r+`){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
(?:`+r+`:){2}(?:(?::`+r+`){0,3}:`+n+`|(?::`+r+`){1,5}|:)| // 1:2::            1:2::4:5:6:7:8   1:2::8          1:2::4:5:6:7:1.2.3.4
(?:`+r+`:){1}(?:(?::`+r+`){0,4}:`+n+`|(?::`+r+`){1,6}|:)| // 1::              1::3:4:5:6:7:8   1::8            1::3:4:5:6:7:1.2.3.4
(?::(?:(?::`+r+`){0,5}:`+n+`|(?::`+r+`){1,7}|:))             // ::2:3:4:5:6:7:8  ::2:3:4:5:6:7:8  ::8             ::1.2.3.4
)(?:%[0-9a-zA-Z]{1,})?                                             // %eth0            %1
`).replace(/\s*\/\/.*$/gm,``).replace(/\n/g,``).trim(),a=RegExp(`(?:^`+n+`$)|(?:^`+i+`$)`),o=RegExp(`^`+n+`$`),s=RegExp(`^`+i+`$`),c=function(e){return e&&e.exact?a:RegExp(`(?:`+t(e)+n+t(e)+`)|(?:`+t(e)+i+t(e)+`)`,`g`)};c.v4=function(e){return e&&e.exact?o:RegExp(``+t(e)+n+t(e),`g`)},c.v6=function(e){return e&&e.exact?s:RegExp(``+t(e)+i+t(e),`g`)};var l=`(?:(?:[a-z]+:)?//)`,u=`(?:\\S+(?::\\S*)?@)?`,d=c.v4().source,f=c.v6().source,p=`(?:`+l+`|www\\.)`+u+`(?:localhost|`+d+`|`+f+`|(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:[/?#][^\\s"]*)?`;return T=RegExp(`(?:^`+p+`$)`,`i`),T}),D={email:/^(([^<>()\[\]\\.,;:\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,}))$/,hex:/^#?([a-f0-9]{6}|[a-f0-9]{3})$/i},O={integer:function(e){return O.number(e)&&parseInt(e,10)===e},float:function(e){return O.number(e)&&!O.integer(e)},array:function(e){return Array.isArray(e)},regexp:function(e){if(e instanceof RegExp)return!0;try{return!!new RegExp(e)}catch{return!1}},date:function(e){return typeof e.getTime==`function`&&typeof e.getMonth==`function`&&typeof e.getYear==`function`&&!isNaN(e.getTime())},number:function(e){return!isNaN(e)&&typeof e==`number`},object:function(e){return typeof e==`object`&&!O.array(e)},method:function(e){return typeof e==`function`},email:function(e){return typeof e==`string`&&e.length<=320&&!!e.match(D.email)},url:function(e){return typeof e==`string`&&e.length<=2048&&!!e.match(E())},hex:function(e){return typeof e==`string`&&!!e.match(D.hex)}},k=function(e,t,n,r,i){if(e.required&&t===void 0){C(e,t,n,r,i);return}var a=[`integer`,`float`,`array`,`regexp`,`object`,`method`,`email`,`number`,`date`,`url`,`hex`],o=e.type;a.indexOf(o)>-1?O[o](t)||r.push(d(i.messages.types[o],e.fullField,e.type)):o&&typeof t!==e.type&&r.push(d(i.messages.types[o],e.fullField,e.type))},A=function(e,t,n,r,i){var a=typeof e.len==`number`,o=typeof e.min==`number`,s=typeof e.max==`number`,c=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,l=t,u=null,f=typeof t==`number`,p=typeof t==`string`,m=Array.isArray(t);if(f?u=`number`:p?u=`string`:m&&(u=`array`),!u)return!1;m&&(l=t.length),p&&(l=t.replace(c,`_`).length),a?l!==e.len&&r.push(d(i.messages[u].len,e.fullField,e.len)):o&&!s&&l<e.min?r.push(d(i.messages[u].min,e.fullField,e.min)):s&&!o&&l>e.max?r.push(d(i.messages[u].max,e.fullField,e.max)):o&&s&&(l<e.min||l>e.max)&&r.push(d(i.messages[u].range,e.fullField,e.min,e.max))},j=`enum`,M={required:C,whitespace:w,type:k,range:A,enum:function(e,t,n,r,i){e[j]=Array.isArray(e[j])?e[j]:[],e[j].indexOf(t)===-1&&r.push(d(i.messages[j],e.fullField,e[j].join(`, `)))},pattern:function(e,t,n,r,i){e.pattern&&(e.pattern instanceof RegExp?(e.pattern.lastIndex=0,e.pattern.test(t)||r.push(d(i.messages.pattern.mismatch,e.fullField,t,e.pattern))):typeof e.pattern==`string`&&(new RegExp(e.pattern).test(t)||r.push(d(i.messages.pattern.mismatch,e.fullField,t,e.pattern))))}},N=function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(p(t,`string`)&&!e.required)return n();M.required(e,t,r,a,i,`string`),p(t,`string`)||(M.type(e,t,r,a,i),M.range(e,t,r,a,i),M.pattern(e,t,r,a,i),e.whitespace===!0&&M.whitespace(e,t,r,a,i))}n(a)},P=function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(p(t)&&!e.required)return n();M.required(e,t,r,a,i),t!==void 0&&M.type(e,t,r,a,i)}n(a)},F=function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(t===``&&(t=void 0),p(t)&&!e.required)return n();M.required(e,t,r,a,i),t!==void 0&&(M.type(e,t,r,a,i),M.range(e,t,r,a,i))}n(a)},I=function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(p(t)&&!e.required)return n();M.required(e,t,r,a,i),t!==void 0&&M.type(e,t,r,a,i)}n(a)},L=function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(p(t)&&!e.required)return n();M.required(e,t,r,a,i),p(t)||M.type(e,t,r,a,i)}n(a)},R=function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(p(t)&&!e.required)return n();M.required(e,t,r,a,i),t!==void 0&&(M.type(e,t,r,a,i),M.range(e,t,r,a,i))}n(a)},z=function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(p(t)&&!e.required)return n();M.required(e,t,r,a,i),t!==void 0&&(M.type(e,t,r,a,i),M.range(e,t,r,a,i))}n(a)},B=function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(t==null&&!e.required)return n();M.required(e,t,r,a,i,`array`),t!=null&&(M.type(e,t,r,a,i),M.range(e,t,r,a,i))}n(a)},V=function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(p(t)&&!e.required)return n();M.required(e,t,r,a,i),t!==void 0&&M.type(e,t,r,a,i)}n(a)},H=`enum`,U=function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(p(t)&&!e.required)return n();M.required(e,t,r,a,i),t!==void 0&&M[H](e,t,r,a,i)}n(a)},W=function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(p(t,`string`)&&!e.required)return n();M.required(e,t,r,a,i),p(t,`string`)||M.pattern(e,t,r,a,i)}n(a)},G=function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(p(t,`date`)&&!e.required)return n();if(M.required(e,t,r,a,i),!p(t,`date`)){var o=t instanceof Date?t:new Date(t);M.type(e,o,r,a,i),o&&M.range(e,o.getTime(),r,a,i)}}n(a)},K=function(e,t,n,r,i){var a=[],o=Array.isArray(t)?`array`:typeof t;M.required(e,t,r,a,i,o),n(a)},q=function(e,t,n,r,i){var a=e.type,o=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(p(t,a)&&!e.required)return n();M.required(e,t,r,o,i,a),p(t,a)||M.type(e,t,r,o,i)}n(o)},J={string:N,method:P,number:F,boolean:I,regexp:L,integer:R,float:z,array:B,object:V,enum:U,pattern:W,date:G,url:q,hex:q,email:q,required:K,any:function(e,t,n,r,i){var a=[];if(e.required||!e.required&&r.hasOwnProperty(e.field)){if(p(t)&&!e.required)return n();M.required(e,t,r,a,i)}n(a)}};function Y(){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(){var e=JSON.parse(JSON.stringify(this));return e.clone=this.clone,e}}}var X=Y(),Z=function(){function t(e){this.rules=null,this._messages=X,this.define(e)}var n=t.prototype;return n.define=function(e){var t=this;if(!e)throw Error(`Cannot configure a schema with no rules`);if(typeof e!=`object`||Array.isArray(e))throw Error(`Rules must be an object`);this.rules={},Object.keys(e).forEach(function(n){var r=e[n];t.rules[n]=Array.isArray(r)?r:[r]})},n.messages=function(e){return e&&(this._messages=S(Y(),e)),this._messages},n.validate=function(n,r,i){var a=this;r===void 0&&(r={}),i===void 0&&(i=function(){});var o=n,s=r,c=i;if(typeof s==`function`&&(c=s,s={}),!this.rules||Object.keys(this.rules).length===0)return c&&c(null,o),Promise.resolve(o);function l(e){var t=[],n={};function r(e){if(Array.isArray(e)){var n;t=(n=t).concat.apply(n,e)}else t.push(e)}for(var i=0;i<e.length;i++)r(e[i]);t.length?(n=u(t),c(t,n)):c(null,o)}if(s.messages){var f=this.messages();f===X&&(f=Y()),S(f,s.messages),s.messages=f}else s.messages=this.messages();var p={};(s.keys||Object.keys(this.rules)).forEach(function(t){var r=a.rules[t],i=o[t];r.forEach(function(r){var s=r;typeof s.transform==`function`&&(o===n&&(o=e({},o)),i=o[t]=s.transform(i)),s=typeof s==`function`?{validator:s}:e({},s),s.validator=a.getValidationMethod(s),s.validator&&(s.field=t,s.fullField=s.fullField||t,s.type=a.getType(s),p[t]=p[t]||[],p[t].push({rule:s,value:i,source:o,field:t}))})});var m={};return v(p,s,function(n,r){var i=n.rule,a=(i.type===`object`||i.type===`array`)&&(typeof i.fields==`object`||typeof i.defaultField==`object`);a=a&&(i.required||!i.required&&n.value),i.field=n.field;function c(t,n){return e({},n,{fullField:i.fullField+`.`+t,fullFields:i.fullFields?[].concat(i.fullFields,[t]):[t]})}function l(l){l===void 0&&(l=[]);var u=Array.isArray(l)?l:[l];!s.suppressWarning&&u.length&&t.warning(`async-validator:`,u),u.length&&i.message!==void 0&&(u=[].concat(i.message));var f=u.map(x(i,o));if(s.first&&f.length)return m[i.field]=1,r(f);if(!a)r(f);else{if(i.required&&!n.value)return i.message===void 0?s.error&&(f=[s.error(i,d(s.messages.required,i.field))]):f=[].concat(i.message).map(x(i,o)),r(f);var p={};i.defaultField&&Object.keys(n.value).map(function(e){p[e]=i.defaultField}),p=e({},p,n.rule.fields);var h={};Object.keys(p).forEach(function(e){var t=p[e];h[e]=(Array.isArray(t)?t:[t]).map(c.bind(null,e))});var g=new t(h);g.messages(s.messages),n.rule.options&&(n.rule.options.messages=s.messages,n.rule.options.error=s.error),g.validate(n.value,n.rule.options||s,function(e){var t=[];f&&f.length&&t.push.apply(t,f),e&&e.length&&t.push.apply(t,e),r(t.length?t:null)})}}var u;if(i.asyncValidator)u=i.asyncValidator(i,n.value,l,n.source,s);else if(i.validator){try{u=i.validator(i,n.value,l,n.source,s)}catch(e){console.error==null||console.error(e),s.suppressValidatorError||setTimeout(function(){throw e},0),l(e.message)}u===!0?l():u===!1?l(typeof i.message==`function`?i.message(i.fullField||i.field):i.message||(i.fullField||i.field)+` fails`):u instanceof Array?l(u):u instanceof Error&&l(u.message)}u&&u.then&&u.then(function(){return l()},function(e){return l(e)})},function(e){l(e)},o)},n.getType=function(e){if(e.type===void 0&&e.pattern instanceof RegExp&&(e.type=`pattern`),typeof e.validator!=`function`&&e.type&&!J.hasOwnProperty(e.type))throw Error(d(`Unknown rule type %s`,e.type));return e.type||`string`},n.getValidationMethod=function(e){if(typeof e.validator==`function`)return e.validator;var t=Object.keys(e),n=t.indexOf(`message`);return n!==-1&&t.splice(n,1),t.length===1&&t[0]===`required`?J.required:J[this.getType(e)]||void 0},t}();Z.register=function(e,t){if(typeof t!=`function`)throw Error(`Cannot register a validator by type, validator is not a function`);J[e]=t},Z.warning=l,Z.messages=X,Z.validators=J,exports.default=Z;