!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).exprEval={})}(this,function(t){"use strict";var y="INUMBER",x="IOP1",w="IOP2",d="IOP3",g="IVAR",M="IVARNAME",E="IFUNCALL",m="IFUNDEF",A="IEXPR",b="IEXPREVAL",k="IMEMBER",O="IENDSTATEMENT",T="IARRAY";function C(t,e){this.type=t,this.value=null!=e?e:0}function c(t){return new C(x,t)}function f(t){return new C(w,t)}function l(t){return new C(d,t)}function N(t,i,o){var e,r,s,n,a,p,h=[];if(I(t))return P(t,o);for(var u=t.length,c=0;c=this.expression.length?this.newToken(n,"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)+'"')},B.prototype.isString=function(){var t=!1,e=this.pos,r=this.expression.charAt(e);if("'"===r||'"'===r)for(var s=this.expression.indexOf(r,e+1);0<=s&&this.pos=this.expression.length));)e=this.expression.charAt(this.pos);return t};var V=/^[0-9a-f]{4}$/i;function _(t,e,r){this.parser=t,this.tokens=e,this.current=null,this.nextToken=null,this.next(),this.savedCurrent=null,this.savedNextToken=null,this.allowMemberAccess=!1!==r.allowMemberAccess}B.prototype.unescape=function(t){var e=t.indexOf("\\");if(e<0)return t;for(var r=t.substring(0,e);0<=e;){var s=t.charAt(++e);switch(s){case"'":r+="'";break;case'"':r+='"';break;case"\\":r+="\\";break;case"/":r+="/";break;case"b":r+="\b";break;case"f":r+="\f";break;case"n":r+="\n";break;case"r":r+="\r";break;case"t":r+="\t";break;case"u":var n=t.substring(e+1,e+5);V.test(n)||this.parseError("Illegal escape sequence: \\u"+n),r+=String.fromCharCode(parseInt(n,16)),e+=4;break;default:throw this.parseError('Illegal escape sequence: "\\'+s+'"')}++e;var i=t.indexOf("\\",e);r+=t.substring(e,i<0?t.length:i),e=i}return r},B.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)},B.prototype.isRadixInteger=function(){var t,e,r=this.pos;if(r>=this.expression.length-2||"0"!==this.expression.charAt(r))return!1;if(++r,"x"===this.expression.charAt(r))t=16,e=/^[0-9a-f]$/i,++r;else{if("b"!==this.expression.charAt(r))return!1;t=2,e=/^[01]$/i,++r}for(var s=!1,n=r;r"===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(h,">="),this.pos++):this.current=this.newToken(h,">");else if("<"===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(h,"<="),this.pos++):this.current=this.newToken(h,"<");else if("|"===e){if("|"!==this.expression.charAt(this.pos+1))return!1;this.current=this.newToken(h,"||"),this.pos++}else if("="===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(h,"=="),this.pos++):this.current=this.newToken(h,e);else{if("!"!==e)return!1;"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(h,"!="),this.pos++):this.current=this.newToken(h,e)}return this.pos++,!!this.isOperatorEnabled(this.current.value)||(this.pos=t,!1)},B.prototype.isOperatorEnabled=function(t){return this.parser.isOperatorEnabled(t)},B.prototype.getCoordinates=function(){for(var t,e=0,r=-1;e++,t=this.pos-r,0<=(r=this.expression.indexOf("\n",r+1))&&r=",">","in"];_.prototype.parseComparison=function(t){for(this.parseAddSub(t);this.accept(h,r);){var e=this.current;this.parseAddSub(t),t.push(f(e.value))}};var $=["+","-","||"];_.prototype.parseAddSub=function(t){for(this.parseTerm(t);this.accept(h,$);){var e=this.current;this.parseTerm(t),t.push(f(e.value))}};var D=["*","/","%"];function e(t,e){return Number(t)+Number(e)}function G(t,e){return t-e}function J(t,e){return t*e}function W(t,e){return t/e}function X(t,e){return t%e}function Y(t,e){return Array.isArray(t)&&Array.isArray(e)?t.concat(e):""+t+e}function K(t,e){return t===e}function z(t,e){return t!==e}function H(t,e){return e":H,"<":Q,">=":Z,"<=":tt,and:et,or:rt,in:st,"=":At,"[":bt},this.ternaryOps={"?":Et},this.functions={random:vt,fac:yt,min:Ot,max:kt,hypot:Math.hypot||Mt,pyt:Math.hypot||Mt,pow:Math.pow,atan2:Math.atan2,if:Et,gamma:dt,roundTo:mt,map:Tt,fold:Ct,filter:Nt,indexOf:St,join:It},this.consts={E:Math.E,PI:Math.PI,true:!0,false:!1}}qt.prototype.parse=function(t){var e=[],r=new _(this,new B(this,t),{allowMemberAccess:this.options.allowMemberAccess});return r.parseExpression(e),r.expect(n,"EOF"),new s(e,this)},qt.prototype.evaluate=function(t,e){return this.parse(t).evaluate(e)};var Bt=new qt;qt.parse=function(t){return Bt.parse(t)},qt.evaluate=function(t,e){return Bt.parse(t).evaluate(e)};var Vt={"+":"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"};qt.prototype.isOperatorEnabled=function(t){var e=function(t){return Vt.hasOwnProperty(t)?Vt[t]:t}(t),r=this.options.operators||{};return!(e in r&&!r[e])};var _t={Parser:qt,Expression:s};t.Expression=s,t.Parser=qt,t.default=_t,Object.defineProperty(t,"__esModule",{value:!0})});