@oat-sa/expr-eval
Advanced tools
Comparing version 2.1.1 to 2.1.2
@@ -157,2 +157,3 @@ (function (global, factory) { | ||
var n1, n2, n3; | ||
var op1, op2; | ||
var f, args, argCount; | ||
@@ -169,18 +170,21 @@ | ||
var type = item.type; | ||
var token = item.value; | ||
if (type === INUMBER || type === IVARNAME) { | ||
nstack.push(item.value, item.value); | ||
nstack.push(type, token); | ||
} else if (type === IOP2) { | ||
var right = nstack.pop(); | ||
var left = nstack.pop(); | ||
n2 = right.value; | ||
n1 = left.value; | ||
if (item.value === 'and') { | ||
nstack.push(item.value, n1 ? !!evaluate(n2, expr, values) : false); | ||
} else if (item.value === 'or') { | ||
nstack.push(item.value, n1 ? true : !!evaluate(n2, expr, values)); | ||
} else if (item.value === '=') { | ||
f = expr.binaryOps[item.value]; | ||
nstack.push(item.value, f(n1, evaluate(n2, expr, values), values)); | ||
} else if ((item.value === '+' || item.value === '-') && right.token === '#' && right.token !== left.token) { | ||
f = expr.binaryOps[item.value]; | ||
op2 = nstack.pop(); | ||
op1 = nstack.pop(); | ||
n2 = op2.value; | ||
n1 = op1.value; | ||
if (token === 'and') { | ||
nstack.push(token, n1 ? !!evaluate(n2, expr, values) : false); | ||
} else if (token === 'or') { | ||
nstack.push(token, n1 ? true : !!evaluate(n2, expr, values)); | ||
} else if (token === '=') { | ||
f = expr.binaryOps[token]; | ||
nstack.push(token, f(n1, evaluate(n2, expr, values), values)); | ||
} else if (token === '+' && op2.token === '#' && op2.token !== op1.token) { | ||
// If the percentage operator is applied to the right-hand operand of an addition, | ||
// we need to take into account the left-hand operand, because the percentage applies to it | ||
f = expr.binaryOps[token]; | ||
n1 = resolveExpression(n1, values); | ||
@@ -192,6 +196,6 @@ n2 = evaluate([ | ||
], expr, values); | ||
nstack.push(item.value, f(n1, n2)); | ||
nstack.push(token, f(n1, n2)); | ||
} else { | ||
f = expr.binaryOps[item.value]; | ||
nstack.push(item.value, f(resolveExpression(n1, values), resolveExpression(n2, values))); | ||
f = expr.binaryOps[token]; | ||
nstack.push(token, f(resolveExpression(n1, values), resolveExpression(n2, values))); | ||
} | ||
@@ -202,28 +206,34 @@ } else if (type === IOP3) { | ||
n1 = nstack.popValue(); | ||
if (item.value === '?') { | ||
nstack.push(item.value, evaluate(n1 ? n2 : n3, expr, values)); | ||
if (token === '?') { | ||
nstack.push(token, evaluate(n1 ? n2 : n3, expr, values)); | ||
} else { | ||
f = expr.ternaryOps[item.value]; | ||
nstack.push(item.value, f(resolveExpression(n1, values), resolveExpression(n2, values), resolveExpression(n3, values))); | ||
f = expr.ternaryOps[token]; | ||
nstack.push(token, f(resolveExpression(n1, values), resolveExpression(n2, values), resolveExpression(n3, values))); | ||
} | ||
} else if (type === IVAR) { | ||
if (/^__proto__|prototype|constructor$/.test(item.value)) { | ||
if (/^__proto__|prototype|constructor$/.test(token)) { | ||
throw new Error('prototype access detected'); | ||
} | ||
if (item.value in expr.functions) { | ||
nstack.push(item.value, expr.functions[item.value]); | ||
} else if (item.value in expr.unaryOps && expr.parser.isOperatorEnabled(item.value)) { | ||
nstack.push(item.value, expr.unaryOps[item.value]); | ||
if (token in expr.functions) { | ||
nstack.push(token, expr.functions[token]); | ||
} else if (token in expr.unaryOps && expr.parser.isOperatorEnabled(token)) { | ||
nstack.push(token, expr.unaryOps[token]); | ||
} else { | ||
var v = values[item.value]; | ||
var v = values[token]; | ||
if (v !== undefined) { | ||
nstack.push(item.value, v); | ||
nstack.push(token, v); | ||
} else { | ||
throw new Error('undefined variable: ' + item.value); | ||
throw new Error('undefined variable: ' + token); | ||
} | ||
} | ||
} else if (type === IOP1) { | ||
n1 = nstack.popValue(); | ||
f = expr.unaryOps[item.value]; | ||
nstack.push(item.value, f(resolveExpression(n1, values))); | ||
op1 = nstack.pop(); | ||
n1 = op1.value; | ||
f = expr.unaryOps[token]; | ||
// If the percentage operator was applied to the operand of a negation, we need to forward it through the context. | ||
// Otherwise, it will be ignored from the detection made on a possible addition. | ||
if (token === '-' && op1.token === '#') { | ||
token = '#'; | ||
} | ||
nstack.push(token, f(resolveExpression(n1, values))); | ||
} else if (type === IFUNCOP) { | ||
@@ -233,5 +243,5 @@ n2 = nstack.popValue(); | ||
args = [n1, n2]; | ||
f = expr.functions[item.value]; | ||
f = expr.functions[token]; | ||
if (f.apply && f.call) { | ||
nstack.push(item.value, f.apply(undefined, args)); | ||
nstack.push(token, f.apply(undefined, args)); | ||
} else { | ||
@@ -241,3 +251,3 @@ throw new Error(f + ' is not a function'); | ||
} else if (type === IFUNCALL) { | ||
argCount = item.value; | ||
argCount = token; | ||
args = []; | ||
@@ -249,3 +259,3 @@ while (argCount-- > 0) { | ||
if (f.apply && f.call) { | ||
nstack.push(item.value, f.apply(undefined, args)); | ||
nstack.push(token, f.apply(undefined, args)); | ||
} else { | ||
@@ -259,3 +269,3 @@ throw new Error(f + ' is not a function'); | ||
var args = []; | ||
var argCount = item.value; | ||
var argCount = token; | ||
while (argCount-- > 0) { | ||
@@ -281,12 +291,12 @@ args.unshift(nstack.popValue()); | ||
} else if (type === IEXPR) { | ||
nstack.push(IEXPR, createExpressionEvaluator(item, expr)); | ||
nstack.push(type, createExpressionEvaluator(item, expr)); | ||
} else if (type === IEXPREVAL) { | ||
nstack.push(IEXPREVAL, item); | ||
nstack.push(type, item); | ||
} else if (type === IMEMBER) { | ||
n1 = nstack.popValue(); | ||
nstack.push(item.value, n1[item.value]); | ||
nstack.push(token, n1[token]); | ||
} else if (type === IENDSTATEMENT) { | ||
nstack.pop(); | ||
} else if (type === IARRAY) { | ||
argCount = item.value; | ||
argCount = token; | ||
args = []; | ||
@@ -296,3 +306,3 @@ while (argCount-- > 0) { | ||
} | ||
nstack.push(IARRAY, args); | ||
nstack.push(type, args); | ||
} else { | ||
@@ -1280,6 +1290,6 @@ throw new Error('invalid Expression'); | ||
ParserState.prototype.parseComparison = function (instr) { | ||
this.parseAddSub(instr); | ||
this.parseConcat(instr); | ||
while (this.accept(TOP, COMPARISON_OPERATORS)) { | ||
var op = this.current; | ||
this.parseAddSub(instr); | ||
this.parseConcat(instr); | ||
instr.push(binaryInstruction(op.value)); | ||
@@ -1289,8 +1299,25 @@ } | ||
var ADD_SUB_OPERATORS = ['+', '-', '||']; | ||
ParserState.prototype.parseConcat = function (instr) { | ||
this.parseAddSub(instr); | ||
while (this.accept(TOP, '||')) { | ||
this.parseAddSub(instr); | ||
instr.push(binaryInstruction('||')); | ||
} | ||
}; | ||
var ADD_SUB_OPERATORS = ['+', '-']; | ||
ParserState.prototype.parseAddSub = function (instr) { | ||
this.parseTerm(instr); | ||
this.save(); | ||
while (this.accept(TOP, ADD_SUB_OPERATORS)) { | ||
var op = this.current; | ||
if (op.value === '-') { | ||
// Turns the subtraction into an addition of a negative number. | ||
// This is needed as the addition is commutative while subtraction is not. | ||
// To properly manage the percentage operator, the operation order is reversed, | ||
// and the operation actually needs to be commutative. | ||
op = Object.assign({}, op, { value: '+' }); | ||
this.restore(); | ||
} | ||
this.parseAddSub(instr); | ||
@@ -1297,0 +1324,0 @@ instr.push(binaryInstruction(op.value)); |
@@ -1,2 +0,2 @@ | ||
!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 e="INUMBER",r="IOP1",s="IOP2",n="IOP3",i="IVAR",o="IVARNAME",a="IFUNCOP",p="IFUNCALL",u="IFUNDEF",h="IEXPR",c="IEXPREVAL",l="IMEMBER",f="IENDSTATEMENT",v="IARRAY";function y(t,e){this.type=t,this.value=null!=e?e:0}function x(t){return new y(r,t)}function w(t){return new y(s,t)}function d(t){return new y(n,t)}function g(t,a,p,u,c){for(var f,x,w,d,E=[],M=[],m=0;m<t.length;m++){var A=t[m],b=A.type;if(b===e||b===o)Array.isArray(A.value)?E.push.apply(E,g(A.value.map((function(t){return new y(e,t)})).concat(new y(v,A.value.length)),a,p,u,c)):E.push(A);else if(b===i&&Object.prototype.hasOwnProperty.call(c,A.value))A=new y(e,c[A.value]),E.push(A);else if(b===s&&E.length>1)x=E.pop(),f=E.pop(),d=p[A.value],A=new y(e,d(f.value,x.value)),E.push(A);else if(b===n&&E.length>2)w=E.pop(),x=E.pop(),f=E.pop(),"?"===A.value?E.push(f.value?x.value:w.value):(d=u[A.value],A=new y(e,d(f.value,x.value,w.value)),E.push(A));else if(b===r&&E.length>0)f=E.pop(),d=a[A.value],A=new y(e,d(f.value)),E.push(A);else if(b===h){for(;E.length>0;)M.push(E.shift());M.push(new y(h,g(A.value,a,p,u,c)))}else if(b===l&&E.length>0)f=E.pop(),E.push(new y(e,f.value[A.value]));else{for(;E.length>0;)M.push(E.shift());M.push(A)}}for(;E.length>0;)M.push(E.shift());return M}function E(t,e,o){for(var a=[],p=0;p<t.length;p++){var u=t[p],c=u.type;if(c===i&&u.value===e)for(var l=0;l<o.tokens.length;l++){var f,v=o.tokens[l];f=v.type===r?x(v.value):v.type===s?w(v.value):v.type===n?d(v.value):new y(v.type,v.value),a.push(f)}else c===h?a.push(new y(h,E(u.value,e,o))):a.push(u)}return a}function M(t,y,x){var w,d,g,E,k,O,T,C=(w=[],{get length(){return w.length},pop:function(){return w.pop()},popValue:function(){return w.pop().value},push:function(t,e){w.push({token:t,value:e})},first:function(){return w[0]&&w[0].value}});if(A(t))return b(t,x);for(var N=t.length,S=0;S<N;S++){var I=t[S],F=I.type;if(F===e||F===o)C.push(I.value,I.value);else if(F===s){var P=C.pop(),V=C.pop();g=P.value,d=V.value,"and"===I.value?C.push(I.value,!!d&&!!M(g,y,x)):"or"===I.value?C.push(I.value,!!d||!!M(g,y,x)):"="===I.value?(k=y.binaryOps[I.value],C.push(I.value,k(d,M(g,y,x),x))):"+"!==I.value&&"-"!==I.value||"#"!==P.token||P.token===V.token?(k=y.binaryOps[I.value],C.push(I.value,k(b(d,x),b(g,x)))):(k=y.binaryOps[I.value],d=b(d,x),g=M([{type:e,value:d},{type:e,value:b(g,x)},{type:s,value:"*"}],y,x),C.push(I.value,k(d,g)))}else if(F===n)E=C.popValue(),g=C.popValue(),d=C.popValue(),"?"===I.value?C.push(I.value,M(d?g:E,y,x)):(k=y.ternaryOps[I.value],C.push(I.value,k(b(d,x),b(g,x),b(E,x))));else if(F===i){if(/^__proto__|prototype|constructor$/.test(I.value))throw new Error("prototype access detected");if(I.value in y.functions)C.push(I.value,y.functions[I.value]);else if(I.value in y.unaryOps&&y.parser.isOperatorEnabled(I.value))C.push(I.value,y.unaryOps[I.value]);else{var j=x[I.value];if(void 0===j)throw new Error("undefined variable: "+I.value);C.push(I.value,j)}}else if(F===r)d=C.popValue(),k=y.unaryOps[I.value],C.push(I.value,k(b(d,x)));else if(F===a){if(g=C.popValue(),O=[d=C.popValue(),g],!(k=y.functions[I.value]).apply||!k.call)throw new Error(k+" is not a function");C.push(I.value,k.apply(void 0,O))}else if(F===p){for(T=I.value,O=[];T-- >0;)O.unshift(b(C.popValue(),x));if(!(k=C.popValue()).apply||!k.call)throw new Error(k+" is not a function");C.push(I.value,k.apply(void 0,O))}else if(F===u)C.push(F,function(){for(var t=C.popValue(),e=[],r=I.value;r-- >0;)e.unshift(C.popValue());var s=C.popValue(),n=function(){for(var r=Object.assign({},x),s=0,n=e.length;s<n;s++)r[e[s]]=arguments[s];return M(t,y,r)};return Object.defineProperty(n,"name",{value:s,writable:!1}),x[s]=n,n}());else if(F===h)C.push(h,m(I,y));else if(F===c)C.push(c,I);else if(F===l)d=C.popValue(),C.push(I.value,d[I.value]);else if(F===f)C.pop();else{if(F!==v)throw new Error("invalid Expression");for(T=I.value,O=[];T-- >0;)O.unshift(C.popValue());C.push(v,O)}}if(C.length>1)throw new Error("invalid Expression (parity)");return 0===C.first()?0:b(C.first(),x)}function m(t,e,r){return A(t)?t:{type:c,value:function(r){return M(t.value,e,r)}}}function A(t){return t&&t.type===c}function b(t,e){return A(t)?t.value(e):t}function k(t,a){for(var c,y,x,w,d,g,E=[],M=0;M<t.length;M++){var m=t[M],A=m.type;if(A===e)"number"==typeof m.value&&m.value<0?E.push("("+m.value+")"):Array.isArray(m.value)?E.push("["+m.value.map(O).join(", ")+"]"):E.push(O(m.value));else if(A===s)y=E.pop(),c=E.pop(),w=m.value,a?"^"===w?E.push("Math.pow("+c+", "+y+")"):"and"===w?E.push("(!!"+c+" && !!"+y+")"):"or"===w?E.push("(!!"+c+" || !!"+y+")"):"||"===w?E.push("(function(a,b){ return Array.isArray(a) && Array.isArray(b) ? a.concat(b) : String(a) + String(b); }(("+c+"),("+y+")))"):"=="===w?E.push("("+c+" === "+y+")"):"!="===w?E.push("("+c+" !== "+y+")"):"["===w?E.push(c+"[("+y+") | 0]"):E.push("("+c+" "+w+" "+y+")"):"["===w?E.push(c+"["+y+"]"):E.push("("+c+" "+w+" "+y+")");else if(A===n){if(x=E.pop(),y=E.pop(),c=E.pop(),"?"!==(w=m.value))throw new Error("invalid Expression");E.push("("+c+" ? "+y+" : "+x+")")}else if(A===i||A===o)E.push(m.value);else if(A===r)c=E.pop(),"-"===(w=m.value)||"+"===w?E.push("("+w+c+")"):a?"not"===w?E.push("(!"+c+")"):"!"===w?E.push("fac("+c+")"):"#"===w?E.push("percent("+c+")"):E.push(w+"("+c+")"):"!"===w?E.push("("+c+"!)"):"#"===w?E.push("("+c+"#)"):E.push("("+w+" "+c+")");else if(A===p){for(g=m.value,d=[];g-- >0;)d.unshift(E.pop());w=E.pop(),E.push(w+"("+d.join(", ")+")")}else if(A===u){for(y=E.pop(),g=m.value,d=[];g-- >0;)d.unshift(E.pop());c=E.pop(),a?E.push("("+c+" = function("+d.join(", ")+") { return "+y+" })"):E.push("("+c+"("+d.join(", ")+") = "+y+")")}else if(A===l)c=E.pop(),E.push(c+"."+m.value);else if(A===v){for(g=m.value,d=[];g-- >0;)d.unshift(E.pop());E.push("["+d.join(", ")+"]")}else if(A===h)E.push("("+k(m.value,a)+")");else if(A!==f)throw new Error("invalid Expression")}return E.length>1&&(E=a?[E.join(",")]:[E.join(";")]),String(E[0])}function O(t){return"string"==typeof t?JSON.stringify(t).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029"):t}function T(t,e){for(var r=0;r<t.length;r++)if(t[r]===e)return!0;return!1}function C(t,e,r){for(var s=!!(r=r||{}).withMembers,n=null,a=0;a<t.length;a++){var p=t[a];p.type===i||p.type===o?s||T(e,p.value)?null!==n?(T(e,n)||e.push(n),n=p.value):n=p.value:e.push(p.value):p.type===l&&s&&null!==n?n+="."+p.value:p.type===h?C(p.value,e,r):null!==n&&(T(e,n)||e.push(n),n=null)}null===n||T(e,n)||e.push(n)}function N(t,e){this.tokens=t,this.parser=e,this.unaryOps=e.unaryOps,this.binaryOps=e.binaryOps,this.ternaryOps=e.ternaryOps,this.functions=e.functions}y.prototype.toString=function(){switch(this.type){case e:case r:case s:case n:case i:case o:case f:case a:return this.value;case p:return"CALL "+this.value;case u:return"DEF "+this.value;case v:return"ARRAY "+this.value;case l:return"."+this.value;default:return"Invalid Instruction"}},N.prototype.simplify=function(t){return t=t||{},new N(g(this.tokens,this.unaryOps,this.binaryOps,this.ternaryOps,t),this.parser)},N.prototype.substitute=function(t,e){return e instanceof N||(e=this.parser.parse(String(e))),new N(E(this.tokens,t,e),this.parser)},N.prototype.evaluate=function(t){return t=t||{},M(this.tokens,this,t)},N.prototype.toString=function(){return k(this.tokens,!1)},N.prototype.symbols=function(t){t=t||{};var e=[];return C(this.tokens,e,t),e},N.prototype.variables=function(t){t=t||{};var e=[];C(this.tokens,e,t);var r=this.functions;return e.filter((function(t){return!(t in r)}))},N.prototype.toJSFunction=function(t,e){var r=this,s=new Function(t,"with(this.functions) with (this.ternaryOps) with (this.binaryOps) with (this.unaryOps) { return "+k(this.simplify(e).tokens,!0)+"; }");return function(){return s.apply(r,arguments)}};var S="TEOF",I="TOP",F="TFUNCOP",P="TNUMBER",V="TSTRING",j="TPAREN",L="TBRACKET",R="TCOMMA",U="TNAME",_="TSEMICOLON";function q(t,e,r){this.type=t,this.value=e,this.index=r}function B(t,e){this.pos=0,this.current=null,this.unaryOps=t.unaryOps,this.binaryOps=t.binaryOps,this.ternaryOps=t.ternaryOps,this.functions=t.functions,this.consts=t.consts,this.expression=e,this.savedPosition=0,this.savedCurrent=null,this.options=t.options,this.parser=t}q.prototype.toString=function(){return this.type+": "+this.value},B.prototype.newToken=function(t,e,r){return new q(t,e,null!=r?r:this.pos)},B.prototype.save=function(){this.savedPosition=this.pos,this.savedCurrent=this.current},B.prototype.restore=function(){this.pos=this.savedPosition,this.current=this.savedCurrent},B.prototype.next=function(){return this.pos>=this.expression.length?this.newToken(S,"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.isFuncOp()||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);s>=0&&this.pos<this.expression.length;){if(this.pos=s+1,"\\"!==this.expression.charAt(s-1)){var n=this.expression.substring(e+1,s);this.current=this.newToken(V,this.unescape(n),e),t=!0;break}s=this.expression.indexOf(r,s+1)}return t},B.prototype.isParen=function(){var t=this.expression.charAt(this.pos);return("("===t||")"===t)&&(this.current=this.newToken(j,t),this.pos++,!0)},B.prototype.isBracket=function(){var t=this.expression.charAt(this.pos);return!("["!==t&&"]"!==t||!this.isOperatorEnabled("["))&&(this.current=this.newToken(L,t),this.pos++,!0)},B.prototype.isComma=function(){return","===this.expression.charAt(this.pos)&&(this.current=this.newToken(R,","),this.pos++,!0)},B.prototype.isSemicolon=function(){return";"===this.expression.charAt(this.pos)&&(this.current=this.newToken(_,";"),this.pos++,!0)},B.prototype.isConst=function(){for(var t=this.pos,e=t;e<this.expression.length;e++){var r=this.expression.charAt(e);if(r.toUpperCase()===r.toLowerCase()&&(e===this.pos||"_"!==r&&"."!==r&&(r<"0"||r>"9")))break}if(e>t){var s=this.expression.substring(t,e);if(s in this.consts)return this.current=this.newToken(P,this.consts[s]),this.pos+=s.length,!0}return!1},B.prototype.isNamedOp=function(){for(var t=this.pos,e=t;e<this.expression.length;e++){var r=this.expression.charAt(e);if(r.toUpperCase()===r.toLowerCase()&&(e===this.pos||"_"!==r&&(r<"0"||r>"9")))break}if(e>t){var s=this.expression.substring(t,e);if(this.isOperatorEnabled(s)&&(s in this.binaryOps||s in this.unaryOps||s in this.ternaryOps))return this.current=this.newToken(I,s),this.pos+=s.length,!0}return!1},B.prototype.isFuncOp=function(){var t,e=this.expression.charAt(this.pos),r=this.pos+1,s=r;if("@"===e){for(;s<this.expression.length&&((e=this.expression.charAt(s)).toUpperCase()!==e.toLowerCase()||!(s===r||"_"!==e&&(e<"0"||e>"9")));s++);if(s>r&&(t=this.expression.substring(r,s))in this.functions)return this.current=this.newToken(F,t),this.pos=r+t.length,!0}return!1},B.prototype.isName=function(){for(var t=this.pos,e=t,r=!1;e<this.expression.length;e++){var s=this.expression.charAt(e);if(s.toUpperCase()===s.toLowerCase()){if(e===this.pos&&("$"===s||"_"===s)){"_"===s&&(r=!0);continue}if(e===this.pos||!r||"_"!==s&&(s<"0"||s>"9"))break}else r=!0}if(r){var n=this.expression.substring(t,e);return this.current=this.newToken(U,n),this.pos+=n.length,!0}return!1},B.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 $=/^[0-9a-f]{4}$/i;function D(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);e>=0;){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);$.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<this.expression.length;){var i=this.expression.charAt(r);if(!e.test(i))break;r++,s=!0}return s&&(this.current=this.newToken(P,parseInt(this.expression.substring(n,r),t)),this.pos=r),s},B.prototype.isNumber=function(){for(var t,e=!1,r=this.pos,s=r,n=r,i=!1,o=!1;r<this.expression.length&&((t=this.expression.charAt(r))>="0"&&t<="9"||!i&&"."===t);)"."===t?i=!0:o=!0,r++,e=o;if(e&&(n=r),"e"===t||"E"===t){r++;for(var a=!0,p=!1;r<this.expression.length;){if(t=this.expression.charAt(r),!a||"+"!==t&&"-"!==t){if(!(t>="0"&&t<="9"))break;p=!0,a=!1}else a=!1;r++}p||(r=n)}return e?(this.current=this.newToken(P,parseFloat(this.expression.substring(s,r))),this.pos=r):this.pos=n,e},B.prototype.isOperator=function(){var t=this.pos,e=this.expression.charAt(this.pos);if("+"===e||"-"===e||"*"===e||"/"===e||"%"===e||"^"===e||"?"===e||":"===e||"."===e||"#"===e)this.current=this.newToken(I,e);else if("∙"===e||"•"===e)this.current=this.newToken(I,"*");else if(">"===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(I,">="),this.pos++):this.current=this.newToken(I,">");else if("<"===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(I,"<="),this.pos++):this.current=this.newToken(I,"<");else if("|"===e){if("|"!==this.expression.charAt(this.pos+1))return!1;this.current=this.newToken(I,"||"),this.pos++}else if("="===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(I,"=="),this.pos++):this.current=this.newToken(I,e);else{if("!"!==e)return!1;"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(I,"!="),this.pos++):this.current=this.newToken(I,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(){var t,e=0,r=-1;do{e++,t=this.pos-r,r=this.expression.indexOf("\n",r+1)}while(r>=0&&r<this.pos);return{line:e,column:t}},B.prototype.parseError=function(t){var e=this.getCoordinates();throw new Error("parse error ["+e.line+":"+e.column+"]: "+t)},D.prototype.next=function(){return this.current=this.nextToken,this.nextToken=this.tokens.next()},D.prototype.tokenMatches=function(t,e){return void 0===e||(Array.isArray(e)?T(e,t.value):"function"==typeof e?e(t):t.value===e)},D.prototype.save=function(){this.savedCurrent=this.current,this.savedNextToken=this.nextToken,this.tokens.save()},D.prototype.restore=function(){this.tokens.restore(),this.current=this.savedCurrent,this.nextToken=this.savedNextToken},D.prototype.accept=function(t,e){return!(this.nextToken.type!==t||!this.tokenMatches(this.nextToken,e))&&(this.next(),!0)},D.prototype.expect=function(t,e){if(!this.accept(t,e)){var r=this.tokens.getCoordinates();throw new Error("parse error ["+r.line+":"+r.column+"]: Expected "+(e||t))}},D.prototype.parseAtom=function(t){var r=this.tokens.unaryOps;if(this.accept(U)||this.accept(I,(function(t){return t.value in r})))t.push(new y(i,this.current.value));else if(this.accept(P))t.push(new y(e,this.current.value));else if(this.accept(V))t.push(new y(e,this.current.value));else if(this.accept(j,"("))this.parseExpression(t),this.expect(j,")");else{if(!this.accept(L,"["))throw new Error("unexpected "+this.nextToken);if(this.accept(L,"]"))t.push(new y(v,0));else{var s=this.parseArrayList(t);t.push(new y(v,s))}}},D.prototype.parseExpression=function(t){var e=[];this.parseUntilEndStatement(t,e)||(this.parseVariableAssignmentExpression(e),this.parseUntilEndStatement(t,e)||this.pushExpression(t,e))},D.prototype.pushExpression=function(t,e){for(var r=0,s=e.length;r<s;r++)t.push(e[r])},D.prototype.parseUntilEndStatement=function(t,e){return!!this.accept(_)&&(!this.nextToken||this.nextToken.type===S||this.nextToken.type===j&&")"===this.nextToken.value||e.push(new y(f)),this.nextToken.type!==S&&this.parseExpression(e),t.push(new y(h,e)),!0)},D.prototype.parseArrayList=function(t){for(var e=0;!this.accept(L,"]");)for(this.parseExpression(t),++e;this.accept(R);)this.parseExpression(t),++e;return e},D.prototype.parseVariableAssignmentExpression=function(t){for(this.parseConditionalExpression(t);this.accept(I,"=");){var e=t.pop(),r=[],s=t.length-1;if(e.type!==p){if(e.type!==i&&e.type!==l)throw new Error("expected variable for assignment");this.parseVariableAssignmentExpression(r),t.push(new y(o,e.value)),t.push(new y(h,r)),t.push(w("="))}else{if(!this.tokens.isOperatorEnabled("()="))throw new Error("function definition is not permitted");for(var n=0,a=e.value+1;n<a;n++){var c=s-n;t[c].type===i&&(t[c]=new y(o,t[c].value))}this.parseVariableAssignmentExpression(r),t.push(new y(h,r)),t.push(new y(u,e.value))}}},D.prototype.parseConditionalExpression=function(t){for(this.parseOrExpression(t);this.accept(I,"?");){var e=[],r=[];this.parseConditionalExpression(e),this.expect(I,":"),this.parseConditionalExpression(r),t.push(new y(h,e)),t.push(new y(h,r)),t.push(d("?"))}},D.prototype.parseOrExpression=function(t){for(this.parseAndExpression(t);this.accept(I,"or");){var e=[];this.parseAndExpression(e),t.push(new y(h,e)),t.push(w("or"))}},D.prototype.parseAndExpression=function(t){for(this.parseComparison(t);this.accept(I,"and");){var e=[];this.parseComparison(e),t.push(new y(h,e)),t.push(w("and"))}};var G=["==","!=","<","<=",">=",">","in"];D.prototype.parseComparison=function(t){for(this.parseAddSub(t);this.accept(I,G);){var e=this.current;this.parseAddSub(t),t.push(w(e.value))}};var J=["+","-","||"];D.prototype.parseAddSub=function(t){for(this.parseTerm(t);this.accept(I,J);){var e=this.current;this.parseAddSub(t),t.push(w(e.value))}};var W=["*","/","%"];D.prototype.parseTerm=function(t){for(this.parseFactor(t);this.accept(I,W);){var e=this.current;this.parseFactor(t),t.push(w(e.value))}},D.prototype.parseFactor=function(t){var e=this.tokens.unaryOps;if(this.save(),this.accept(I,(function(t){return t.value in e}))){if("-"!==this.current.value&&"+"!==this.current.value){if(this.nextToken.type===j&&"("===this.nextToken.value)return this.restore(),void this.parseExponential(t);if(this.nextToken.type===_||this.nextToken.type===R||this.nextToken.type===S||this.nextToken.type===j&&")"===this.nextToken.value)return this.restore(),void this.parseAtom(t)}var r=this.current;this.parseFactor(t),t.push(x(r.value))}else this.parseExponential(t)},D.prototype.parseExponential=function(t){for(this.parsePostfixExpression(t);this.accept(I,"^");)this.parseFactor(t),t.push(w("^"))};var X=["!","#"];function Y(t,e){return Number(t)+Number(e)}function K(t,e){return t-e}function z(t,e){return t*e}function H(t,e){return t/e}function Q(t,e){return t%e}function Z(t,e){return Array.isArray(t)&&Array.isArray(e)?t.concat(e):""+t+e}function tt(t,e){return t===e}function et(t,e){return t!==e}function rt(t,e){return t>e}function st(t,e){return t<e}function nt(t,e){return t>=e}function it(t,e){return t<=e}function ot(t,e){return Boolean(t&&e)}function at(t,e){return Boolean(t||e)}function pt(t,e){return T(e,t)}function ut(t){return(Math.exp(t)-Math.exp(-t))/2}function ht(t){return(Math.exp(t)+Math.exp(-t))/2}function ct(t){return t===1/0?1:t===-1/0?-1:(Math.exp(t)-Math.exp(-t))/(Math.exp(t)+Math.exp(-t))}function lt(t){return t===-1/0?t:Math.log(t+Math.sqrt(t*t+1))}function ft(t){return Math.log(t+Math.sqrt(t*t-1))}function vt(t){return Math.log((1+t)/(1-t))/2}function yt(t){return Math.log(t)*Math.LOG10E}function xt(t){return-t}function wt(t){return!t}function dt(t){return t<0?Math.ceil(t):Math.floor(t)}function gt(t){return Math.random()*(t||1)}function Et(t){return bt(t+1)}function Mt(t){return t/100}D.prototype.parsePostfixExpression=function(t){for(this.parseFunctionOperator(t);this.accept(I,X);){var e=this.current;t.push(x(e.value))}},D.prototype.parseFunctionOperator=function(t){var e,r=this.tokens.functions;function s(t){return t.value in r}for(this.parseFunctionCall(t);this.accept(F,s);)e=this.current,this.parseFactor(t),t.push(new y(a,e.value))},D.prototype.parseFunctionCall=function(t){var e=this.tokens.unaryOps;if(this.accept(I,(function(t){return t.value in e}))){var r=this.current;this.parseAtom(t),t.push(x(r.value))}else for(this.parseMemberExpression(t);this.accept(j,"(");)if(this.accept(j,")"))t.push(new y(p,0));else{var s=this.parseArgumentList(t);t.push(new y(p,s))}},D.prototype.parseArgumentList=function(t){for(var e=0;!this.accept(j,")");)for(this.parseExpression(t),++e;this.accept(R);)this.parseExpression(t),++e;return e},D.prototype.parseMemberExpression=function(t){for(this.parseAtom(t);this.accept(I,".")||this.accept(L,"[");){var e=this.current;if("."===e.value){if(!this.allowMemberAccess)throw new Error('unexpected ".", member access is not permitted');this.expect(U),t.push(new y(l,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(L,"]"),t.push(w("["))}}};var mt=4.7421875,At=[.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 bt(t){var e,r;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 s=t-2,n=t-1;s>1;)n*=s,s--;return 0===n&&(n=1),n}if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*bt(1-t));if(t>=171.35)return 1/0;if(t>85){var i=t*t,o=i*t,a=o*t,p=a*t;return Math.sqrt(2*Math.PI/t)*Math.pow(t/Math.E,t)*(1+1/(12*t)+1/(288*i)-139/(51840*o)-571/(2488320*a)+163879/(209018880*p)+5246819/(75246796800*p*t))}--t,r=At[0];for(var u=1;u<At.length;++u)r+=At[u]/(t+u);return e=t+mt+.5,Math.sqrt(2*Math.PI)*Math.pow(e,t+.5)*Math.exp(-e)*r}function kt(t){return Array.isArray(t)?t.length:String(t).length}function Ot(){for(var t=0,e=0,r=0;r<arguments.length;r++){var s,n=Math.abs(arguments[r]);e<n?(t=t*(s=e/n)*s+1,e=n):t+=n>0?(s=n/e)*s:n}return e===1/0?1/0:e*Math.sqrt(t)}function Tt(t,e,r){return t?e:r}function Ct(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 Nt(t,e,r){return r&&(r[t]=e),e}function St(t,e){return t[0|e]}function It(t){return 1===arguments.length&&Array.isArray(t)?Math.max.apply(Math,t):Math.max.apply(Math,arguments)}function Ft(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,r){return t(e,r)}))}function Vt(t,e,r){if("function"!=typeof t)throw new Error("First argument to fold is not a function");if(!Array.isArray(r))throw new Error("Second argument to fold is not an array");return r.reduce((function(e,r,s){return t(e,r,s)}),e)}function jt(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,r){return t(e,r)}))}function Lt(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 Rt(t,e){if(!Array.isArray(e))throw new Error("Second argument to join is not an array");return e.join(t)}function Ut(t){return(t>0)-(t<0)||+t}var _t=1/3;function qt(t){return t<0?-Math.pow(-t,_t):Math.pow(t,_t)}function Bt(t){return Math.exp(t)-1}function $t(t){return Math.log(1+t)}function Dt(t){return Math.log(t)/Math.LN2}function Gt(t){if(!Array.isArray(t))throw new Error("Sum argument is not an array");return t.reduce((function(t,e){return t+Number(e)}),0)}function Jt(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||ut,cosh:Math.cosh||ht,tanh:Math.tanh||ct,asinh:Math.asinh||lt,acosh:Math.acosh||ft,atanh:Math.atanh||vt,sqrt:Math.sqrt,cbrt:Math.cbrt||qt,log:Math.log,log2:Math.log2||Dt,ln:Math.log,lg:Math.log10||yt,log10:Math.log10||yt,expm1:Math.expm1||Bt,log1p:Math.log1p||$t,abs:Math.abs,ceil:Math.ceil,floor:Math.floor,round:Math.round,trunc:Math.trunc||dt,"-":xt,"+":Number,exp:Math.exp,not:wt,length:kt,"!":Et,"#":Mt,sign:Math.sign||Ut},this.binaryOps={"+":Y,"-":K,"*":z,"/":H,"%":Q,"^":Math.pow,"||":Z,"==":tt,"!=":et,">":rt,"<":st,">=":nt,"<=":it,and:ot,or:at,in:pt,"=":Nt,"[":St},this.ternaryOps={"?":Tt},this.functions={random:gt,fac:Et,percent:Mt,min:Ft,max:It,hypot:Math.hypot||Ot,pyt:Math.hypot||Ot,pow:Math.pow,atan2:Math.atan2,if:Tt,gamma:bt,roundTo:Ct,map:Pt,fold:Vt,filter:jt,indexOf:Lt,join:Rt,sum:Gt},this.consts={E:Math.E,PI:Math.PI,true:!0,false:!1}}Jt.prototype.parse=function(t){var e=[],r=new D(this,new B(this,t),{allowMemberAccess:this.options.allowMemberAccess});return r.parseExpression(e),r.expect(S,"EOF"),new N(e,this)},Jt.prototype.evaluate=function(t,e){return this.parse(t).evaluate(e)};var Wt=new Jt;Jt.parse=function(t){return Wt.parse(t)},Jt.evaluate=function(t,e){return Wt.parse(t).evaluate(e)};var Xt={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"remainder","^":"power","!":"factorial","#":"percent","<":"comparison",">":"comparison","<=":"comparison",">=":"comparison","==":"comparison","!=":"comparison","||":"concatenate",and:"logical",or:"logical",not:"logical","?":"conditional",":":"conditional","=":"assignment","[":"array","()=":"fndef"};Jt.prototype.isOperatorEnabled=function(t){var e=function(t){return Object.prototype.hasOwnProperty.call(Xt,t)?Xt[t]:t}(t),r=this.options.operators||{};return!(e in r)||!!r[e]}; | ||
!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 e="INUMBER",r="IOP1",s="IOP2",n="IOP3",i="IVAR",o="IVARNAME",a="IFUNCOP",p="IFUNCALL",h="IFUNDEF",u="IEXPR",c="IEXPREVAL",f="IMEMBER",l="IENDSTATEMENT",v="IARRAY";function y(t,e){this.type=t,this.value=null!=e?e:0}function x(t){return new y(r,t)}function w(t){return new y(s,t)}function d(t){return new y(n,t)}function g(t,a,p,h,c){for(var l,x,w,d,E=[],M=[],m=0;m<t.length;m++){var A=t[m],b=A.type;if(b===e||b===o)Array.isArray(A.value)?E.push.apply(E,g(A.value.map((function(t){return new y(e,t)})).concat(new y(v,A.value.length)),a,p,h,c)):E.push(A);else if(b===i&&Object.prototype.hasOwnProperty.call(c,A.value))A=new y(e,c[A.value]),E.push(A);else if(b===s&&E.length>1)x=E.pop(),l=E.pop(),d=p[A.value],A=new y(e,d(l.value,x.value)),E.push(A);else if(b===n&&E.length>2)w=E.pop(),x=E.pop(),l=E.pop(),"?"===A.value?E.push(l.value?x.value:w.value):(d=h[A.value],A=new y(e,d(l.value,x.value,w.value)),E.push(A));else if(b===r&&E.length>0)l=E.pop(),d=a[A.value],A=new y(e,d(l.value)),E.push(A);else if(b===u){for(;E.length>0;)M.push(E.shift());M.push(new y(u,g(A.value,a,p,h,c)))}else if(b===f&&E.length>0)l=E.pop(),E.push(new y(e,l.value[A.value]));else{for(;E.length>0;)M.push(E.shift());M.push(A)}}for(;E.length>0;)M.push(E.shift());return M}function E(t,e,o){for(var a=[],p=0;p<t.length;p++){var h=t[p],c=h.type;if(c===i&&h.value===e)for(var f=0;f<o.tokens.length;f++){var l,v=o.tokens[f];l=v.type===r?x(v.value):v.type===s?w(v.value):v.type===n?d(v.value):new y(v.type,v.value),a.push(l)}else c===u?a.push(new y(u,E(h.value,e,o))):a.push(h)}return a}function M(t,y,x){var w,d,g,E,k,O,T,C,N,S=(w=[],{get length(){return w.length},pop:function(){return w.pop()},popValue:function(){return w.pop().value},push:function(t,e){w.push({token:t,value:e})},first:function(){return w[0]&&w[0].value}});if(A(t))return b(t,x);for(var I=t.length,F=0;F<I;F++){var P=t[F],V=P.type,j=P.value;if(V===e||V===o)S.push(V,j);else if(V===s)O=S.pop(),k=S.pop(),g=O.value,d=k.value,"and"===j?S.push(j,!!d&&!!M(g,y,x)):"or"===j?S.push(j,!!d||!!M(g,y,x)):"="===j?(T=y.binaryOps[j],S.push(j,T(d,M(g,y,x),x))):"+"===j&&"#"===O.token&&O.token!==k.token?(T=y.binaryOps[j],d=b(d,x),g=M([{type:e,value:d},{type:e,value:b(g,x)},{type:s,value:"*"}],y,x),S.push(j,T(d,g))):(T=y.binaryOps[j],S.push(j,T(b(d,x),b(g,x))));else if(V===n)E=S.popValue(),g=S.popValue(),d=S.popValue(),"?"===j?S.push(j,M(d?g:E,y,x)):(T=y.ternaryOps[j],S.push(j,T(b(d,x),b(g,x),b(E,x))));else if(V===i){if(/^__proto__|prototype|constructor$/.test(j))throw new Error("prototype access detected");if(j in y.functions)S.push(j,y.functions[j]);else if(j in y.unaryOps&&y.parser.isOperatorEnabled(j))S.push(j,y.unaryOps[j]);else{var L=x[j];if(void 0===L)throw new Error("undefined variable: "+j);S.push(j,L)}}else if(V===r)d=(k=S.pop()).value,T=y.unaryOps[j],"-"===j&&"#"===k.token&&(j="#"),S.push(j,T(b(d,x)));else if(V===a){if(g=S.popValue(),C=[d=S.popValue(),g],!(T=y.functions[j]).apply||!T.call)throw new Error(T+" is not a function");S.push(j,T.apply(void 0,C))}else if(V===p){for(N=j,C=[];N-- >0;)C.unshift(b(S.popValue(),x));if(!(T=S.popValue()).apply||!T.call)throw new Error(T+" is not a function");S.push(j,T.apply(void 0,C))}else if(V===h)S.push(V,function(){for(var t=S.popValue(),e=[],r=j;r-- >0;)e.unshift(S.popValue());var s=S.popValue(),n=function(){for(var r=Object.assign({},x),s=0,n=e.length;s<n;s++)r[e[s]]=arguments[s];return M(t,y,r)};return Object.defineProperty(n,"name",{value:s,writable:!1}),x[s]=n,n}());else if(V===u)S.push(V,m(P,y));else if(V===c)S.push(V,P);else if(V===f)d=S.popValue(),S.push(j,d[j]);else if(V===l)S.pop();else{if(V!==v)throw new Error("invalid Expression");for(N=j,C=[];N-- >0;)C.unshift(S.popValue());S.push(V,C)}}if(S.length>1)throw new Error("invalid Expression (parity)");return 0===S.first()?0:b(S.first(),x)}function m(t,e,r){return A(t)?t:{type:c,value:function(r){return M(t.value,e,r)}}}function A(t){return t&&t.type===c}function b(t,e){return A(t)?t.value(e):t}function k(t,a){for(var c,y,x,w,d,g,E=[],M=0;M<t.length;M++){var m=t[M],A=m.type;if(A===e)"number"==typeof m.value&&m.value<0?E.push("("+m.value+")"):Array.isArray(m.value)?E.push("["+m.value.map(O).join(", ")+"]"):E.push(O(m.value));else if(A===s)y=E.pop(),c=E.pop(),w=m.value,a?"^"===w?E.push("Math.pow("+c+", "+y+")"):"and"===w?E.push("(!!"+c+" && !!"+y+")"):"or"===w?E.push("(!!"+c+" || !!"+y+")"):"||"===w?E.push("(function(a,b){ return Array.isArray(a) && Array.isArray(b) ? a.concat(b) : String(a) + String(b); }(("+c+"),("+y+")))"):"=="===w?E.push("("+c+" === "+y+")"):"!="===w?E.push("("+c+" !== "+y+")"):"["===w?E.push(c+"[("+y+") | 0]"):E.push("("+c+" "+w+" "+y+")"):"["===w?E.push(c+"["+y+"]"):E.push("("+c+" "+w+" "+y+")");else if(A===n){if(x=E.pop(),y=E.pop(),c=E.pop(),"?"!==(w=m.value))throw new Error("invalid Expression");E.push("("+c+" ? "+y+" : "+x+")")}else if(A===i||A===o)E.push(m.value);else if(A===r)c=E.pop(),"-"===(w=m.value)||"+"===w?E.push("("+w+c+")"):a?"not"===w?E.push("(!"+c+")"):"!"===w?E.push("fac("+c+")"):"#"===w?E.push("percent("+c+")"):E.push(w+"("+c+")"):"!"===w?E.push("("+c+"!)"):"#"===w?E.push("("+c+"#)"):E.push("("+w+" "+c+")");else if(A===p){for(g=m.value,d=[];g-- >0;)d.unshift(E.pop());w=E.pop(),E.push(w+"("+d.join(", ")+")")}else if(A===h){for(y=E.pop(),g=m.value,d=[];g-- >0;)d.unshift(E.pop());c=E.pop(),a?E.push("("+c+" = function("+d.join(", ")+") { return "+y+" })"):E.push("("+c+"("+d.join(", ")+") = "+y+")")}else if(A===f)c=E.pop(),E.push(c+"."+m.value);else if(A===v){for(g=m.value,d=[];g-- >0;)d.unshift(E.pop());E.push("["+d.join(", ")+"]")}else if(A===u)E.push("("+k(m.value,a)+")");else if(A!==l)throw new Error("invalid Expression")}return E.length>1&&(E=a?[E.join(",")]:[E.join(";")]),String(E[0])}function O(t){return"string"==typeof t?JSON.stringify(t).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029"):t}function T(t,e){for(var r=0;r<t.length;r++)if(t[r]===e)return!0;return!1}function C(t,e,r){for(var s=!!(r=r||{}).withMembers,n=null,a=0;a<t.length;a++){var p=t[a];p.type===i||p.type===o?s||T(e,p.value)?null!==n?(T(e,n)||e.push(n),n=p.value):n=p.value:e.push(p.value):p.type===f&&s&&null!==n?n+="."+p.value:p.type===u?C(p.value,e,r):null!==n&&(T(e,n)||e.push(n),n=null)}null===n||T(e,n)||e.push(n)}function N(t,e){this.tokens=t,this.parser=e,this.unaryOps=e.unaryOps,this.binaryOps=e.binaryOps,this.ternaryOps=e.ternaryOps,this.functions=e.functions}y.prototype.toString=function(){switch(this.type){case e:case r:case s:case n:case i:case o:case l:case a:return this.value;case p:return"CALL "+this.value;case h:return"DEF "+this.value;case v:return"ARRAY "+this.value;case f:return"."+this.value;default:return"Invalid Instruction"}},N.prototype.simplify=function(t){return t=t||{},new N(g(this.tokens,this.unaryOps,this.binaryOps,this.ternaryOps,t),this.parser)},N.prototype.substitute=function(t,e){return e instanceof N||(e=this.parser.parse(String(e))),new N(E(this.tokens,t,e),this.parser)},N.prototype.evaluate=function(t){return t=t||{},M(this.tokens,this,t)},N.prototype.toString=function(){return k(this.tokens,!1)},N.prototype.symbols=function(t){t=t||{};var e=[];return C(this.tokens,e,t),e},N.prototype.variables=function(t){t=t||{};var e=[];C(this.tokens,e,t);var r=this.functions;return e.filter((function(t){return!(t in r)}))},N.prototype.toJSFunction=function(t,e){var r=this,s=new Function(t,"with(this.functions) with (this.ternaryOps) with (this.binaryOps) with (this.unaryOps) { return "+k(this.simplify(e).tokens,!0)+"; }");return function(){return s.apply(r,arguments)}};var S="TEOF",I="TOP",F="TFUNCOP",P="TNUMBER",V="TSTRING",j="TPAREN",L="TBRACKET",R="TCOMMA",U="TNAME",_="TSEMICOLON";function q(t,e,r){this.type=t,this.value=e,this.index=r}function B(t,e){this.pos=0,this.current=null,this.unaryOps=t.unaryOps,this.binaryOps=t.binaryOps,this.ternaryOps=t.ternaryOps,this.functions=t.functions,this.consts=t.consts,this.expression=e,this.savedPosition=0,this.savedCurrent=null,this.options=t.options,this.parser=t}q.prototype.toString=function(){return this.type+": "+this.value},B.prototype.newToken=function(t,e,r){return new q(t,e,null!=r?r:this.pos)},B.prototype.save=function(){this.savedPosition=this.pos,this.savedCurrent=this.current},B.prototype.restore=function(){this.pos=this.savedPosition,this.current=this.savedCurrent},B.prototype.next=function(){return this.pos>=this.expression.length?this.newToken(S,"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.isFuncOp()||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);s>=0&&this.pos<this.expression.length;){if(this.pos=s+1,"\\"!==this.expression.charAt(s-1)){var n=this.expression.substring(e+1,s);this.current=this.newToken(V,this.unescape(n),e),t=!0;break}s=this.expression.indexOf(r,s+1)}return t},B.prototype.isParen=function(){var t=this.expression.charAt(this.pos);return("("===t||")"===t)&&(this.current=this.newToken(j,t),this.pos++,!0)},B.prototype.isBracket=function(){var t=this.expression.charAt(this.pos);return!("["!==t&&"]"!==t||!this.isOperatorEnabled("["))&&(this.current=this.newToken(L,t),this.pos++,!0)},B.prototype.isComma=function(){return","===this.expression.charAt(this.pos)&&(this.current=this.newToken(R,","),this.pos++,!0)},B.prototype.isSemicolon=function(){return";"===this.expression.charAt(this.pos)&&(this.current=this.newToken(_,";"),this.pos++,!0)},B.prototype.isConst=function(){for(var t=this.pos,e=t;e<this.expression.length;e++){var r=this.expression.charAt(e);if(r.toUpperCase()===r.toLowerCase()&&(e===this.pos||"_"!==r&&"."!==r&&(r<"0"||r>"9")))break}if(e>t){var s=this.expression.substring(t,e);if(s in this.consts)return this.current=this.newToken(P,this.consts[s]),this.pos+=s.length,!0}return!1},B.prototype.isNamedOp=function(){for(var t=this.pos,e=t;e<this.expression.length;e++){var r=this.expression.charAt(e);if(r.toUpperCase()===r.toLowerCase()&&(e===this.pos||"_"!==r&&(r<"0"||r>"9")))break}if(e>t){var s=this.expression.substring(t,e);if(this.isOperatorEnabled(s)&&(s in this.binaryOps||s in this.unaryOps||s in this.ternaryOps))return this.current=this.newToken(I,s),this.pos+=s.length,!0}return!1},B.prototype.isFuncOp=function(){var t,e=this.expression.charAt(this.pos),r=this.pos+1,s=r;if("@"===e){for(;s<this.expression.length&&((e=this.expression.charAt(s)).toUpperCase()!==e.toLowerCase()||!(s===r||"_"!==e&&(e<"0"||e>"9")));s++);if(s>r&&(t=this.expression.substring(r,s))in this.functions)return this.current=this.newToken(F,t),this.pos=r+t.length,!0}return!1},B.prototype.isName=function(){for(var t=this.pos,e=t,r=!1;e<this.expression.length;e++){var s=this.expression.charAt(e);if(s.toUpperCase()===s.toLowerCase()){if(e===this.pos&&("$"===s||"_"===s)){"_"===s&&(r=!0);continue}if(e===this.pos||!r||"_"!==s&&(s<"0"||s>"9"))break}else r=!0}if(r){var n=this.expression.substring(t,e);return this.current=this.newToken(U,n),this.pos+=n.length,!0}return!1},B.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 $=/^[0-9a-f]{4}$/i;function D(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);e>=0;){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);$.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<this.expression.length;){var i=this.expression.charAt(r);if(!e.test(i))break;r++,s=!0}return s&&(this.current=this.newToken(P,parseInt(this.expression.substring(n,r),t)),this.pos=r),s},B.prototype.isNumber=function(){for(var t,e=!1,r=this.pos,s=r,n=r,i=!1,o=!1;r<this.expression.length&&((t=this.expression.charAt(r))>="0"&&t<="9"||!i&&"."===t);)"."===t?i=!0:o=!0,r++,e=o;if(e&&(n=r),"e"===t||"E"===t){r++;for(var a=!0,p=!1;r<this.expression.length;){if(t=this.expression.charAt(r),!a||"+"!==t&&"-"!==t){if(!(t>="0"&&t<="9"))break;p=!0,a=!1}else a=!1;r++}p||(r=n)}return e?(this.current=this.newToken(P,parseFloat(this.expression.substring(s,r))),this.pos=r):this.pos=n,e},B.prototype.isOperator=function(){var t=this.pos,e=this.expression.charAt(this.pos);if("+"===e||"-"===e||"*"===e||"/"===e||"%"===e||"^"===e||"?"===e||":"===e||"."===e||"#"===e)this.current=this.newToken(I,e);else if("∙"===e||"•"===e)this.current=this.newToken(I,"*");else if(">"===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(I,">="),this.pos++):this.current=this.newToken(I,">");else if("<"===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(I,"<="),this.pos++):this.current=this.newToken(I,"<");else if("|"===e){if("|"!==this.expression.charAt(this.pos+1))return!1;this.current=this.newToken(I,"||"),this.pos++}else if("="===e)"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(I,"=="),this.pos++):this.current=this.newToken(I,e);else{if("!"!==e)return!1;"="===this.expression.charAt(this.pos+1)?(this.current=this.newToken(I,"!="),this.pos++):this.current=this.newToken(I,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(){var t,e=0,r=-1;do{e++,t=this.pos-r,r=this.expression.indexOf("\n",r+1)}while(r>=0&&r<this.pos);return{line:e,column:t}},B.prototype.parseError=function(t){var e=this.getCoordinates();throw new Error("parse error ["+e.line+":"+e.column+"]: "+t)},D.prototype.next=function(){return this.current=this.nextToken,this.nextToken=this.tokens.next()},D.prototype.tokenMatches=function(t,e){return void 0===e||(Array.isArray(e)?T(e,t.value):"function"==typeof e?e(t):t.value===e)},D.prototype.save=function(){this.savedCurrent=this.current,this.savedNextToken=this.nextToken,this.tokens.save()},D.prototype.restore=function(){this.tokens.restore(),this.current=this.savedCurrent,this.nextToken=this.savedNextToken},D.prototype.accept=function(t,e){return!(this.nextToken.type!==t||!this.tokenMatches(this.nextToken,e))&&(this.next(),!0)},D.prototype.expect=function(t,e){if(!this.accept(t,e)){var r=this.tokens.getCoordinates();throw new Error("parse error ["+r.line+":"+r.column+"]: Expected "+(e||t))}},D.prototype.parseAtom=function(t){var r=this.tokens.unaryOps;if(this.accept(U)||this.accept(I,(function(t){return t.value in r})))t.push(new y(i,this.current.value));else if(this.accept(P))t.push(new y(e,this.current.value));else if(this.accept(V))t.push(new y(e,this.current.value));else if(this.accept(j,"("))this.parseExpression(t),this.expect(j,")");else{if(!this.accept(L,"["))throw new Error("unexpected "+this.nextToken);if(this.accept(L,"]"))t.push(new y(v,0));else{var s=this.parseArrayList(t);t.push(new y(v,s))}}},D.prototype.parseExpression=function(t){var e=[];this.parseUntilEndStatement(t,e)||(this.parseVariableAssignmentExpression(e),this.parseUntilEndStatement(t,e)||this.pushExpression(t,e))},D.prototype.pushExpression=function(t,e){for(var r=0,s=e.length;r<s;r++)t.push(e[r])},D.prototype.parseUntilEndStatement=function(t,e){return!!this.accept(_)&&(!this.nextToken||this.nextToken.type===S||this.nextToken.type===j&&")"===this.nextToken.value||e.push(new y(l)),this.nextToken.type!==S&&this.parseExpression(e),t.push(new y(u,e)),!0)},D.prototype.parseArrayList=function(t){for(var e=0;!this.accept(L,"]");)for(this.parseExpression(t),++e;this.accept(R);)this.parseExpression(t),++e;return e},D.prototype.parseVariableAssignmentExpression=function(t){for(this.parseConditionalExpression(t);this.accept(I,"=");){var e=t.pop(),r=[],s=t.length-1;if(e.type!==p){if(e.type!==i&&e.type!==f)throw new Error("expected variable for assignment");this.parseVariableAssignmentExpression(r),t.push(new y(o,e.value)),t.push(new y(u,r)),t.push(w("="))}else{if(!this.tokens.isOperatorEnabled("()="))throw new Error("function definition is not permitted");for(var n=0,a=e.value+1;n<a;n++){var c=s-n;t[c].type===i&&(t[c]=new y(o,t[c].value))}this.parseVariableAssignmentExpression(r),t.push(new y(u,r)),t.push(new y(h,e.value))}}},D.prototype.parseConditionalExpression=function(t){for(this.parseOrExpression(t);this.accept(I,"?");){var e=[],r=[];this.parseConditionalExpression(e),this.expect(I,":"),this.parseConditionalExpression(r),t.push(new y(u,e)),t.push(new y(u,r)),t.push(d("?"))}},D.prototype.parseOrExpression=function(t){for(this.parseAndExpression(t);this.accept(I,"or");){var e=[];this.parseAndExpression(e),t.push(new y(u,e)),t.push(w("or"))}},D.prototype.parseAndExpression=function(t){for(this.parseComparison(t);this.accept(I,"and");){var e=[];this.parseComparison(e),t.push(new y(u,e)),t.push(w("and"))}};var G=["==","!=","<","<=",">=",">","in"];D.prototype.parseComparison=function(t){for(this.parseConcat(t);this.accept(I,G);){var e=this.current;this.parseConcat(t),t.push(w(e.value))}},D.prototype.parseConcat=function(t){for(this.parseAddSub(t);this.accept(I,"||");)this.parseAddSub(t),t.push(w("||"))};var J=["+","-"];D.prototype.parseAddSub=function(t){for(this.parseTerm(t),this.save();this.accept(I,J);){var e=this.current;"-"===e.value&&(e=Object.assign({},e,{value:"+"}),this.restore()),this.parseAddSub(t),t.push(w(e.value))}};var W=["*","/","%"];D.prototype.parseTerm=function(t){for(this.parseFactor(t);this.accept(I,W);){var e=this.current;this.parseFactor(t),t.push(w(e.value))}},D.prototype.parseFactor=function(t){var e=this.tokens.unaryOps;if(this.save(),this.accept(I,(function(t){return t.value in e}))){if("-"!==this.current.value&&"+"!==this.current.value){if(this.nextToken.type===j&&"("===this.nextToken.value)return this.restore(),void this.parseExponential(t);if(this.nextToken.type===_||this.nextToken.type===R||this.nextToken.type===S||this.nextToken.type===j&&")"===this.nextToken.value)return this.restore(),void this.parseAtom(t)}var r=this.current;this.parseFactor(t),t.push(x(r.value))}else this.parseExponential(t)},D.prototype.parseExponential=function(t){for(this.parsePostfixExpression(t);this.accept(I,"^");)this.parseFactor(t),t.push(w("^"))};var X=["!","#"];function Y(t,e){return Number(t)+Number(e)}function K(t,e){return t-e}function z(t,e){return t*e}function H(t,e){return t/e}function Q(t,e){return t%e}function Z(t,e){return Array.isArray(t)&&Array.isArray(e)?t.concat(e):""+t+e}function tt(t,e){return t===e}function et(t,e){return t!==e}function rt(t,e){return t>e}function st(t,e){return t<e}function nt(t,e){return t>=e}function it(t,e){return t<=e}function ot(t,e){return Boolean(t&&e)}function at(t,e){return Boolean(t||e)}function pt(t,e){return T(e,t)}function ht(t){return(Math.exp(t)-Math.exp(-t))/2}function ut(t){return(Math.exp(t)+Math.exp(-t))/2}function ct(t){return t===1/0?1:t===-1/0?-1:(Math.exp(t)-Math.exp(-t))/(Math.exp(t)+Math.exp(-t))}function ft(t){return t===-1/0?t:Math.log(t+Math.sqrt(t*t+1))}function lt(t){return Math.log(t+Math.sqrt(t*t-1))}function vt(t){return Math.log((1+t)/(1-t))/2}function yt(t){return Math.log(t)*Math.LOG10E}function xt(t){return-t}function wt(t){return!t}function dt(t){return t<0?Math.ceil(t):Math.floor(t)}function gt(t){return Math.random()*(t||1)}function Et(t){return bt(t+1)}function Mt(t){return t/100}D.prototype.parsePostfixExpression=function(t){for(this.parseFunctionOperator(t);this.accept(I,X);){var e=this.current;t.push(x(e.value))}},D.prototype.parseFunctionOperator=function(t){var e,r=this.tokens.functions;function s(t){return t.value in r}for(this.parseFunctionCall(t);this.accept(F,s);)e=this.current,this.parseFactor(t),t.push(new y(a,e.value))},D.prototype.parseFunctionCall=function(t){var e=this.tokens.unaryOps;if(this.accept(I,(function(t){return t.value in e}))){var r=this.current;this.parseAtom(t),t.push(x(r.value))}else for(this.parseMemberExpression(t);this.accept(j,"(");)if(this.accept(j,")"))t.push(new y(p,0));else{var s=this.parseArgumentList(t);t.push(new y(p,s))}},D.prototype.parseArgumentList=function(t){for(var e=0;!this.accept(j,")");)for(this.parseExpression(t),++e;this.accept(R);)this.parseExpression(t),++e;return e},D.prototype.parseMemberExpression=function(t){for(this.parseAtom(t);this.accept(I,".")||this.accept(L,"[");){var e=this.current;if("."===e.value){if(!this.allowMemberAccess)throw new Error('unexpected ".", member access is not permitted');this.expect(U),t.push(new y(f,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(L,"]"),t.push(w("["))}}};var mt=4.7421875,At=[.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 bt(t){var e,r;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 s=t-2,n=t-1;s>1;)n*=s,s--;return 0===n&&(n=1),n}if(t<.5)return Math.PI/(Math.sin(Math.PI*t)*bt(1-t));if(t>=171.35)return 1/0;if(t>85){var i=t*t,o=i*t,a=o*t,p=a*t;return Math.sqrt(2*Math.PI/t)*Math.pow(t/Math.E,t)*(1+1/(12*t)+1/(288*i)-139/(51840*o)-571/(2488320*a)+163879/(209018880*p)+5246819/(75246796800*p*t))}--t,r=At[0];for(var h=1;h<At.length;++h)r+=At[h]/(t+h);return e=t+mt+.5,Math.sqrt(2*Math.PI)*Math.pow(e,t+.5)*Math.exp(-e)*r}function kt(t){return Array.isArray(t)?t.length:String(t).length}function Ot(){for(var t=0,e=0,r=0;r<arguments.length;r++){var s,n=Math.abs(arguments[r]);e<n?(t=t*(s=e/n)*s+1,e=n):t+=n>0?(s=n/e)*s:n}return e===1/0?1/0:e*Math.sqrt(t)}function Tt(t,e,r){return t?e:r}function Ct(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 Nt(t,e,r){return r&&(r[t]=e),e}function St(t,e){return t[0|e]}function It(t){return 1===arguments.length&&Array.isArray(t)?Math.max.apply(Math,t):Math.max.apply(Math,arguments)}function Ft(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,r){return t(e,r)}))}function Vt(t,e,r){if("function"!=typeof t)throw new Error("First argument to fold is not a function");if(!Array.isArray(r))throw new Error("Second argument to fold is not an array");return r.reduce((function(e,r,s){return t(e,r,s)}),e)}function jt(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,r){return t(e,r)}))}function Lt(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 Rt(t,e){if(!Array.isArray(e))throw new Error("Second argument to join is not an array");return e.join(t)}function Ut(t){return(t>0)-(t<0)||+t}var _t=1/3;function qt(t){return t<0?-Math.pow(-t,_t):Math.pow(t,_t)}function Bt(t){return Math.exp(t)-1}function $t(t){return Math.log(1+t)}function Dt(t){return Math.log(t)/Math.LN2}function Gt(t){if(!Array.isArray(t))throw new Error("Sum argument is not an array");return t.reduce((function(t,e){return t+Number(e)}),0)}function Jt(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||ht,cosh:Math.cosh||ut,tanh:Math.tanh||ct,asinh:Math.asinh||ft,acosh:Math.acosh||lt,atanh:Math.atanh||vt,sqrt:Math.sqrt,cbrt:Math.cbrt||qt,log:Math.log,log2:Math.log2||Dt,ln:Math.log,lg:Math.log10||yt,log10:Math.log10||yt,expm1:Math.expm1||Bt,log1p:Math.log1p||$t,abs:Math.abs,ceil:Math.ceil,floor:Math.floor,round:Math.round,trunc:Math.trunc||dt,"-":xt,"+":Number,exp:Math.exp,not:wt,length:kt,"!":Et,"#":Mt,sign:Math.sign||Ut},this.binaryOps={"+":Y,"-":K,"*":z,"/":H,"%":Q,"^":Math.pow,"||":Z,"==":tt,"!=":et,">":rt,"<":st,">=":nt,"<=":it,and:ot,or:at,in:pt,"=":Nt,"[":St},this.ternaryOps={"?":Tt},this.functions={random:gt,fac:Et,percent:Mt,min:Ft,max:It,hypot:Math.hypot||Ot,pyt:Math.hypot||Ot,pow:Math.pow,atan2:Math.atan2,if:Tt,gamma:bt,roundTo:Ct,map:Pt,fold:Vt,filter:jt,indexOf:Lt,join:Rt,sum:Gt},this.consts={E:Math.E,PI:Math.PI,true:!0,false:!1}}Jt.prototype.parse=function(t){var e=[],r=new D(this,new B(this,t),{allowMemberAccess:this.options.allowMemberAccess});return r.parseExpression(e),r.expect(S,"EOF"),new N(e,this)},Jt.prototype.evaluate=function(t,e){return this.parse(t).evaluate(e)};var Wt=new Jt;Jt.parse=function(t){return Wt.parse(t)},Jt.evaluate=function(t,e){return Wt.parse(t).evaluate(e)};var Xt={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"remainder","^":"power","!":"factorial","#":"percent","<":"comparison",">":"comparison","<=":"comparison",">=":"comparison","==":"comparison","!=":"comparison","||":"concatenate",and:"logical",or:"logical",not:"logical","?":"conditional",":":"conditional","=":"assignment","[":"array","()=":"fndef"};Jt.prototype.isOperatorEnabled=function(t){var e=function(t){return Object.prototype.hasOwnProperty.call(Xt,t)?Xt[t]:t}(t),r=this.options.operators||{};return!(e in r)||!!r[e]}; | ||
/*! | ||
@@ -3,0 +3,0 @@ Based on ndef.parser, by Raphael Graf(r@undefined.ch) |
{ | ||
"name": "@oat-sa/expr-eval", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "Mathematical expression evaluator", | ||
@@ -5,0 +5,0 @@ "main": "dist/bundle.js", |
@@ -231,3 +231,4 @@ JavaScript Expression Evaluator | ||
\*, /, % | Left | Multiplication, division, remainder | ||
+, -, \|\| | Left | Addition, subtraction, array/list concatenation | ||
\|\| | Left | array/list concatenation | ||
+, - | Left (Right) | Addition, subtraction (associativity: `1+2+3` => `1+(2+3)`, `1-2-3` => `1+((-2)+(-3))`) | ||
==, !=, >=, <=, >, <, in | Left | Equals, not equals, etc. "in" means "is the left operand included in the right array operand?" | ||
@@ -265,2 +266,3 @@ and | Left | Logical AND | ||
x! | Factorial (x * (x-1) * (x-2) * … * 2 * 1). gamma(x + 1) for non-integers. | ||
x# | Percentage (`10% = 0.1`, `50 + 10% = 55`, `50 * 10% = 5`) | ||
abs x | Absolute value (magnitude) of x | ||
@@ -306,2 +308,3 @@ acos x | Arc cosine of x (in radians) | ||
fac(n) | n! (factorial of n: "n * (n-1) * (n-2) * … * 2 * 1") Deprecated. Use the ! operator instead. | ||
percent(n) | Turns a percentage into a value (`percent(10) = 0.1`). | ||
min(a,b,…) | Get the smallest (minimum) number in the list. | ||
@@ -337,2 +340,12 @@ max(a,b,…) | Get the largest (maximum) number in the list. | ||
``` | ||
#### Functions as binary operator | ||
You can turn any function that accepts 2 operands into a binary operator. To do so, you need to prefix the function name by `@` and do not add the parenthesis. The precedence is higher than the normal function call. | ||
Examples: | ||
// equivalent to nthrt(4, 254) | ||
4 @nthrt 254 | ||
#### Custom JavaScript functions | ||
@@ -339,0 +352,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
157948
3753
395