UNPKG

boel

Version:

Form Data validation library

1 lines 46.5 kB
var boel=function(t){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var n=function(){return(n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},r="INUMBER",i="IVAR",s="IEXPR";function a(t,e){this.type=t,this.value=null!=e?e:0}function o(t){return new a("IOP1",t)}function u(t){return new a("IOP2",t)}function h(t){return new a("IOP3",t)}function p(t,e,n){var a,o,u,h,d,v,y=[];if(c(t))return f(t,n);for(var m=t.length,g=0;g<m;g++){var x=t[g],w=x.type;if(w===r||"IVARNAME"===w)y.push(x.value);else if("IOP2"===w)o=y.pop(),a=y.pop(),"and"===x.value?y.push(!!a&&!!p(o,e,n)):"or"===x.value?y.push(!!a||!!p(o,e,n)):"="===x.value?(h=e.binaryOps[x.value],y.push(h(a,p(o,e,n),n))):(h=e.binaryOps[x.value],y.push(h(f(a,n),f(o,n))));else if("IOP3"===w)u=y.pop(),o=y.pop(),a=y.pop(),"?"===x.value?y.push(p(a?o:u,e,n)):(h=e.ternaryOps[x.value],y.push(h(f(a,n),f(o,n),f(u,n))));else if(w===i)if(x.value in e.functions)y.push(e.functions[x.value]);else if(x.value in e.unaryOps&&e.parser.isOperatorEnabled(x.value))y.push(e.unaryOps[x.value]);else{var E=n[x.value];if(void 0===E)throw new Error("undefined variable: "+x.value);y.push(E)}else if("IOP1"===w)a=y.pop(),h=e.unaryOps[x.value],y.push(h(f(a,n)));else if("IFUNCALL"===w){for(v=x.value,d=[];v-- >0;)d.unshift(f(y.pop(),n));if(!(h=y.pop()).apply||!h.call)throw new Error(h+" is not a function");y.push(h.apply(void 0,d))}else if("IFUNDEF"===w)y.push(function(){for(var t=y.pop(),r=[],i=x.value;i-- >0;)r.unshift(y.pop());var s=y.pop(),a=function(){for(var i=Object.assign({},n),s=0,a=r.length;s<a;s++)i[r[s]]=arguments[s];return p(t,e,i)};return Object.defineProperty(a,"name",{value:s,writable:!1}),n[s]=a,a}());else if(w===s)y.push(l(x,e));else if("IEXPREVAL"===w)y.push(x);else if("IMEMBER"===w)a=y.pop(),y.push(a[x.value]);else if("IENDSTATEMENT"===w)y.pop();else{if("IARRAY"!==w)throw new Error("invalid Expression");for(v=x.value,d=[];v-- >0;)d.unshift(y.pop());y.push(d)}}if(y.length>1)throw new Error("invalid Expression (parity)");return 0===y[0]?0:f(y[0],n)}function l(t,e,n){return c(t)?t:{type:"IEXPREVAL",value:function(n){return p(t.value,e,n)}}}function c(t){return t&&"IEXPREVAL"===t.type}function f(t,e){return c(t)?t.value(e):t}function d(t,e){for(var n,a,o,u,h,p,l=[],c=0;c<t.length;c++){var f=t[c],y=f.type;if(y===r)"number"==typeof f.value&&f.value<0?l.push("("+f.value+")"):Array.isArray(f.value)?l.push("["+f.value.map(v).join(", ")+"]"):l.push(v(f.value));else if("IOP2"===y)a=l.pop(),n=l.pop(),u=f.value,e?"^"===u?l.push("Math.pow("+n+", "+a+")"):"and"===u?l.push("(!!"+n+" && !!"+a+")"):"or"===u?l.push("(!!"+n+" || !!"+a+")"):"||"===u?l.push("(function(a,b){ return Array.isArray(a) && Array.isArray(b) ? a.concat(b) : String(a) + String(b); }(("+n+"),("+a+")))"):"=="===u?l.push("("+n+" === "+a+")"):"!="===u?l.push("("+n+" !== "+a+")"):"["===u?l.push(n+"[("+a+") | 0]"):l.push("("+n+" "+u+" "+a+")"):"["===u?l.push(n+"["+a+"]"):l.push("("+n+" "+u+" "+a+")");else if("IOP3"===y){if(o=l.pop(),a=l.pop(),n=l.pop(),"?"!==(u=f.value))throw new Error("invalid Expression");l.push("("+n+" ? "+a+" : "+o+")")}else if(y===i||"IVARNAME"===y)l.push(f.value);else if("IOP1"===y)n=l.pop(),"-"===(u=f.value)||"+"===u?l.push("("+u+n+")"):e?"not"===u?l.push("(!"+n+")"):"!"===u?l.push("fac("+n+")"):l.push(u+"("+n+")"):"!"===u?l.push("("+n+"!)"):l.push("("+u+" "+n+")");else if("IFUNCALL"===y){for(p=f.value,h=[];p-- >0;)h.unshift(l.pop());u=l.pop(),l.push(u+"("+h.join(", ")+")")}else if("IFUNDEF"===y){for(a=l.pop(),p=f.value,h=[];p-- >0;)h.unshift(l.pop());n=l.pop(),e?l.push("("+n+" = function("+h.join(", ")+") { return "+a+" })"):l.push("("+n+"("+h.join(", ")+") = "+a+")")}else if("IMEMBER"===y)n=l.pop(),l.push(n+"."+f.value);else if("IARRAY"===y){for(p=f.value,h=[];p-- >0;)h.unshift(l.pop());l.push("["+h.join(", ")+"]")}else if(y===s)l.push("("+d(f.value,e)+")");else if("IENDSTATEMENT"!==y)throw new Error("invalid Expression")}return l.length>1&&(l=e?[l.join(",")]:[l.join(";")]),String(l[0])}function v(t){return"string"==typeof t?JSON.stringify(t).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029"):t}function y(t,e){for(var n=0;n<t.length;n++)if(t[n]===e)return!0;return!1}function m(t,e,n){for(var r=!!(n=n||{}).withMembers,a=null,o=0;o<t.length;o++){var u=t[o];u.type===i||"IVARNAME"===u.type?r||y(e,u.value)?null!==a?(y(e,a)||e.push(a),a=u.value):a=u.value:e.push(u.value):"IMEMBER"===u.type&&r&&null!==a?a+="."+u.value:u.type===s?m(u.value,e,n):null!==a&&(y(e,a)||e.push(a),a=null)}null===a||y(e,a)||e.push(a)}function g(t,e){this.tokens=t,this.parser=e,this.unaryOps=e.unaryOps,this.binaryOps=e.binaryOps,this.ternaryOps=e.ternaryOps,this.functions=e.functions}a.prototype.toString=function(){switch(this.type){case r:case"IOP1":case"IOP2":case"IOP3":case i:case"IVARNAME":case"IENDSTATEMENT":return this.value;case"IFUNCALL":return"CALL "+this.value;case"IFUNDEF":return"DEF "+this.value;case"IARRAY":return"ARRAY "+this.value;case"IMEMBER":return"."+this.value;default:return"Invalid Instruction"}},g.prototype.simplify=function(t){return t=t||{},new g(function t(e,n,o,u,h){for(var p,l,c,f,d=[],v=[],y=0;y<e.length;y++){var m=e[y],g=m.type;if(g===r||"IVARNAME"===g)Array.isArray(m.value)?d.push.apply(d,t(m.value.map((function(t){return new a(r,t)})).concat(new a("IARRAY",m.value.length)),n,o,u,h)):d.push(m);else if(g===i&&h.hasOwnProperty(m.value))m=new a(r,h[m.value]),d.push(m);else if("IOP2"===g&&d.length>1)l=d.pop(),p=d.pop(),f=o[m.value],m=new a(r,f(p.value,l.value)),d.push(m);else if("IOP3"===g&&d.length>2)c=d.pop(),l=d.pop(),p=d.pop(),"?"===m.value?d.push(p.value?l.value:c.value):(f=u[m.value],m=new a(r,f(p.value,l.value,c.value)),d.push(m));else if("IOP1"===g&&d.length>0)p=d.pop(),f=n[m.value],m=new a(r,f(p.value)),d.push(m);else if(g===s){for(;d.length>0;)v.push(d.shift());v.push(new a(s,t(m.value,n,o,u,h)))}else if("IMEMBER"===g&&d.length>0)p=d.pop(),d.push(new a(r,p.value[m.value]));else{for(;d.length>0;)v.push(d.shift());v.push(m)}}for(;d.length>0;)v.push(d.shift());return v}(this.tokens,this.unaryOps,this.binaryOps,this.ternaryOps,t),this.parser)},g.prototype.substitute=function(t,e){return e instanceof g||(e=this.parser.parse(String(e))),new g(function t(e,n,r){for(var p=[],l=0;l<e.length;l++){var c=e[l],f=c.type;if(f===i&&c.value===n)for(var d=0;d<r.tokens.length;d++){var v,y=r.tokens[d];v="IOP1"===y.type?o(y.value):"IOP2"===y.type?u(y.value):"IOP3"===y.type?h(y.value):new a(y.type,y.value),p.push(v)}else f===s?p.push(new a(s,t(c.value,n,r))):p.push(c)}return p}(this.tokens,t,e),this.parser)},g.prototype.evaluate=function(t){return t=t||{},p(this.tokens,this,t)},g.prototype.toString=function(){return d(this.tokens,!1)},g.prototype.symbols=function(t){t=t||{};var e=[];return m(this.tokens,e,t),e},g.prototype.variables=function(t){t=t||{};var e=[];m(this.tokens,e,t);var n=this.functions;return e.filter((function(t){return!(t in n)}))},g.prototype.toJSFunction=function(t,e){var n=this,r=new Function(t,"with(this.functions) with (this.ternaryOps) with (this.binaryOps) with (this.unaryOps) { return "+d(this.simplify(e).tokens,!0)+"; }");return function(){return r.apply(n,arguments)}};var x="TOP",w="TPAREN";function E(t,e,n){this.type=t,this.value=e,this.index=n}function F(t,e){this.pos=0,this.current=null,this.unaryOps=t.unaryOps,this.binaryOps=t.binaryOps,this.ternaryOps=t.ternaryOps,this.consts=t.consts,this.expression=e,this.savedPosition=0,this.savedCurrent=null,this.options=t.options,this.parser=t}E.prototype.toString=function(){return this.type+": "+this.value},F.prototype.newToken=function(t,e,n){return new E(t,e,null!=n?n:this.pos)},F.prototype.save=function(){this.savedPosition=this.pos,this.savedCurrent=this.current},F.prototype.restore=function(){this.pos=this.savedPosition,this.current=this.savedCurrent},F.prototype.next=function(){return this.pos>=this.expression.length?this.newToken("TEOF","EOF"):this.isWhitespace()||this.isComment()?this.next():this.isRadixInteger()||this.isNumber()||this.isOperator()||this.isString()||this.isParen()||this.isBracket()||this.isComma()||this.isSemicolon()||this.isNamedOp()||this.isConst()||this.isName()?this.current:void this.parseError('Unknown character "'+this.expression.charAt(this.pos)+'"')},F.prototype.isString=function(){var t=!1,e=this.pos,n=this.expression.charAt(e);if("'"===n||'"'===n)for(var r=this.expression.indexOf(n,e+1);r>=0&&this.pos<this.expression.length;){if(this.pos=r+1,"\\"!==this.expression.charAt(r-1)){var i=this.expression.substring(e+1,r);this.current=this.newToken("TSTRING",this.unescape(i),e),t=!0;break}r=this.expression.indexOf(n,r+1)}return t},F.prototype.isParen=function(){var t=this.expression.charAt(this.pos);return("("===t||")"===t)&&(this.current=this.newToken(w,t),this.pos++,!0)},F.prototype.isBracket=function(){var t=this.expression.charAt(this.pos);return!("["!==t&&"]"!==t||!this.isOperatorEnabled("["))&&(this.current=this.newToken("TBRACKET",t),this.pos++,!0)},F.prototype.isComma=function(){return","===this.expression.charAt(this.pos)&&(this.current=this.newToken("TCOMMA",","),this.pos++,!0)},F.prototype.isSemicolon=function(){return";"===this.expression.charAt(this.pos)&&(this.current=this.newToken("TSEMICOLON",";"),this.pos++,!0)},F.prototype.isConst=function(){for(var t=this.pos,e=t;e<this.expression.length;e++){var n=this.expression.charAt(e);if(n.toUpperCase()===n.toLowerCase()&&(e===this.pos||"_"!==n&&"."!==n&&(n<"0"||n>"9")))break}if(e>t){var r=this.expression.substring(t,e);if(r in this.consts)return this.current=this.newToken("TNUMBER",this.consts[r]),this.pos+=r.length,!0}return!1},F.prototype.isNamedOp=function(){for(var t=this.pos,e=t;e<this.expression.length;e++){var n=this.expression.charAt(e);if(n.toUpperCase()===n.toLowerCase()&&(e===this.pos||"_"!==n&&(n<"0"||n>"9")))break}if(e>t){var r=this.expression.substring(t,e);if(this.isOperatorEnabled(r)&&(r in this.binaryOps||r in this.unaryOps||r in this.ternaryOps))return this.current=this.newToken(x,r),this.pos+=r.length,!0}return!1},F.prototype.isName=function(){for(var t=this.pos,e=t,n=!1;e<this.expression.length;e++){var r=this.expression.charAt(e);if(r.toUpperCase()===r.toLowerCase()){if(e===this.pos&&("$"===r||"_"===r)){"_"===r&&(n=!0);continue}if(e===this.pos||!n||"_"!==r&&(r<"0"||r>"9"))break}else n=!0}if(n){var i=this.expression.substring(t,e);return this.current=this.newToken("TNAME",i),this.pos+=i.length,!0}return!1},F.prototype.isWhitespace=function(){for(var t=!1,e=this.expression.charAt(this.pos);!(" "!==e&&"\t"!==e&&"\n"!==e&&"\r"!==e||(t=!0,this.pos++,this.pos>=this.expression.length));)e=this.expression.charAt(this.pos);return t};var b=/^[0-9a-f]{4}$/i;function A(t,e,n){this.parser=t,this.tokens=e,this.current=null,this.nextToken=null,this.next(),this.savedCurrent=null,this.savedNextToken=null,this.allowMemberAccess=!1!==n.allowMemberAccess}F.prototype.unescape=function(t){var e=t.indexOf("\\");if(e<0)return t;for(var n=t.substring(0,e);e>=0;){var r=t.charAt(++e);switch(r){case"'":n+="'";break;case'"':n+='"';break;case"\\":n+="\\";break;case"/":n+="/";break;case"b":n+="\b";break;case"f":n+="\f";break;case"n":n+="\n";break;case"r":n+="\r";break;case"t":n+="\t";break;case"u":var i=t.substring(e+1,e+5);b.test(i)||this.parseError("Illegal escape sequence: \\u"+i),n+=String.fromCharCode(parseInt(i,16)),e+=4;break;default:throw this.parseError('Illegal escape sequence: "\\'+r+'"')}++e;var s=t.indexOf("\\",e);n+=t.substring(e,s<0?t.length:s),e=s}return n},F.prototype.isComment=function(){return"/"===this.expression.charAt(this.pos)&&"*"===this.expression.charAt(this.pos+1)&&(this.pos=this.expression.indexOf("*/",this.pos)+2,1===this.pos&&(this.pos=this.expression.length),!0)},F.prototype.isRadixInteger=function(){var t,e,n=this.pos;if(n>=this.expression.length-2||"0"!==this.expression.charAt(n))return!1;if(++n,"x"===this.expression.charAt(n))t=16,e=/^[0-9a-f]$/i,++n;else{if("b"!==this.expression.charAt(n))return!1;t=2,e=/^[01]$/i,++n}for(var r=!1,i=n;n<this.expression.length;){var s=this.expression.charAt(n);if(!e.test(s))break;n++,r=!0}return r&&(this.current=this.newToken("TNUMBER",parseInt(this.expression.substring(i,n),t)),this.pos=n),r},F.prototype.isNumber=function(){for(var t,e=!1,n=this.pos,r=n,i=n,s=!1,a=!1;n<this.expression.length&&((t=this.expression.charAt(n))>="0"&&t<="9"||!s&&"."===t);)"."===t?s=!0:a=!0,n++,e=a;if(e&&(i=n),"e"===t||"E"===t){n++;for(var o=!0,u=!1;n<this.expression.length;){if(t=this.expression.charAt(n),!o||"+"!==t&&"-"!==t){if(!(t>="0"&&t<="9"))break;u=!0,o=!1}else o=!1;n++}u||(n=i)}return e?(this.current=this.newToken("TNUMBER",parseFloat(this.expression.substring(r,n))),this.pos=n):this.pos=i,e},F.prototype.isOperator=function(){var t=this.pos,e=this.expression.charAt(this.pos);if("+"===e||"-"===e||"*"===e||"/"===e||"%"===e||"^"===e||"?"===e||":"===e||"."===e)this.current=this.newToken(x,e);else if("∙"===e||"•"===e)this.current=this.newToken(x,"*");else if(">"===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(x,">="),this.pos++):this.current=this.newToken(x,">");else if("<"===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(x,"<="),this.pos++):this.current=this.newToken(x,"<");else if("|"===e){if("|"!==this.expression.charAt(this.pos+1))return!1;this.current=this.newToken(x,"||"),this.pos++}else if("="===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(x,"=="),this.pos++):this.current=this.newToken(x,e);else{if("!"!==e)return!1;"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(x,"!="),this.pos++):this.current=this.newToken(x,e)}return this.pos++,!!this.isOperatorEnabled(this.current.value)||(this.pos=t,!1)},F.prototype.isOperatorEnabled=function(t){return this.parser.isOperatorEnabled(t)},F.prototype.getCoordinates=function(){var t,e=0,n=-1;do{e++,t=this.pos-n,n=this.expression.indexOf("\n",n+1)}while(n>=0&&n<this.pos);return{line:e,column:t}},F.prototype.parseError=function(t){var e=this.getCoordinates();throw new Error("parse error ["+e.line+":"+e.column+"]: "+t)},A.prototype.next=function(){return this.current=this.nextToken,this.nextToken=this.tokens.next()},A.prototype.tokenMatches=function(t,e){return void 0===e||(Array.isArray(e)?y(e,t.value):"function"==typeof e?e(t):t.value===e)},A.prototype.save=function(){this.savedCurrent=this.current,this.savedNextToken=this.nextToken,this.tokens.save()},A.prototype.restore=function(){this.tokens.restore(),this.current=this.savedCurrent,this.nextToken=this.savedNextToken},A.prototype.accept=function(t,e){return!(this.nextToken.type!==t||!this.tokenMatches(this.nextToken,e))&&(this.next(),!0)},A.prototype.expect=function(t,e){if(!this.accept(t,e)){var n=this.tokens.getCoordinates();throw new Error("parse error ["+n.line+":"+n.column+"]: Expected "+(e||t))}},A.prototype.parseAtom=function(t){var e=this.tokens.unaryOps;if(this.accept("TNAME")||this.accept(x,(function(t){return t.value in e})))t.push(new a(i,this.current.value));else if(this.accept("TNUMBER"))t.push(new a(r,this.current.value));else if(this.accept("TSTRING"))t.push(new a(r,this.current.value));else if(this.accept(w,"("))this.parseExpression(t),this.expect(w,")");else{if(!this.accept("TBRACKET","["))throw new Error("unexpected "+this.nextToken);if(this.accept("TBRACKET","]"))t.push(new a("IARRAY",0));else{var n=this.parseArrayList(t);t.push(new a("IARRAY",n))}}},A.prototype.parseExpression=function(t){var e=[];this.parseUntilEndStatement(t,e)||(this.parseVariableAssignmentExpression(e),this.parseUntilEndStatement(t,e)||this.pushExpression(t,e))},A.prototype.pushExpression=function(t,e){for(var n=0,r=e.length;n<r;n++)t.push(e[n])},A.prototype.parseUntilEndStatement=function(t,e){return!!this.accept("TSEMICOLON")&&(!this.nextToken||"TEOF"===this.nextToken.type||this.nextToken.type===w&&")"===this.nextToken.value||e.push(new a("IENDSTATEMENT")),"TEOF"!==this.nextToken.type&&this.parseExpression(e),t.push(new a(s,e)),!0)},A.prototype.parseArrayList=function(t){for(var e=0;!this.accept("TBRACKET","]");)for(this.parseExpression(t),++e;this.accept("TCOMMA");)this.parseExpression(t),++e;return e},A.prototype.parseVariableAssignmentExpression=function(t){for(this.parseConditionalExpression(t);this.accept(x,"=");){var e=t.pop(),n=[],r=t.length-1;if("IFUNCALL"!==e.type){if(e.type!==i&&"IMEMBER"!==e.type)throw new Error("expected variable for assignment");this.parseVariableAssignmentExpression(n),t.push(new a("IVARNAME",e.value)),t.push(new a(s,n)),t.push(u("="))}else{if(!this.tokens.isOperatorEnabled("()="))throw new Error("function definition is not permitted");for(var o=0,h=e.value+1;o<h;o++){var p=r-o;t[p].type===i&&(t[p]=new a("IVARNAME",t[p].value))}this.parseVariableAssignmentExpression(n),t.push(new a(s,n)),t.push(new a("IFUNDEF",e.value))}}},A.prototype.parseConditionalExpression=function(t){for(this.parseOrExpression(t);this.accept(x,"?");){var e=[],n=[];this.parseConditionalExpression(e),this.expect(x,":"),this.parseConditionalExpression(n),t.push(new a(s,e)),t.push(new a(s,n)),t.push(h("?"))}},A.prototype.parseOrExpression=function(t){for(this.parseAndExpression(t);this.accept(x,"or");){var e=[];this.parseAndExpression(e),t.push(new a(s,e)),t.push(u("or"))}},A.prototype.parseAndExpression=function(t){for(this.parseComparison(t);this.accept(x,"and");){var e=[];this.parseComparison(e),t.push(new a(s,e)),t.push(u("and"))}};var T=["==","!=","<","<=",">=",">","in"];A.prototype.parseComparison=function(t){for(this.parseAddSub(t);this.accept(x,T);){var e=this.current;this.parseAddSub(t),t.push(u(e.value))}};var M=["+","-","||"];A.prototype.parseAddSub=function(t){for(this.parseTerm(t);this.accept(x,M);){var e=this.current;this.parseTerm(t),t.push(u(e.value))}};var O=["*","/","%"];function _(t,e){return Number(t)+Number(e)}function k(t,e){return t-e}function S(t,e){return t*e}function I(t,e){return t/e}function N(t,e){return t%e}function C(t,e){return Array.isArray(t)&&Array.isArray(e)?t.concat(e):""+t+e}function V(t,e){return t===e}function R(t,e){return t!==e}function D(t,e){return t>e}function P(t,e){return t<e}function q(t,e){return t>=e}function L(t,e){return t<=e}function j(t,e){return Boolean(t&&e)}function B(t,e){return Boolean(t||e)}function U(t,e){return y(e,t)}function z(t){return(Math.exp(t)-Math.exp(-t))/2}function $(t){return(Math.exp(t)+Math.exp(-t))/2}function G(t){return t===1/0?1:t===-1/0?-1:(Math.exp(t)-Math.exp(-t))/(Math.exp(t)+Math.exp(-t))}function Y(t){return t===-1/0?t:Math.log(t+Math.sqrt(t*t+1))}function Z(t){return Math.log(t+Math.sqrt(t*t-1))}function K(t){return Math.log((1+t)/(1-t))/2}function W(t){return Math.log(t)*Math.LOG10E}function X(t){return-t}function J(t){return!t}function H(t){return t<0?Math.ceil(t):Math.floor(t)}function Q(t){return Math.random()*(t||1)}function tt(t){return nt(t+1)}A.prototype.parseTerm=function(t){for(this.parseFactor(t);this.accept(x,O);){var e=this.current;this.parseFactor(t),t.push(u(e.value))}},A.prototype.parseFactor=function(t){var e=this.tokens.unaryOps;if(this.save(),this.accept(x,(function(t){return t.value in e}))){if("-"!==this.current.value&&"+"!==this.current.value){if(this.nextToken.type===w&&"("===this.nextToken.value)return this.restore(),void this.parseExponential(t);if("TSEMICOLON"===this.nextToken.type||"TCOMMA"===this.nextToken.type||"TEOF"===this.nextToken.type||this.nextToken.type===w&&")"===this.nextToken.value)return this.restore(),void this.parseAtom(t)}var n=this.current;this.parseFactor(t),t.push(o(n.value))}else this.parseExponential(t)},A.prototype.parseExponential=function(t){for(this.parsePostfixExpression(t);this.accept(x,"^");)this.parseFactor(t),t.push(u("^"))},A.prototype.parsePostfixExpression=function(t){for(this.parseFunctionCall(t);this.accept(x,"!");)t.push(o("!"))},A.prototype.parseFunctionCall=function(t){var e=this.tokens.unaryOps;if(this.accept(x,(function(t){return t.value in e}))){var n=this.current;this.parseAtom(t),t.push(o(n.value))}else for(this.parseMemberExpression(t);this.accept(w,"(");)if(this.accept(w,")"))t.push(new a("IFUNCALL",0));else{var r=this.parseArgumentList(t);t.push(new a("IFUNCALL",r))}},A.prototype.parseArgumentList=function(t){for(var e=0;!this.accept(w,")");)for(this.parseExpression(t),++e;this.accept("TCOMMA");)this.parseExpression(t),++e;return e},A.prototype.parseMemberExpression=function(t){for(this.parseAtom(t);this.accept(x,".")||this.accept("TBRACKET","[");){var e=this.current;if("."===e.value){if(!this.allowMemberAccess)throw new Error('unexpected ".", member access is not permitted');this.expect("TNAME"),t.push(new a("IMEMBER",this.current.value))}else{if("["!==e.value)throw new Error("unexpected symbol: "+e.value);if(!this.tokens.isOperatorEnabled("["))throw new Error('unexpected "[]", arrays are disabled');this.parseExpression(t),this.expect("TBRACKET","]"),t.push(u("["))}}};var et=[.9999999999999971,57.15623566586292,-59.59796035547549,14.136097974741746,-.4919138160976202,3399464998481189e-20,4652362892704858e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.00021743961811521265,-.0001643181065367639,8441822398385275e-20,-26190838401581408e-21,36899182659531625e-22];function nt(t){var e,n;if(function(t){return isFinite(t)&&t===Math.round(t)}(t)){if(t<=0)return isFinite(t)?1/0:NaN;if(t>171)return 1/0;for(var r=t-2,i=t-1;r>1;)i*=r,r--;return 0===i&&(i=1),i}if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*nt(1-t));if(t>=171.35)return 1/0;if(t>85){var s=t*t,a=s*t,o=a*t,u=o*t;return Math.sqrt(2*Math.PI/t)*Math.pow(t/Math.E,t)*(1+1/(12*t)+1/(288*s)-139/(51840*a)-571/(2488320*o)+163879/(209018880*u)+5246819/(75246796800*u*t))}--t,n=et[0];for(var h=1;h<et.length;++h)n+=et[h]/(t+h);return e=t+4.7421875+.5,Math.sqrt(2*Math.PI)*Math.pow(e,t+.5)*Math.exp(-e)*n}function rt(t){return Array.isArray(t)?t.length:String(t).length}function it(){for(var t=0,e=0,n=0;n<arguments.length;n++){var r,i=Math.abs(arguments[n]);e<i?(t=t*(r=e/i)*r+1,e=i):t+=i>0?(r=i/e)*r:i}return e===1/0?1/0:e*Math.sqrt(t)}function st(t,e,n){return t?e:n}function at(t,e){return void 0===e||0==+e?Math.round(t):(t=+t,e=-+e,isNaN(t)||"number"!=typeof e||e%1!=0?NaN:(t=t.toString().split("e"),+((t=(t=Math.round(+(t[0]+"e"+(t[1]?+t[1]-e:-e)))).toString().split("e"))[0]+"e"+(t[1]?+t[1]+e:e))))}function ot(t,e,n){return n&&(n[t]=e),e}function ut(t,e){return t[0|e]}function ht(t){return 1===arguments.length&&Array.isArray(t)?Math.max.apply(Math,t):Math.max.apply(Math,arguments)}function pt(t){return 1===arguments.length&&Array.isArray(t)?Math.min.apply(Math,t):Math.min.apply(Math,arguments)}function lt(t,e){if("function"!=typeof t)throw new Error("First argument to map is not a function");if(!Array.isArray(e))throw new Error("Second argument to map is not an array");return e.map((function(e,n){return t(e,n)}))}function ct(t,e,n){if("function"!=typeof t)throw new Error("First argument to fold is not a function");if(!Array.isArray(n))throw new Error("Second argument to fold is not an array");return n.reduce((function(e,n,r){return t(e,n,r)}),e)}function ft(t,e){if("function"!=typeof t)throw new Error("First argument to filter is not a function");if(!Array.isArray(e))throw new Error("Second argument to filter is not an array");return e.filter((function(e,n){return t(e,n)}))}function dt(t,e){if(!Array.isArray(e)&&"string"!=typeof e)throw new Error("Second argument to indexOf is not a string or array");return e.indexOf(t)}function vt(t,e){if(!Array.isArray(e))throw new Error("Second argument to join is not an array");return e.join(t)}function yt(t){return(t>0)-(t<0)||+t}function mt(t){return t<0?-Math.pow(-t,.3333333333333333):Math.pow(t,.3333333333333333)}function gt(t){return Math.exp(t)-1}function xt(t){return Math.log(1+t)}function wt(t){return Math.log(t)/Math.LN2}function Et(t){this.options=t||{},this.unaryOps={sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,sinh:Math.sinh||z,cosh:Math.cosh||$,tanh:Math.tanh||G,asinh:Math.asinh||Y,acosh:Math.acosh||Z,atanh:Math.atanh||K,sqrt:Math.sqrt,cbrt:Math.cbrt||mt,log:Math.log,log2:Math.log2||wt,ln:Math.log,lg:Math.log10||W,log10:Math.log10||W,expm1:Math.expm1||gt,log1p:Math.log1p||xt,abs:Math.abs,ceil:Math.ceil,floor:Math.floor,round:Math.round,trunc:Math.trunc||H,"-":X,"+":Number,exp:Math.exp,not:J,length:rt,"!":tt,sign:Math.sign||yt},this.binaryOps={"+":_,"-":k,"*":S,"/":I,"%":N,"^":Math.pow,"||":C,"==":V,"!=":R,">":D,"<":P,">=":q,"<=":L,and:j,or:B,in:U,"=":ot,"[":ut},this.ternaryOps={"?":st},this.functions={random:Q,fac:tt,min:pt,max:ht,hypot:Math.hypot||it,pyt:Math.hypot||it,pow:Math.pow,atan2:Math.atan2,if:st,gamma:nt,roundTo:at,map:lt,fold:ct,filter:ft,indexOf:dt,join:vt},this.consts={E:Math.E,PI:Math.PI,true:!0,false:!1}}Et.prototype.parse=function(t){var e=[],n=new A(this,new F(this,t),{allowMemberAccess:this.options.allowMemberAccess});return n.parseExpression(e),n.expect("TEOF","EOF"),new g(e,this)},Et.prototype.evaluate=function(t,e){return this.parse(t).evaluate(e)};var Ft=new Et;Et.parse=function(t){return Ft.parse(t)},Et.evaluate=function(t,e){return Ft.parse(t).evaluate(e)};var bt={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"remainder","^":"power","!":"factorial","<":"comparison",">":"comparison","<=":"comparison",">=":"comparison","==":"comparison","!=":"comparison","||":"concatenate",and:"logical",or:"logical",not:"logical","?":"conditional",":":"conditional","=":"assignment","[":"array","()=":"fndef"};function At(t){return t.name?t.name:t.constructor.name}Et.prototype.isOperatorEnabled=function(t){var e=function(t){return bt.hasOwnProperty(t)?bt[t]:t}(t),n=this.options.operators||{};return!(e in n)||!!n[e]};var Tt,Mt=function(){function t(t){this.message="",this.condition_expr=null,this.validator=t}return Object.defineProperty(t.prototype,"condition",{set:function(t){if(t){var e=new Et;this.condition_expr=e.parse(t)}else this.condition_expr=null},enumerable:!1,configurable:!0}),t}(),Ot=function(){function t(t,e){this.fields=t,this.validator_info=e,this.validations=[]}return t.prototype.addValidation=function(t){this.validations.push(new Mt(t))},t.prototype.addMessage=function(t){this.validations.length>0&&(this.validations[this.validations.length-1].message=t)},t.prototype.addCondition=function(t){this.validations.length>0&&(this.validations[this.validations.length-1].condition=t)},t.prototype.validate=function(t){for(var e={},n=0,r=this.validations;n<r.length;n++){var i=r[n];if(null!==i.condition_expr)if(!i.condition_expr.evaluate(t))continue;for(var s=0,a=this.fields;s<a.length;s++){var o=a[s];i.validator.validate(o,t)||e[o]||(e[o]={validation:At(i.validator),message:this.getMessage(i,o)})}}return e},t.prototype.getMessage=function(t,r){return function(t,n){if("string"==typeof t&&"object"===e(n))for(var r in n)t=t.replace(new RegExp("{{\\s*"+r+"\\s*}}","g"),String(n[r]));return t}(t.message?t.message:this.validator_info.getMessageTemplate(t.validator),n({field:r},t.validator))},t.prototype.hasValidations=function(){return this.validations.length>0},t}(),_t=function(){function t(t){this.field_v=t}return t.prototype.addValidation=function(t){this.field_v.addValidation(t)},t.prototype.validate=function(t){return this.field_v.validate(t)},t.prototype.message=function(t){return this.field_v.addMessage(t),this},t.prototype.onlyWhen=function(t){return this.field_v.addCondition(t),this},t}(),kt=function(){function t(){this.message="{{field}} is required"}return t.prototype.validate=function(t,e){if(e[t]){if(String(e[t]).length>0)return!0}else if(0===e[t]||!1===e[t])return!0;return!1},t}(),St=function(){function t(t){this.max_length=t,this.message="{{field}} exceeded max length {{max_length}}"}return t.prototype.validate=function(t,e){return void 0===e[t]||!(String(e[t]).length>this.max_length)},t}(),It=function(){function t(t){this.min_length=t,this.message="{{field}} input length should be at least {{min_length}}"}return t.prototype.validate=function(t,e){return void 0===e[t]||!(String(e[t]).length<this.min_length)},t}(),Nt={"<":{name:"LessThan",message:"{{field}} should be less than {{test_value}}",fn:function(t,e){return t<e}},"<=":{name:"LessThanOrEqualTo",message:"{{field}} should be less than or equal to {{test_value}}",fn:function(t,e){return t<=e}},">":{name:"GreaterThan",message:"{{field}} should be greater than {{test_value}}",fn:function(t,e){return t>e}},">=":{name:"GreaterThanOrEqualTo",message:"{{field}} should be greater than or equal to {{test_value}}",fn:function(t,e){return t>=e}},"=":{name:"EqualTo",message:"{{field}} should be equal to {{test_value}}",fn:function(t,e){return t===e}},"!=":{name:"NotEqualTo",message:"{{field}} should not be equal to {{test_value}}",fn:function(t,e){return t!==e}}};!function(t){t[t.Value=0]="Value",t[t.Field=1]="Field"}(Tt||(Tt={}));var Ct=function(){function t(t,e){if(this.comparison=t,this.options=e,this.message="",this.test_value=0,this.test_against=Tt.Value,this.name="",!Object.keys(Nt).includes(t))throw Error("unsupported comparison operator "+t);if(this.name=Nt[t].name,this.message=Nt[t].message,void 0!==e.test_value)this.test_against=Tt.Value,this.test_value=e.test_value;else{if(void 0===e.test_field)throw Error("Provide one of test_value or test_field in the options");this.test_against=Tt.Field,this.test_value=e.test_field}}return t.prototype.validate=function(t,e){if(void 0===e[t])return!0;var n,r=this.getOtherValue(e);if("string"==typeof r)n=String(e[t]);else if("number"==typeof r)n=Number(e[t]);else{if(!(r instanceof Date))throw Error("Couldn't identify value type");n=new Date(e[t])}return this.doComparison(n,r)},t.prototype.getOtherValue=function(t){if(this.test_against==Tt.Field){if(void 0===this.options.test_field)throw Error("The test_field is not provided");if("string"==typeof t[this.options.test_field])return String(t[this.options.test_field]);if("number"==typeof t[this.options.test_field])return Number(t[this.options.test_field]);throw Error("Wrong type for test_field (neither string nor number)")}if(void 0===this.options.test_value)throw Error("The test_value is not provided");return this.options.test_value},t.prototype.doComparison=function(t,e){return Nt[this.comparison].fn(t,e)},t}();function Vt(t,e,n){return t(n={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&n.path)}},n.exports),n.exports}var Rt=Vt((function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.isValidDate=function(t,e){return void 0===e&&(e="-"),new RegExp("^(?!0{4}"+e+"0{2}"+e+"0{2})((?=[0-9]{4}"+e+"(((0[^2])|1[0-2])|02(?="+e+"(([0-1][0-9])|2[0-8])))"+e+"[0-9]{2})|(?=((([13579][26])|([2468][048])|(0[48]))0{2})|([0-9]{2}((((0|[2468])[48])|[2468][048])|([13579][26])))"+e+"02"+e+"29))([0-9]{4})"+e+"(?!((0[469])|11)"+e+"31)((0[1,3-9]|1[0-2])|(02(?!"+e+"3)))"+e+"([0-2][0-9]|3[0-1])$").test(t)}})),Dt=Vt((function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.getStringSeparator=function(t){var e=/\D/.exec(t);return e?e[0]:""}})),Pt=Vt((function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.isValidZoneOffset=function(t,e,n){return void 0===n&&(n=":"),new RegExp(e?"^(0(?!(2"+n+"4)|0"+n+"3)|1(?=([0-1]|2(?="+n+"[04])|[34](?="+n+"0))))([03469](?="+n+"[03])|[17](?="+n+"0)|2(?="+n+"[04])|5(?="+n+"[034])|8(?="+n+"[04]))"+n+"([03](?=0)|4(?=5))[05]$":"^(0(?=[^0])|1(?=[0-2]))([39](?="+n+"[03])|[0-24-8](?="+n+"00))"+n+"[03]0$").test(t)}})),qt=Vt((function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.isValidTime=function(t,e,n){void 0===e&&(e=":"),void 0===n&&(n=!1);var r=new RegExp("^([0-1]|2(?=([0-3])|4"+e+"00))[0-9]"+e+"[0-5][0-9]("+e+"([0-5]|6(?=0))[0-9])?(.[0-9]{1,9})?$");if(!n||!/[Z+\-]/.test(t))return r.test(t);if(/Z$/.test(t))return r.test(t.replace("Z",""));var i=t.includes("+"),s=t.split(/[+-]/),a=s[0],o=s[1];return r.test(a)&&Pt.isValidZoneOffset(o,i,Dt.getStringSeparator(o))}})),Lt=Vt((function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.isValidISODateString=function(t){var e,n=t.split("T"),r=n[0],i=n[1],s=Dt.getStringSeparator(r),a=Rt.isValidDate(r,s);return!!i&&a&&qt.isValidTime(i,(e=i.match(/[^Z+\-\d]/),Array.isArray(e)?e[0]:""),!0)}})),jt=Vt((function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.isValidYearMonth=function(t,e){return void 0===e&&(e="-"),new RegExp("^[0-9]{4}"+e+"(0(?=[^0])|1(?=[0-2]))[0-9]$").test(t)}})),Bt=Vt((function(t,e){function n(t){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}Object.defineProperty(e,"__esModule",{value:!0}),n(Rt),n(Lt),n(qt),n(jt)})),Ut="A-Za-zªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͅͰ-ʹͶͷͺ-ͽͿΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԯԱ-Ֆՙՠ-ֈְ-ׇֽֿׁׂׅׄא-תׯ-ײؐ-ؚؠ-ٗٙ-ٟٮ-ۓە-ۜۡ-ۭۨ-ۯۺ-ۼۿܐ-ܿݍ-ޱߊ-ߪߴߵߺࠀ-ࠗࠚ-ࠬࡀ-ࡘࡠ-ࡪࡰ-ࢇࢉ-ࢎࢠ-ࣉࣔ-ࣣࣟ-ࣰࣩ-ऻऽ-ौॎ-ॐॕ-ॣॱ-ঃঅ-ঌএঐও-নপ-রলশ-হঽ-ৄেৈোৌৎৗড়ঢ়য়-ৣৰৱৼਁ-ਃਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਾ-ੂੇੈੋੌੑਖ਼-ੜਫ਼ੰ-ੵઁ-ઃઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽ-ૅે-ૉોૌૐૠ-ૣૹ-ૼଁ-ଃଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽ-ୄେୈୋୌୖୗଡ଼ଢ଼ୟ-ୣୱஂஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹா-ூெ-ைொ-ௌௐௗఀ-ఃఅ-ఌఎ-ఐఒ-నప-హఽ-ౄె-ైొ-ౌౕౖౘ-ౚౝౠ-ౣಀ-ಃಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽ-ೄೆ-ೈೊ-ೌೕೖೝೞೠ-ೣೱೲഀ-ഌഎ-ഐഒ-ഺഽ-ൄെ-ൈൊ-ൌൎൔ-ൗൟ-ൣൺ-ൿඁ-ඃඅ-ඖක-නඳ-රලව-ෆා-ුූෘ-ෟෲෳก-ฺเ-ๆํກຂຄຆ-ຊຌ-ຣລວ-ູົ-ຽເ-ໄໆໍໜ-ໟༀཀ-ཇཉ-ཬཱ-ཱྀྈ-ྗྙ-ྼက-ံးျ-ဿၐ-ႏႚ-ႝႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏽᏸ-ᏽᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛸᜀ-ᜓᜟ-ᜳᝀ-ᝓᝠ-ᝬᝮ-ᝰᝲᝳក-ឳា-ៈៗៜᠠ-ᡸᢀ-ᢪᢰ-ᣵᤀ-ᤞᤠ-ᤫᤰ-ᤸᥐ-ᥭᥰ-ᥴᦀ-ᦫᦰ-ᧉᨀ-ᨛᨠ-ᩞᩡ-ᩴᪧᪿᫀᫌ-ᫎᬀ-ᬳᬵ-ᭃᭅ-ᭌᮀ-ᮩᮬ-ᮯᮺ-ᯥᯧ-ᯱᰀ-ᰶᱍ-ᱏᱚ-ᱽᲀ-ᲈᲐ-ᲺᲽ-Ჿᳩ-ᳬᳮ-ᳳᳵᳶᳺᴀ-ᶿᷧ-ᷴḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕℙ-ℝℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⒶ-ⓩⰀ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞⷠ-ⷿⸯ々-〇〡-〩〱-〵〸-〼ぁ-ゖゝ-ゟァ-ヺー-ヿㄅ-ㄯㄱ-ㆎㆠ-ㆿㇰ-ㇿ㐀-䶿一-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙴ-ꙻꙿ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꟊꟐꟑꟓꟕ-ꟙꟲ-ꠅꠇ-ꠧꡀ-ꡳꢀ-ꣃꣅꣲ-ꣷꣻꣽ-ꣿꤊ-ꤪꤰ-ꥒꥠ-ꥼꦀ-ꦲꦴ-ꦿꧏꧠ-ꧯꧺ-ꧾꨀ-ꨶꩀ-ꩍꩠ-ꩶꩺ-ꪾꫀꫂꫛ-ꫝꫠ-ꫯꫲ-ꫵꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꬰ-ꭚꭜ-ꭩꭰ-ꯪ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ",zt={alpha:{name:"Alphabetic",message:"{{field}} can contain only alphabetic characters",fn:function(t){return RegExp("^["+Ut+"]+$").test(t)}},alpha_s:{name:"Alphabetic",message:"{{field}} can contain only alphabetic characters",fn:function(t){return RegExp("^["+Ut+"\\s]+$").test(t)}},alnum:{name:"AlphaNumeric",message:"{{field}} can contain only alpha-numeric characters",fn:function(t){return RegExp("^["+Ut+"0-9]+$").test(t)}},alnum_s:{name:"AlphaNumeric",message:"{{field}} can contain only alpha-numeric characters",fn:function(t){return RegExp("^["+Ut+"\\s0-9]+$").test(t)}},email:{name:"Email",message:"Please provide a valid email address",fn:function(t){return/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(t)}},number:{name:"Number",message:"Please provide a valid number",fn:function(t){return/^[\-\+]?\d+([\.,]\d+)?$/.test(t)}},phone:{name:"Phone",message:"Please provide a valid phone number",fn:function(t){var e=t.replace(/[^\d]/g,"");return e.length>6&&e.length<=14}},color:{name:"Color",message:"Please provide a valid color code",fn:function(t){return/^#[0-9a-fA-F]{6}$/i.test(t)}},date:{name:"Date",message:"Please enter a valid date",fn:function(t){return Bt.isValidDate(t)}},datetime:{name:"DateTime",message:"Please enter a valid date",fn:function(t){return Bt.isValidISODateString(t)}},url:{name:"URL",message:"Please enter a valid URL",fn:function(t){return/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[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*)?$/i.test(t)}}},$t=function(){function t(t){if(this.type=t,this.message="",this.name="",!Object.keys(zt).includes(t))throw Error("unsupported content type "+t);this.name=zt[t].name,this.message=zt[t].message}return t.prototype.validate=function(t,e){return void 0===e[t]||""==e[t]||zt[this.type].fn(e[t])},t}(),Gt=function(){function t(t){this.max_count=t,this.message="{{field}} selections exceeds max limit {{max_count}}"}return t.prototype.validate=function(t,e){return void 0===e[t]||(!Array.isArray(e[t])||!(e[t].length>this.max_count))},t}(),Yt=function(){function t(t){this.min_count=t,this.message="For {{field}}, select at least {{min_count}} options"}return t.prototype.validate=function(t,e){return void 0===e[t]||(!Array.isArray(e[t])||!(e[t].length<this.min_count))},t}(),Zt=function(){function t(){this.message="{{field}} should be selected"}return t.prototype.validate=function(t,e){return!!e[t]},t}(),Kt=function(){function t(t){this.regex=t,this.message="{{field}} does not match the pattern"}return t.prototype.validate=function(t,e){if(void 0===e[t])return!0;var n=e[t];return new RegExp(this.regex).test(n)},t}(),Wt=function(){function t(t){this.extensions_str=t,this.message="Valid file extensions are: {{extensions_str}}",this.valid_extensions=[],this.valid_extensions=this.extensions_str.split(",").map((function(t){return t.trim()}))}return t.prototype.validate=function(t,e){if(void 0!==e[t]){if("string"==typeof e[t])return this.checkExtension(String(e[t]));if(e[t].file_name&&"string"==typeof e[t].file_name)return this.checkExtension(String(e[t].file_name))}return!0},t.prototype.checkExtension=function(t){if(""==t)return!0;var e=t.split(".").pop();return void 0!==e&&!!this.valid_extensions.includes(e)},t}();function Xt(t,e){var n=new Ot([t.name],e);for(var r in t.validations){var i=t.validations[r],s=Jt(r,i);s&&(n.addValidation(s),n.addMessage(i.message||""),n.addCondition(i.condition||""))}return n}function Jt(t,e){var n=null;switch(t){case"required":!0===e.enabled&&(n=new kt);break;case"maxlength":e.size&&(n=new St(+e.size));break;case"minlength":e.size&&(n=new It(+e.size));break;case"min":void 0!==e.num&&(n=new Ct(">=",{test_value:+e.num}));break;case"max":void 0!==e.num&&(n=new Ct("<=",{test_value:+e.num}));break;case"confirm":e.other&&(n=new Ct("=",{test_field:String(e.other)}));break;case"max_date":void 0!==e.date&&""!==e.other&&(n=new Ct("<=",{test_value:new Date(String(e.date))}));break;case"min_date":void 0!==e.date&&""!==e.other&&(n=new Ct(">=",{test_value:new Date(String(e.date))}));break;case"content_type":var r=String(e.type);r&&(n=new $t(r));break;case"max_count":e.num&&(n=new Gt(Number(e.num)));break;case"min_count":e.num&&(n=new Yt(Number(e.num)));break;case"must_check":e.enabled&&(n=new Zt);break;case"should_select":e.item&&(n=new Ct("=",{test_value:String(e.item)}));break;case"should_not_select":e.item&&(n=new Ct("!=",{test_value:String(e.item)}));break;case"pattern":e.regexp&&(n=new Kt(String(e.regexp)));break;case"file_extension":e.valid_extensions&&(n=new Wt(String(e.valid_extensions)))}return n}var Ht=function(){function t(){this.validator_makers={},this.all_validators={}}return t.prototype.addValidator=function(t,e){if("string"==typeof t)this.validator_makers[t]=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=e.apply(void 0,t);return null!=r&&this.addValidation(r),this};else for(var n=0,r=t;n<r.length;n++){var i=r[n];this.addValidator(i,e)}return this},t.prototype.updateMessages=function(t){for(var e in t)this.all_validators[e]?this.all_validators[e].message=t[e]:this.all_validators[e]={message:t[e]}},t.prototype.field=function(t){var e=new _t(new Ot([t],this));return Object.assign(e,this.validator_makers),e},t.prototype.fields=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=new _t(new Ot(t,this));return Object.assign(n,this.validator_makers),n},t.prototype.validate=function(t,e){return this.validateByRules(t,e)},t.prototype.validateByRules=function(t,e){for(var r={},i=0,s=t;i<s.length;i++){var a=s[i].validate(e);r=n(n({},r),a)}return{has_errors:Object.keys(r).length>0,error_map:r}},t.prototype.validateFields=function(t,e){var n=function(t,e){for(var n=[],r=0,i=t;r<i.length;r++){var s=Xt(i[r],e);s.hasValidations()&&n.push(s)}return n}(t,this);return n.length<=0?{has_errors:!1}:this.validateByRules(n,e)},t.prototype.getMessageTemplate=function(t){var e="Error! ",n=At(t);return this.all_validators[n]&&this.all_validators[n].message?e=this.all_validators[n].message:t.message&&(e=t.message),e},t}();return t.makeBoel=function(){return function(t){return t.addValidator(["isRequired","areRequired","required"],(function(){return new kt})).addValidator(["maxLength","checkMaxLength"],(function(t){return"number"==typeof t?new St(t):null})).addValidator(["minLength","checkMinLength"],(function(t){return"number"==typeof t?new It(t):null})).addValidator(["isAlphabetic","areAlphabetic"],(function(t){return void 0===t&&(t=!0),new $t(t?"alpha_s":"alpha")})).addValidator(["isAlphaNumeric","areAlphaNumeric"],(function(t){return void 0===t&&(t=!0),new $t(t?"alnum_s":"alnum")})).addValidator(["isEmail","areEmails"],(function(){return new $t("email")})).addValidator(["isPhone","isPhoneNumber","arePhoneNumbers"],(function(){return new $t("phone")})).addValidator(["isNumber","areNumbers"],(function(){return new $t("number")})).addValidator(["isColorCode","areColorCodes"],(function(){return new $t("color")})).addValidator(["isDate","areDates"],(function(){return new $t("date")})).addValidator(["isDateTime","areDateTime"],(function(){return new $t("datetime")})).addValidator(["isURL","areURLs"],(function(){return new $t("url")})).addValidator(["lessThan","isLessThan","areLessThan"],(function(t){return"number"==typeof t?new Ct("<",{test_value:t}):null})).addValidator(["lessThanOrEqualTo","isLessThanOrEqualTo","areLessThanOrEqualTo","max","isMax","areMax"],(function(t){return"number"==typeof t?new Ct("<=",{test_value:t}):null})).addValidator(["greaterThan","isGreaterThan","areGreaterThan"],(function(t){return"number"==typeof t?new Ct(">",{test_value:t}):null})).addValidator(["greaterThanOrEqualTo","isGreaterThanOrEqualTo","areGreaterThanOrEqualTo"],(function(t){return"number"==typeof t?new Ct(">=",{test_value:t}):null})).addValidator(["equalsTo","isEqualTo","areEqualTo"],(function(t){return"number"==typeof t||"string"==typeof t?new Ct("=",{test_value:t}):null})).addValidator(["notEqualTo","isNotEqualTo","areNotEqualTo"],(function(t){return"number"==typeof t||"string"==typeof t?new Ct("!=",{test_value:t}):null})).addValidator(["maxDate","onOrBefore"],(function(t){return"string"==typeof t?new Ct("<=",{test_value:new Date(t)}):null})).addValidator(["minDate","onOrAfter"],(function(t){return"string"==typeof t?new Ct(">=",{test_value:new Date(t)}):null})).addValidator(["lessThanField","isLessThanField","areLessThanField"],(function(t){return"string"==typeof t?new Ct("<",{test_field:t}):null})).addValidator(["lessThanOrEqualToField","isLessThanOrEqualToField","areLessThanOrEqualToField"],(function(t){return"string"==typeof t?new Ct("<=",{test_field:t}):null})).addValidator(["greaterThanField","isGreaterThanField","areGreaterThanField"],(function(t){return"string"==typeof t?new Ct(">",{test_field:t}):null})).addValidator(["greaterThanOrEqualToField","isGreaterThanOrEqualToField","areGreaterThanOrEqualToField"],(function(t){return"string"==typeof t?new Ct(">=",{test_field:t}):null})).addValidator(["equalsToField","isEqualToField","areEqualToField"],(function(t){return"string"==typeof t?new Ct("=",{test_field:t}):null})).addValidator(["notEqualsToField","isNotEqualToField","areNotEqualToField"],(function(t){return"string"==typeof t?new Ct("!=",{test_field:t}):null})).addValidator(["maxSelections","hasMaxSelections","maxCount"],(function(t){return"number"==typeof t?new Gt(t):null})).addValidator(["minSelections","hasMinSelections","minCount"],(function(t){return"number"==typeof t?new Yt(t):null})).addValidator(["isSelected","selected"],(function(){return new Zt})).addValidator(["shouldSelect"],(function(t){return new Ct("=",{test_value:String(t)})})).addValidator(["shouldNotSelect"],(function(t){return new Ct("!=",{test_value:String(t)})})).addValidator(["matchesPattern","pattern"],(function(t){return new Kt(String(t))})).addValidator(["hasExtension","hasFileExtension"],(function(t){return"string"==typeof t?new Wt(t):null})),t}(new Ht)},t}({});