UNPKG

boel

Version:

Form Data validation library

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