Socket
Socket
Sign inDemoInstall

@oat-sa/expr-eval

Package Overview
Dependencies
Maintainers
18
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oat-sa/expr-eval - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

158

dist/bundle.js

@@ -79,3 +79,3 @@ (function (global, factory) {

}
} else if (type === IVAR && values.hasOwnProperty(item.value)) {
} else if (type === IVAR && Object.prototype.hasOwnProperty.call(values, item.value)) {
item = new Instruction(INUMBER, values[item.value]);

@@ -113,9 +113,3 @@ nstack.push(item);

nstack.push(new Instruction(INUMBER, n1.value[item.value]));
} /* else if (type === IARRAY && nstack.length >= item.value) {
var length = item.value;
while (length-- > 0) {
newexpression.push(nstack.pop());
}
newexpression.push(new Instruction(IARRAY, item.value));
} */ else {
} else {
while (nstack.length > 0) {

@@ -163,3 +157,3 @@ newexpression.push(nstack.shift());

function evaluate(tokens, expr, values) {
var nstack = [];
var nstack = stackFactory();
var n1, n2, n3;

@@ -178,26 +172,37 @@ var f, args, argCount;

if (type === INUMBER || type === IVARNAME) {
nstack.push(item.value);
nstack.push(item.value, item.value);
} else if (type === IOP2) {
n2 = nstack.pop();
n1 = nstack.pop();
var right = nstack.pop();
var left = nstack.pop();
n2 = right.value;
n1 = left.value;
if (item.value === 'and') {
nstack.push(n1 ? !!evaluate(n2, expr, values) : false);
nstack.push(item.value, n1 ? !!evaluate(n2, expr, values) : false);
} else if (item.value === 'or') {
nstack.push(n1 ? true : !!evaluate(n2, expr, values));
nstack.push(item.value, n1 ? true : !!evaluate(n2, expr, values));
} else if (item.value === '=') {
f = expr.binaryOps[item.value];
nstack.push(f(n1, evaluate(n2, expr, values), values));
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];
n1 = resolveExpression(n1, values);
n2 = evaluate([
{ type: INUMBER, value: n1 },
{ type: INUMBER, value: resolveExpression(n2, values) },
{ type: IOP2, value: '*' }
], expr, values);
nstack.push(item.value, f(n1, n2));
} else {
f = expr.binaryOps[item.value];
nstack.push(f(resolveExpression(n1, values), resolveExpression(n2, values)));
nstack.push(item.value, f(resolveExpression(n1, values), resolveExpression(n2, values)));
}
} else if (type === IOP3) {
n3 = nstack.pop();
n2 = nstack.pop();
n1 = nstack.pop();
n3 = nstack.popValue();
n2 = nstack.popValue();
n1 = nstack.popValue();
if (item.value === '?') {
nstack.push(evaluate(n1 ? n2 : n3, expr, values));
nstack.push(item.value, evaluate(n1 ? n2 : n3, expr, values));
} else {
f = expr.ternaryOps[item.value];
nstack.push(f(resolveExpression(n1, values), resolveExpression(n2, values), resolveExpression(n3, values)));
nstack.push(item.value, f(resolveExpression(n1, values), resolveExpression(n2, values), resolveExpression(n3, values)));
}

@@ -209,9 +214,9 @@ } else if (type === IVAR) {

if (item.value in expr.functions) {
nstack.push(expr.functions[item.value]);
nstack.push(item.value, expr.functions[item.value]);
} else if (item.value in expr.unaryOps && expr.parser.isOperatorEnabled(item.value)) {
nstack.push(expr.unaryOps[item.value]);
nstack.push(item.value, expr.unaryOps[item.value]);
} else {
var v = values[item.value];
if (v !== undefined) {
nstack.push(v);
nstack.push(item.value, v);
} else {

@@ -222,11 +227,12 @@ throw new Error('undefined variable: ' + item.value);

} else if (type === IOP1) {
n1 = nstack.pop();
n1 = nstack.popValue();
f = expr.unaryOps[item.value];
nstack.push(f(resolveExpression(n1, values)));
nstack.push(item.value, f(resolveExpression(n1, values)));
} else if (type === IFUNCOP) {
n2 = nstack.pop();
n1 = nstack.pop();
n2 = nstack.popValue();
n1 = nstack.popValue();
args = [n1, n2];
f = expr.functions[item.value];
if (f.apply && f.call) {
nstack.push(f.apply(undefined, [n1, n2]));
nstack.push(item.value, f.apply(undefined, args));
} else {

@@ -239,7 +245,7 @@ throw new Error(f + ' is not a function');

while (argCount-- > 0) {
args.unshift(resolveExpression(nstack.pop(), values));
args.unshift(resolveExpression(nstack.popValue(), values));
}
f = nstack.pop();
f = nstack.popValue();
if (f.apply && f.call) {
nstack.push(f.apply(undefined, args));
nstack.push(item.value, f.apply(undefined, args));
} else {

@@ -250,10 +256,10 @@ throw new Error(f + ' is not a function');

// Create closure to keep references to arguments and expression
nstack.push((function () {
var n2 = nstack.pop();
nstack.push(type, (function () {
var n2 = nstack.popValue();
var args = [];
var argCount = item.value;
while (argCount-- > 0) {
args.unshift(nstack.pop());
args.unshift(nstack.popValue());
}
var n1 = nstack.pop();
var n1 = nstack.popValue();
var f = function () {

@@ -275,8 +281,8 @@ var scope = Object.assign({}, values);

} else if (type === IEXPR) {
nstack.push(createExpressionEvaluator(item, expr));
nstack.push(IEXPR, createExpressionEvaluator(item, expr));
} else if (type === IEXPREVAL) {
nstack.push(item);
nstack.push(IEXPREVAL, item);
} else if (type === IMEMBER) {
n1 = nstack.pop();
nstack.push(n1[item.value]);
n1 = nstack.popValue();
nstack.push(item.value, n1[item.value]);
} else if (type === IENDSTATEMENT) {

@@ -288,5 +294,5 @@ nstack.pop();

while (argCount-- > 0) {
args.unshift(nstack.pop());
args.unshift(nstack.popValue());
}
nstack.push(args);
nstack.push(IARRAY, args);
} else {

@@ -300,3 +306,3 @@ throw new Error('invalid Expression');

// Explicitly return zero to avoid test issues caused by -0
return nstack[0] === 0 ? 0 : resolveExpression(nstack[0], values);
return nstack.first() === 0 ? 0 : resolveExpression(nstack.first(), values);
}

@@ -322,2 +328,26 @@

function stackFactory() {
var stack = [];
return {
get length() {
return stack.length;
},
pop: function pop() {
return stack.pop();
},
popValue: function popValue() {
return stack.pop().value;
},
push: function push(token, value) {
stack.push({
token: token,
value: value
});
},
first: function first() {
return stack[0] && stack[0].value;
}
};
}
function expressionToString(tokens, toJS) {

@@ -389,2 +419,4 @@ var nstack = [];

nstack.push('fac(' + n1 + ')');
} else if (f === '#') {
nstack.push('percent(' + n1 + ')');
} else {

@@ -395,2 +427,4 @@ nstack.push(f + '(' + n1 + ')');

nstack.push('(' + n1 + '!)');
} else if (f === '#') {
nstack.push('(' + n1 + '#)');
} else {

@@ -438,5 +472,5 @@ nstack.push('(' + f + ' ' + n1 + ')');

if (toJS) {
nstack = [ nstack.join(',') ];
nstack = [nstack.join(',')];
} else {
nstack = [ nstack.join(';') ];
nstack = [nstack.join(';')];
}

@@ -979,3 +1013,3 @@ }

if (c === '+' || c === '-' || c === '*' || c === '/' || c === '%' || c === '^' || c === '?' || c === ':' || c === '.') {
if (c === '+' || c === '-' || c === '*' || c === '/' || c === '%' || c === '^' || c === '?' || c === ':' || c === '.' || c === '#') {
this.current = this.newToken(TOP, c);

@@ -1318,6 +1352,9 @@ } else if (c === '∙' || c === '•') {

var POSTFIX_OPERATORS = ['!', '#'];
ParserState.prototype.parsePostfixExpression = function (instr) {
this.parseFunctionOperator(instr);
while (this.accept(TOP, '!')) {
instr.push(unaryInstruction('!'));
while (this.accept(TOP, POSTFIX_OPERATORS)) {
var op = this.current;
instr.push(unaryInstruction(op.value));
}

@@ -1518,2 +1555,6 @@ };

function percent(a) { // a%
return a / 100;
}
function isInteger(value) {

@@ -1731,3 +1772,3 @@ return isFinite(value) && (value === Math.round(value));

var ONE_THIRD = 1/3;
var ONE_THIRD = 1 / 3;
function cbrt(x) {

@@ -1794,2 +1835,3 @@ return x < 0 ? -Math.pow(-x, ONE_THIRD) : Math.pow(x, ONE_THIRD);

'!': factorial,
'#': percent,
sign: Math.sign || sign

@@ -1814,3 +1856,3 @@ };

or: orOperator,
'in': inOperator,
in: inOperator,
'=': setVar,

@@ -1827,2 +1869,3 @@ '[': arrayIndex

fac: factorial,
percent: percent,
min: min,

@@ -1834,3 +1877,3 @@ max: max,

atan2: Math.atan2,
'if': condition,
if: condition,
gamma: gamma,

@@ -1849,4 +1892,4 @@ roundTo: roundTo,

PI: Math.PI,
'true': true,
'false': false
true: true,
false: false
};

@@ -1891,2 +1934,3 @@ }

'!': 'factorial',
'#': 'percent',
'<': 'comparison',

@@ -1899,5 +1943,5 @@ '>': 'comparison',

'||': 'concatenate',
'and': 'logical',
'or': 'logical',
'not': 'logical',
and: 'logical',
or: 'logical',
not: 'logical',
'?': 'conditional',

@@ -1911,3 +1955,3 @@ ':': 'conditional',

function getOptionName(op) {
return optionNameMap.hasOwnProperty(op) ? optionNameMap[op] : op;
return Object.prototype.hasOwnProperty.call(optionNameMap, op) ? optionNameMap[op] : op;
}

@@ -1914,0 +1958,0 @@

@@ -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",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&&c.hasOwnProperty(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=[];if(A(t))return b(t,x);for(var C=t.length,N=0;N<C;N++){var S=t[N],I=S.type;if(I===e||I===o)T.push(S.value);else if(I===s)d=T.pop(),w=T.pop(),"and"===S.value?T.push(!!w&&!!M(d,y,x)):"or"===S.value?T.push(!!w||!!M(d,y,x)):"="===S.value?(E=y.binaryOps[S.value],T.push(E(w,M(d,y,x),x))):(E=y.binaryOps[S.value],T.push(E(b(w,x),b(d,x))));else if(I===n)g=T.pop(),d=T.pop(),w=T.pop(),"?"===S.value?T.push(M(w?d:g,y,x)):(E=y.ternaryOps[S.value],T.push(E(b(w,x),b(d,x),b(g,x))));else if(I===i){if(/^__proto__|prototype|constructor$/.test(S.value))throw new Error("prototype access detected");if(S.value in y.functions)T.push(y.functions[S.value]);else if(S.value in y.unaryOps&&y.parser.isOperatorEnabled(S.value))T.push(y.unaryOps[S.value]);else{var F=x[S.value];if(void 0===F)throw new Error("undefined variable: "+S.value);T.push(F)}}else if(I===r)w=T.pop(),E=y.unaryOps[S.value],T.push(E(b(w,x)));else if(I===a){if(d=T.pop(),w=T.pop(),!(E=y.functions[S.value]).apply||!E.call)throw new Error(E+" is not a function");T.push(E.apply(void 0,[w,d]))}else if(I===p){for(O=S.value,k=[];O-- >0;)k.unshift(b(T.pop(),x));if(!(E=T.pop()).apply||!E.call)throw new Error(E+" is not a function");T.push(E.apply(void 0,k))}else if(I===h)T.push(function(){for(var t=T.pop(),e=[],r=S.value;r-- >0;)e.unshift(T.pop());var s=T.pop(),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(I===u)T.push(m(S,y));else if(I===c)T.push(S);else if(I===f)w=T.pop(),T.push(w[S.value]);else if(I===l)T.pop();else{if(I!==v)throw new Error("invalid Expression");for(O=S.value,k=[];O-- >0;)k.unshift(T.pop());T.push(k)}}if(T.length>1)throw new Error("invalid Expression (parity)");return 0===T[0]?0:b(T[0],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+")"):E.push(w+"("+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",L="TSTRING",R="TPAREN",j="TBRACKET",U="TCOMMA",_="TNAME",q="TSEMICOLON";function B(t,e,r){this.type=t,this.value=e,this.index=r}function V(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}B.prototype.toString=function(){return this.type+": "+this.value},V.prototype.newToken=function(t,e,r){return new B(t,e,null!=r?r:this.pos)},V.prototype.save=function(){this.savedPosition=this.pos,this.savedCurrent=this.current},V.prototype.restore=function(){this.pos=this.savedPosition,this.current=this.savedCurrent},V.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)+'"')},V.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(L,this.unescape(n),e),t=!0;break}s=this.expression.indexOf(r,s+1)}return t},V.prototype.isParen=function(){var t=this.expression.charAt(this.pos);return("("===t||")"===t)&&(this.current=this.newToken(R,t),this.pos++,!0)},V.prototype.isBracket=function(){var t=this.expression.charAt(this.pos);return!("["!==t&&"]"!==t||!this.isOperatorEnabled("["))&&(this.current=this.newToken(j,t),this.pos++,!0)},V.prototype.isComma=function(){return","===this.expression.charAt(this.pos)&&(this.current=this.newToken(U,","),this.pos++,!0)},V.prototype.isSemicolon=function(){return";"===this.expression.charAt(this.pos)&&(this.current=this.newToken(q,";"),this.pos++,!0)},V.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},V.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},V.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},V.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(_,n),this.pos+=n.length,!0}return!1},V.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}V.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},V.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)},V.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},V.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},V.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(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)},V.prototype.isOperatorEnabled=function(t){return this.parser.isOperatorEnabled(t)},V.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}},V.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(_)||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(L))t.push(new y(e,this.current.value));else if(this.accept(R,"("))this.parseExpression(t),this.expect(R,")");else{if(!this.accept(j,"["))throw new Error("unexpected "+this.nextToken);if(this.accept(j,"]"))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(q)&&(!this.nextToken||this.nextToken.type===S||this.nextToken.type===R&&")"===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(j,"]");)for(this.parseExpression(t),++e;this.accept(U);)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.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.parseTerm(t),t.push(w(e.value))}};var W=["*","/","%"];function X(t,e){return Number(t)+Number(e)}function Y(t,e){return t-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 Array.isArray(t)&&Array.isArray(e)?t.concat(e):""+t+e}function Z(t,e){return 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 Boolean(t&&e)}function ot(t,e){return Boolean(t||e)}function at(t,e){return T(e,t)}function pt(t){return(Math.exp(t)-Math.exp(-t))/2}function ht(t){return(Math.exp(t)+Math.exp(-t))/2}function ut(t){return t===1/0?1:t===-1/0?-1:(Math.exp(t)-Math.exp(-t))/(Math.exp(t)+Math.exp(-t))}function ct(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 lt(t){return Math.log((1+t)/(1-t))/2}function vt(t){return Math.log(t)*Math.LOG10E}function yt(t){return-t}function xt(t){return!t}function wt(t){return t<0?Math.ceil(t):Math.floor(t)}function dt(t){return Math.random()*(t||1)}function gt(t){return mt(t+1)}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===R&&"("===this.nextToken.value)return this.restore(),void this.parseExponential(t);if(this.nextToken.type===q||this.nextToken.type===U||this.nextToken.type===S||this.nextToken.type===R&&")"===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("^"))},D.prototype.parsePostfixExpression=function(t){for(this.parseFunctionOperator(t);this.accept(I,"!");)t.push(x("!"))},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(R,"(");)if(this.accept(R,")"))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(R,")");)for(this.parseExpression(t),++e;this.accept(U);)this.parseExpression(t),++e;return e},D.prototype.parseMemberExpression=function(t){for(this.parseAtom(t);this.accept(I,".")||this.accept(j,"[");){var e=this.current;if("."===e.value){if(!this.allowMemberAccess)throw new Error('unexpected ".", member access is not permitted');this.expect(_),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(j,"]"),t.push(w("["))}}};var Et=4.7421875,Mt=[.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 mt(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)*mt(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=Mt[0];for(var h=1;h<Mt.length;++h)r+=Mt[h]/(t+h);return e=t+Et+.5,Math.sqrt(2*Math.PI)*Math.pow(e,t+.5)*Math.exp(-e)*r}function At(t){return Array.isArray(t)?t.length:String(t).length}function bt(){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 kt(t,e,r){return t?e:r}function Ot(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 Tt(t,e,r){return r&&(r[t]=e),e}function Ct(t,e){return t[0|e]}function Nt(t){return 1===arguments.length&&Array.isArray(t)?Math.max.apply(Math,t):Math.max.apply(Math,arguments)}function St(t){return 1===arguments.length&&Array.isArray(t)?Math.min.apply(Math,t):Math.min.apply(Math,arguments)}function It(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 Ft(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 Pt(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 jt(t){return(t>0)-(t<0)||+t}var Ut=1/3;function _t(t){return t<0?-Math.pow(-t,Ut):Math.pow(t,Ut)}function qt(t){return Math.exp(t)-1}function Bt(t){return Math.log(1+t)}function Vt(t){return Math.log(t)/Math.LN2}function $t(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 Dt(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||pt,cosh:Math.cosh||ht,tanh:Math.tanh||ut,asinh:Math.asinh||ct,acosh:Math.acosh||ft,atanh:Math.atanh||lt,sqrt:Math.sqrt,cbrt:Math.cbrt||_t,log:Math.log,log2:Math.log2||Vt,ln:Math.log,lg:Math.log10||vt,log10:Math.log10||vt,expm1:Math.expm1||qt,log1p:Math.log1p||Bt,abs:Math.abs,ceil:Math.ceil,floor:Math.floor,round:Math.round,trunc:Math.trunc||wt,"-":yt,"+":Number,exp:Math.exp,not:xt,length:At,"!":gt,sign:Math.sign||jt},this.binaryOps={"+":X,"-":Y,"*":K,"/":z,"%":H,"^":Math.pow,"||":Q,"==":Z,"!=":tt,">":et,"<":rt,">=":st,"<=":nt,and:it,or:ot,in:at,"=":Tt,"[":Ct},this.ternaryOps={"?":kt},this.functions={random:dt,fac:gt,min:St,max:Nt,hypot:Math.hypot||bt,pyt:Math.hypot||bt,pow:Math.pow,atan2:Math.atan2,if:kt,gamma:mt,roundTo:Ot,map:It,fold:Ft,filter:Pt,indexOf:Lt,join:Rt,sum:$t},this.consts={E:Math.E,PI:Math.PI,true:!0,false:!1}}Dt.prototype.parse=function(t){var e=[],r=new D(this,new V(this,t),{allowMemberAccess:this.options.allowMemberAccess});return r.parseExpression(e),r.expect(S,"EOF"),new N(e,this)},Dt.prototype.evaluate=function(t,e){return this.parse(t).evaluate(e)};var Gt=new Dt;Dt.parse=function(t){return Gt.parse(t)},Dt.evaluate=function(t,e){return Gt.parse(t).evaluate(e)};var Jt={"+":"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"};Dt.prototype.isOperatorEnabled=function(t){var e=function(t){return Jt.hasOwnProperty(t)?Jt[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",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.parseTerm(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]};
/*!

@@ -12,2 +12,2 @@ Based on ndef.parser, by Raphael Graf(r@undefined.ch)

*/
var Wt={Parser:Dt,Expression:N};t.Expression=N,t.Parser=Dt,t.default=Wt,Object.defineProperty(t,"__esModule",{value:!0})}));
var Yt={Parser:Jt,Expression:N};t.Expression=N,t.Parser=Jt,t.default=Yt,Object.defineProperty(t,"__esModule",{value:!0})}));
{
"name": "@oat-sa/expr-eval",
"version": "2.0.0",
"version": "2.1.0",
"description": "Mathematical expression evaluator",

@@ -11,3 +11,2 @@ "main": "dist/bundle.js",

},
"dependencies": {},
"devDependencies": {

@@ -22,2 +21,3 @@ "eslint": "^6.3.0",

"mocha": "^10.0.0",
"npm-run-all": "^4.1.5",
"nyc": "^14.1.1",

@@ -29,4 +29,8 @@ "rollup": "^1.20.3",

"test": "npm run build && mocha",
"test:watch": "mocha -w",
"dev": "run-p watch test:watch",
"coverage": "npm run build && nyc --reporter=lcov --reporter=text-summary mocha",
"coverage:clover": "nyc report -r clover",
"lint": "eslint index.js src test rollup.config.js rollup-min.config.js",
"lint:report": "eslint index.js src test rollup.config.js rollup-min.config.js --output-file eslint_report.json --format json",
"watch": "rollup -c rollup.config.js -w",

@@ -52,3 +56,5 @@ "build": "rollup -c rollup.config.js && rollup -c rollup-min.config.js && rollup -c rollup-esm.config.js",

],
"author": "Matthew Crumley",
"author": {
"name": "Matthew Crumley"
},
"license": "MIT",

@@ -55,0 +61,0 @@ "bugs": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc