Socket
Socket
Sign inDemoInstall

@zvenigora/jse-eval

Package Overview
Dependencies
1
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.2 to 1.6.0

17

CHANGELOG.md

@@ -1,2 +0,2 @@

## [1.5.2](https://github.com/Zvenigora/jse-eval/compare/v1.5.1...v1.5.2) (2022-07-21)
# [1.6.0](https://github.com/Zvenigora/jse-eval/compare/v1.5.2...v1.6.0) (2022-08-05)

@@ -6,6 +6,17 @@

* correct changelog.md ([804271e](https://github.com/Zvenigora/jse-eval/commit/804271ecae3d5508650b3c19a5955a6ee9c6a64c))
* updated version ([567238d](https://github.com/Zvenigora/jse-eval/commit/567238df43f2ccb308aed873ad24c59af3844003))
## [1.5.1+0.0.1] (https://github.com/zvenigora/jse-eval/compare/v1.5.1...v1.5.1+0.0.1) (2022-07-18)
### Features
* add options for case-insensitive evaluation ([2b33b18](https://github.com/Zvenigora/jse-eval/commit/2b33b180373b96c9f361e2864746f9dcf455f86e))
## [1.5.1.002] (https://github.com/zvenigora/jse-eval/compare/v1.5.1.002...v1.5.1.003) (2022-07-18)
* Feature: added support for case-insensitive evaluation via options.
* Fix: corrected changelog.md
## [1.5.1.001] (https://github.com/zvenigora/jse-eval/compare/v1.5.1...v1.5.1.001) (2022-07-18)
Forked from [jse-eval](https://github.com/6utt3rfly/jse-eval]) v1.5.1. Many thanks to @Shelly (6utt3rfly) and @donmccurdy

@@ -12,0 +23,0 @@

15

dist/index.d.ts

@@ -7,2 +7,3 @@ import jsep from 'jsep';

export declare type Context = Record<string, unknown>;
export declare type ContextOrObject = Record<string, unknown> | object;
export declare type operand = any;

@@ -17,2 +18,5 @@ export declare type unaryCallback = (a: operand) => operand;

};
export declare type EvalOptions = {
caseSensitive?: boolean;
};
export default class ExpressionEval {

@@ -31,4 +35,4 @@ static jsep: typeof jsep;

static registerPlugin(...plugins: Array<JseEvalPlugin>): void;
static eval(ast: jsep.Expression, context?: Context): unknown;
static evalAsync(ast: jsep.Expression, context?: Context): Promise<unknown>;
static eval(ast: jsep.Expression, context?: Context, options?: EvalOptions): unknown;
static evalAsync(ast: jsep.Expression, context?: Context, options?: EvalOptions): Promise<unknown>;
static compile(expression: string): (context?: Context) => unknown;

@@ -40,3 +44,5 @@ static compileAsync(expression: string): (context?: Context) => Promise<unknown>;

isAsync?: boolean;
constructor(context?: Context, isAsync?: boolean);
options?: EvalOptions;
get caseSensitive(): boolean;
constructor(context?: Context, isAsync?: boolean, options?: EvalOptions);
eval(node: unknown, cb?: (v: any) => any): unknown;

@@ -72,2 +78,5 @@ evalSyncAsync(val: unknown, cb: (unknown: any) => unknown): Promise<unknown> | unknown;

protected static nodeFunctionName(callee: AnyExpression): string;
private static getValue;
private static getKeyValuePair;
private static getLiteralPair;
}

@@ -74,0 +83,0 @@ /** NOTE: exporting named + default.

@@ -1,2 +0,2 @@

import e from"jsep";export{default as jsep,default as parse}from"jsep";function t(){return t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},t.apply(this,arguments)}class n{static addUnaryOp(t,r){e.addUnaryOp(t),n.unops[t]=r}static addBinaryOp(t,r,s,i){let a,o,l;"function"==typeof r?l=r:(a=r,"function"==typeof s?l=s:(o=s,l=i)),e.addBinaryOp(t,a||1,o),n.binops[t]=l}static addEvaluator(e,t){n.evaluators[e]=t}static registerPlugin(...e){e.forEach(e=>{e.init&&n.parse.plugins.register(e),e.initEval&&e.initEval.call(n,n)})}static eval(e,t){return new n(t).eval(e)}static async evalAsync(e,t){return new n(t,!0).eval(e)}static compile(e){return n.eval.bind(null,n.jsep(e))}static compileAsync(e){return n.evalAsync.bind(null,n.jsep(e))}static evalExpr(e,t){return n.compile(e)(t)}static evalExprAsync(e,t){return n.compileAsync(e)(t)}constructor(e,t){this.context=void 0,this.isAsync=void 0,this.context=e,this.isAsync=t}eval(e,t=(e=>e)){const r=n.evaluators[e.type]||n.evaluators.default;if(!r)throw new Error(`unknown node type: ${JSON.stringify(e,null,2)}`);return this.evalSyncAsync(r.bind(this)(e,this.context),n=>(e._value=n,t(n)))}evalSyncAsync(e,t){return this.isAsync?Promise.resolve(e).then(t):t(e)}evalArrayExpression(e){return this.evalArray(e.elements)}evalArray(e){const t=e.map(e=>this.eval(e)),n=t=>t.reduce((t,n,r)=>"SpreadElement"===e[r].type?[...t,...n]:(t.push(n),t),[]);return this.isAsync?Promise.all(t).then(n):n(t)}evalBinaryExpression(e){if("||"===e.operator)return this.eval(e.left,t=>t||this.eval(e.right));if("&&"===e.operator)return this.eval(e.left,t=>t&&this.eval(e.right));const t=[this.eval(e.left),this.eval(e.right)],r=([t,r])=>n.binops[e.operator](t,r);return this.isAsync?Promise.all(t).then(r):r(t)}evalCompoundExpression(e){return this.isAsync?e.body.reduce((e,t)=>e.then(()=>this.eval(t)),Promise.resolve()):e.body.map(e=>this.eval(e))[e.body.length-1]}evalCallExpression(e){return this.evalSyncAsync(this.evalCall(e.callee),([t,n])=>this.evalSyncAsync(this.evalArray(e.arguments),e=>t.apply(n,e)))}evalCall(e){return"MemberExpression"===e.type?this.evalSyncAsync(this.evaluateMember(e),([t,r])=>n.validateFnAndCall(r,t,e)):this.eval(e,t=>n.validateFnAndCall(t,e))}evalConditionalExpression(e){return this.eval(e.test,t=>this.eval(t?e.consequent:e.alternate))}evalIdentifier(e){return this.context[e.name]}static evalLiteral(e){return e.value}evalMemberExpression(e){return this.evalSyncAsync(this.evaluateMember(e),([,e])=>e)}evaluateMember(e){return this.eval(e.object,t=>this.evalSyncAsync(e.computed?this.eval(e.property):e.property.name,n=>{if(/^__proto__|prototype|constructor$/.test(n))throw Error(`Access to member "${n}" disallowed.`);return[t,(e.optional?t||{}:t)[n],n]}))}evalThisExpression(){return this.context}evalUnaryExpression(e){return this.eval(e.argument,t=>n.unops[e.operator](t))}evalArrowFunctionExpression(e){return this.isAsync!==e.async?n[e.async?"evalAsync":"eval"](e,this.context):(...t)=>{const r=this.evalArrowContext(e,t);return n[e.async?"evalAsync":"eval"](e.body,r)}}evalArrowContext(e,n){const r=t({},this.context);return(e.params||[]).forEach((e,s)=>{if("AssignmentExpression"===e.type&&(void 0===n[s]&&(n[s]=this.eval(e.right)),e=e.left),"Identifier"===e.type)r[e.name]=n[s];else if("ArrayExpression"===e.type)e.elements.forEach((e,t)=>{let i=n[s][t];if("AssignmentExpression"===e.type&&(void 0===i&&(i=this.eval(e.right)),e=e.left),"Identifier"!==e.type)throw new Error("Unexpected arrow function argument");r[e.name]=i});else if("ObjectExpression"===e.type){const i=[];e.properties.forEach(e=>{let a,o=e;if("AssignmentExpression"===o.type&&(o=o.left),"Property"===o.type)a="Identifier"===o.key.type?o.key.name:this.eval(o.key).toString();else if("Identifier"===o.type)a=o.name;else{if("SpreadElement"!==o.type||"Identifier"!==o.argument.type)throw new Error("Unexpected arrow function argument");a=o.argument.name}let l=n[s][a];"SpreadElement"===o.type?(l=t({},n[s]),i.forEach(e=>{delete l[e]})):void 0===l&&"AssignmentExpression"===e.type&&(l=this.eval(e.right)),r[a]=l,i.push(a)})}else{if("SpreadElement"!==e.type||"Identifier"!==e.argument.type)throw new Error("Unexpected arrow function argument");r[e.argument.name]=n.slice(s)}}),r}evalAssignmentExpression(e){return this.evalSyncAsync(this.getContextAndKey(e.left),([t,r])=>this.eval(e.right,s=>n.assignOps[e.operator](t,r,s)))}evalUpdateExpression(e){return this.evalSyncAsync(this.getContextAndKey(e.argument),([t,r])=>n.evalUpdateOperation(e,t,r))}evalAwaitExpression(e){return n.evalAsync(e.argument,this.context)}static evalUpdateOperation(e,t,n){return e.prefix?"++"===e.operator?++t[n]:--t[n]:"++"===e.operator?t[n]++:t[n]--}getContextAndKey(e){if("MemberExpression"===e.type)return this.evalSyncAsync(this.evaluateMember(e),([e,,t])=>[e,t]);if("Identifier"===e.type)return[this.context,e.name];if("ConditionalExpression"===e.type)return this.eval(e.test,t=>this.getContextAndKey(t?e.consequent:e.alternate));throw new Error("Invalid Member Key")}evalNewExpression(e){return this.evalSyncAsync(this.evalCall(e.callee),([t])=>this.evalSyncAsync(this.evalArray(e.arguments),r=>n.construct(t,r,e)))}evalObjectExpression(e){const t={},r=e.properties.map(e=>{if("SpreadElement"===e.type)Object.assign(t,n.eval(e.argument,this.context));else if("Property"===e.type)return this.evalSyncAsync("Identifier"===e.key.type?e.key.name:this.eval(e.key),n=>this.eval(e.shorthand?e.key:e.value,e=>{t[n]=e}))});return this.isAsync?Promise.all(r).then(()=>t):t}evalSpreadElement(e){return this.eval(e.argument)}evalTaggedTemplateExpression(e){const t=[this.evalCall(e.tag),this.evalSyncAsync(this.evalArray(e.quasi.expressions),t=>[e.quasi.quasis.map(e=>e.value.cooked),...t])],n=([[e,t],n])=>e.apply(t,n);return this.isAsync?Promise.all(t).then(n):n(t)}evalTemplateLiteral(e){return this.evalSyncAsync(this.evalArray(e.expressions),t=>e.quasis.reduce((e,n,r)=>(e+=n.value.cooked,n.tail||(e+=t[r]),e),""))}static construct(e,t,r){try{return new(Function.prototype.bind.apply(e,[null].concat(t)))}catch(e){throw new Error(`${n.nodeFunctionName(r.callee)} is not a constructor`)}}static validateFnAndCall(e,t,r){if("function"!=typeof e){if(!e&&r&&r.optional)return[()=>{},t];const s=n.nodeFunctionName(r||t);throw new Error(`'${s}' is not a function`)}return[e,t]}static nodeFunctionName(e){return e&&(e.name||e.property&&e.property.name)}}n.jsep=e,n.parse=e,n.evaluate=n.eval,n.evaluators={ArrayExpression:n.prototype.evalArrayExpression,LogicalExpression:n.prototype.evalBinaryExpression,BinaryExpression:n.prototype.evalBinaryExpression,CallExpression:n.prototype.evalCallExpression,Compound:n.prototype.evalCompoundExpression,ConditionalExpression:n.prototype.evalConditionalExpression,Identifier:n.prototype.evalIdentifier,Literal:n.evalLiteral,OptionalMemberExpression:n.prototype.evalMemberExpression,MemberExpression:n.prototype.evalMemberExpression,ThisExpression:n.prototype.evalThisExpression,UnaryExpression:n.prototype.evalUnaryExpression,ArrowFunctionExpression:n.prototype.evalArrowFunctionExpression,AssignmentExpression:n.prototype.evalAssignmentExpression,UpdateExpression:n.prototype.evalUpdateExpression,AwaitExpression:n.prototype.evalAwaitExpression,NewExpression:n.prototype.evalNewExpression,ObjectExpression:n.prototype.evalObjectExpression,SpreadElement:n.prototype.evalSpreadElement,TaggedTemplateExpression:n.prototype.evalTaggedTemplateExpression,TemplateLiteral:n.prototype.evalTemplateLiteral},n.DEFAULT_PRECEDENCE={"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},n.binops={"||":function(e,t){return e||t},"&&":function(e,t){return e&&t},"|":function(e,t){return e|t},"^":function(e,t){return e^t},"&":function(e,t){return e&t},"==":function(e,t){return e==t},"!=":function(e,t){return e!=t},"===":function(e,t){return e===t},"!==":function(e,t){return e!==t},"<":function(e,t){return e<t},">":function(e,t){return e>t},"<=":function(e,t){return e<=t},">=":function(e,t){return e>=t},"<<":function(e,t){return e<<t},">>":function(e,t){return e>>t},">>>":function(e,t){return e>>>t},"+":function(e,t){return e+t},"-":function(e,t){return e-t},"*":function(e,t){return e*t},"/":function(e,t){return e/t},"%":function(e,t){return e%t}},n.unops={"-":function(e){return-e},"+":function(e){return+e},"~":function(e){return~e},"!":function(e){return!e}},n.assignOps={"=":function(e,t,n){return e[t]=n},"*=":function(e,t,n){return e[t]*=n},"**=":function(e,t,n){return e[t]**=n},"/=":function(e,t,n){return e[t]/=n},"%=":function(e,t,n){return e[t]%=n},"+=":function(e,t,n){return e[t]+=n},"-=":function(e,t,n){return e[t]-=n},"<<=":function(e,t,n){return e[t]<<=n},">>=":function(e,t,n){return e[t]>>=n},">>>=":function(e,t,n){return e[t]>>>=n},"&=":function(e,t,n){return e[t]&=n},"^=":function(e,t,n){return e[t]^=n},"|=":function(e,t,n){return e[t]|=n}};const r=n.DEFAULT_PRECEDENCE,s=n.evaluators,i=n.binops,a=n.unops,o=n.assignOps,l=n.addUnaryOp,p=n.addBinaryOp,u=n.addEvaluator,c=n.registerPlugin,y=n.eval,v=n.evalAsync,h=n.compile,f=n.compileAsync,E=n.evalExpr,d=n.evalExprAsync;export{r as DEFAULT_PRECEDENCE,p as addBinaryOp,u as addEvaluator,l as addUnaryOp,o as assignOps,i as binops,h as compile,f as compileAsync,n as default,v as evalAsync,E as evalExpr,d as evalExprAsync,y as evaluate,s as evaluators,c as registerPlugin,a as unops};
import e from"jsep";export{default as jsep,default as parse}from"jsep";function t(){return t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},t.apply(this,arguments)}const n={caseSensitive:!0},r=new Map([["undefined",void 0],["null",null],["true",!0],["false",!1]]);class s{static addUnaryOp(t,n){e.addUnaryOp(t),s.unops[t]=n}static addBinaryOp(t,n,r,i){let a,o,l;"function"==typeof n?l=n:(a=n,"function"==typeof r?l=r:(o=r,l=i)),e.addBinaryOp(t,a||1,o),s.binops[t]=l}static addEvaluator(e,t){s.evaluators[e]=t}static registerPlugin(...e){e.forEach(e=>{e.init&&s.parse.plugins.register(e),e.initEval&&e.initEval.call(s,s)})}static eval(e,t,n){return new s(t,void 0,n).eval(e)}static async evalAsync(e,t,n){return new s(t,!0,n).eval(e)}static compile(e){return s.eval.bind(null,s.jsep(e))}static compileAsync(e){return s.evalAsync.bind(null,s.jsep(e))}static evalExpr(e,t){return s.compile(e)(t)}static evalExprAsync(e,t){return s.compileAsync(e)(t)}get caseSensitive(){return!(!this.options||!this.options.caseSensitive)}constructor(e,t,r){this.context=void 0,this.isAsync=void 0,this.options=void 0,this.context=e,this.isAsync=t,this.options=r||n}eval(e,t=(e=>e)){const n=s.evaluators[e.type]||s.evaluators.default;if(!n)throw new Error(`unknown node type: ${JSON.stringify(e,null,2)}`);return this.evalSyncAsync(n.bind(this)(e,this.context),n=>(e._value=n,t(n)))}evalSyncAsync(e,t){return this.isAsync?Promise.resolve(e).then(t):t(e)}evalArrayExpression(e){return this.evalArray(e.elements)}evalArray(e){const t=e.map(e=>this.eval(e)),n=t=>t.reduce((t,n,r)=>"SpreadElement"===e[r].type?[...t,...n]:(t.push(n),t),[]);return this.isAsync?Promise.all(t).then(n):n(t)}evalBinaryExpression(e){if("||"===e.operator)return this.eval(e.left,t=>t||this.eval(e.right));if("&&"===e.operator)return this.eval(e.left,t=>t&&this.eval(e.right));const t=[this.eval(e.left),this.eval(e.right)],n=([t,n])=>s.binops[e.operator](t,n);return this.isAsync?Promise.all(t).then(n):n(t)}evalCompoundExpression(e){return this.isAsync?e.body.reduce((e,t)=>e.then(()=>this.eval(t)),Promise.resolve()):e.body.map(e=>this.eval(e))[e.body.length-1]}evalCallExpression(e){return this.evalSyncAsync(this.evalCall(e.callee),([t,n])=>this.evalSyncAsync(this.evalArray(e.arguments),e=>t.apply(n,e)))}evalCall(e){return"MemberExpression"===e.type?this.evalSyncAsync(this.evaluateMember(e),([t,n])=>s.validateFnAndCall(n,t,e)):this.eval(e,t=>s.validateFnAndCall(t,e))}evalConditionalExpression(e){return this.eval(e.test,t=>this.eval(t?e.consequent:e.alternate))}evalIdentifier(e){if(this.caseSensitive)return this.context[e.name];if(0===e.name.localeCompare("this","en",{sensitivity:"base"}))return this.evalThisExpression();{const t=s.getLiteralPair(r,e.name,this.caseSensitive);if(t){const[,e]=t;return e}return s.getValue(this.context,e.name,this.caseSensitive)}}static evalLiteral(e){return e.value}evalMemberExpression(e){return this.evalSyncAsync(this.evaluateMember(e),([,e])=>e)}evaluateMember(e){return this.eval(e.object,t=>this.evalSyncAsync(e.computed?this.eval(e.property):e.property.name,n=>{if(/^__proto__|prototype|constructor$/.test(n))throw Error(`Access to member "${n}" disallowed.`);const r=s.getValue(e.optional?t||{}:t,n,this.caseSensitive);return[t,r,n]}))}evalThisExpression(){return this.context}evalUnaryExpression(e){return this.eval(e.argument,t=>s.unops[e.operator](t))}evalArrowFunctionExpression(e){return this.isAsync!==e.async?s[e.async?"evalAsync":"eval"](e,this.context):(...t)=>{const n=this.evalArrowContext(e,t);return s[e.async?"evalAsync":"eval"](e.body,n)}}evalArrowContext(e,n){const r=t({},this.context);return(e.params||[]).forEach((e,s)=>{if("AssignmentExpression"===e.type&&(void 0===n[s]&&(n[s]=this.eval(e.right)),e=e.left),"Identifier"===e.type)r[e.name]=n[s];else if("ArrayExpression"===e.type)e.elements.forEach((e,t)=>{let i=n[s][t];if("AssignmentExpression"===e.type&&(void 0===i&&(i=this.eval(e.right)),e=e.left),"Identifier"!==e.type)throw new Error("Unexpected arrow function argument");r[e.name]=i});else if("ObjectExpression"===e.type){const i=[];e.properties.forEach(e=>{let a,o=e;if("AssignmentExpression"===o.type&&(o=o.left),"Property"===o.type)a="Identifier"===o.key.type?o.key.name:this.eval(o.key).toString();else if("Identifier"===o.type)a=o.name;else{if("SpreadElement"!==o.type||"Identifier"!==o.argument.type)throw new Error("Unexpected arrow function argument");a=o.argument.name}let l=n[s][a];"SpreadElement"===o.type?(l=t({},n[s]),i.forEach(e=>{delete l[e]})):void 0===l&&"AssignmentExpression"===e.type&&(l=this.eval(e.right)),r[a]=l,i.push(a)})}else{if("SpreadElement"!==e.type||"Identifier"!==e.argument.type)throw new Error("Unexpected arrow function argument");r[e.argument.name]=n.slice(s)}}),r}evalAssignmentExpression(e){return this.evalSyncAsync(this.getContextAndKey(e.left),([t,n])=>this.eval(e.right,r=>s.assignOps[e.operator](t,n,r)))}evalUpdateExpression(e){return this.evalSyncAsync(this.getContextAndKey(e.argument),([t,n])=>s.evalUpdateOperation(e,t,n))}evalAwaitExpression(e){return s.evalAsync(e.argument,this.context)}static evalUpdateOperation(e,t,n){return e.prefix?"++"===e.operator?++t[n]:--t[n]:"++"===e.operator?t[n]++:t[n]--}getContextAndKey(e){if("MemberExpression"===e.type)return this.evalSyncAsync(this.evaluateMember(e),([e,,t])=>{const[n]=s.getKeyValuePair(e,t,this.caseSensitive);return[e,n]});if("Identifier"===e.type){const[t]=s.getKeyValuePair(this.context,e.name,this.caseSensitive);return[this.context,t]}if("ConditionalExpression"===e.type)return this.eval(e.test,t=>this.getContextAndKey(t?e.consequent:e.alternate));throw new Error("Invalid Member Key")}evalNewExpression(e){return this.evalSyncAsync(this.evalCall(e.callee),([t])=>this.evalSyncAsync(this.evalArray(e.arguments),n=>s.construct(t,n,e)))}evalObjectExpression(e){const t={},n=e.properties.map(e=>{if("SpreadElement"===e.type)Object.assign(t,s.eval(e.argument,this.context,this.options));else if("Property"===e.type)return this.evalSyncAsync("Identifier"===e.key.type?e.key.name:this.eval(e.key),n=>this.eval(e.shorthand?e.key:e.value,e=>{t[n]=e}))});return this.isAsync?Promise.all(n).then(()=>t):t}evalSpreadElement(e){return this.eval(e.argument)}evalTaggedTemplateExpression(e){const t=[this.evalCall(e.tag),this.evalSyncAsync(this.evalArray(e.quasi.expressions),t=>[e.quasi.quasis.map(e=>e.value.cooked),...t])],n=([[e,t],n])=>e.apply(t,n);return this.isAsync?Promise.all(t).then(n):n(t)}evalTemplateLiteral(e){return this.evalSyncAsync(this.evalArray(e.expressions),t=>e.quasis.reduce((e,n,r)=>(e+=n.value.cooked,n.tail||(e+=t[r]),e),""))}static construct(e,t,n){try{return new(Function.prototype.bind.apply(e,[null].concat(t)))}catch(e){throw new Error(`${s.nodeFunctionName(n.callee)} is not a constructor`)}}static validateFnAndCall(e,t,n){if("function"!=typeof e){if(!e&&n&&n.optional)return[()=>{},t];const r=s.nodeFunctionName(n||t);throw new Error(`'${r}' is not a function`)}return[e,t]}static nodeFunctionName(e){return e&&(e.name||e.property&&e.property.name)}static getValue(e,t,n){const[,r]=s.getKeyValuePair(e,t,n);return r}static getKeyValuePair(e,t,n){if(n||"string"!=typeof t)return[t,e[t]];if("string"==typeof t){let n=e;do{const r=Object.getOwnPropertyNames(n);if(Array.isArray(r)){const n=r.find(e=>0===e.localeCompare(t,"en",{sensitivity:"base"}));if(n)return[n,e[n]]}}while(n=Object.getPrototypeOf(n))}return[t,void 0]}static getLiteralPair(e,t,n){if(n)return e[t];for(const[n,r]of e)if(0===n.localeCompare(t,"en",{sensitivity:"base"}))return[n,r]}}s.jsep=e,s.parse=e,s.evaluate=s.eval,s.evaluators={ArrayExpression:s.prototype.evalArrayExpression,LogicalExpression:s.prototype.evalBinaryExpression,BinaryExpression:s.prototype.evalBinaryExpression,CallExpression:s.prototype.evalCallExpression,Compound:s.prototype.evalCompoundExpression,ConditionalExpression:s.prototype.evalConditionalExpression,Identifier:s.prototype.evalIdentifier,Literal:s.evalLiteral,OptionalMemberExpression:s.prototype.evalMemberExpression,MemberExpression:s.prototype.evalMemberExpression,ThisExpression:s.prototype.evalThisExpression,UnaryExpression:s.prototype.evalUnaryExpression,ArrowFunctionExpression:s.prototype.evalArrowFunctionExpression,AssignmentExpression:s.prototype.evalAssignmentExpression,UpdateExpression:s.prototype.evalUpdateExpression,AwaitExpression:s.prototype.evalAwaitExpression,NewExpression:s.prototype.evalNewExpression,ObjectExpression:s.prototype.evalObjectExpression,SpreadElement:s.prototype.evalSpreadElement,TaggedTemplateExpression:s.prototype.evalTaggedTemplateExpression,TemplateLiteral:s.prototype.evalTemplateLiteral},s.DEFAULT_PRECEDENCE={"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},s.binops={"||":function(e,t){return e||t},"&&":function(e,t){return e&&t},"|":function(e,t){return e|t},"^":function(e,t){return e^t},"&":function(e,t){return e&t},"==":function(e,t){return e==t},"!=":function(e,t){return e!=t},"===":function(e,t){return e===t},"!==":function(e,t){return e!==t},"<":function(e,t){return e<t},">":function(e,t){return e>t},"<=":function(e,t){return e<=t},">=":function(e,t){return e>=t},"<<":function(e,t){return e<<t},">>":function(e,t){return e>>t},">>>":function(e,t){return e>>>t},"+":function(e,t){return e+t},"-":function(e,t){return e-t},"*":function(e,t){return e*t},"/":function(e,t){return e/t},"%":function(e,t){return e%t}},s.unops={"-":function(e){return-e},"+":function(e){return+e},"~":function(e){return~e},"!":function(e){return!e}},s.assignOps={"=":function(e,t,n){return e[t]=n},"*=":function(e,t,n){return e[t]*=n},"**=":function(e,t,n){return e[t]**=n},"/=":function(e,t,n){return e[t]/=n},"%=":function(e,t,n){return e[t]%=n},"+=":function(e,t,n){return e[t]+=n},"-=":function(e,t,n){return e[t]-=n},"<<=":function(e,t,n){return e[t]<<=n},">>=":function(e,t,n){return e[t]>>=n},">>>=":function(e,t,n){return e[t]>>>=n},"&=":function(e,t,n){return e[t]&=n},"^=":function(e,t,n){return e[t]^=n},"|=":function(e,t,n){return e[t]|=n}};const i=s.DEFAULT_PRECEDENCE,a=s.evaluators,o=s.binops,l=s.unops,p=s.assignOps,u=s.addUnaryOp,c=s.addBinaryOp,y=s.addEvaluator,v=s.registerPlugin,h=s.eval,f=s.evalAsync,d=s.compile,m=s.compileAsync,E=s.evalExpr,x=s.evalExprAsync;export{i as DEFAULT_PRECEDENCE,c as addBinaryOp,y as addEvaluator,u as addUnaryOp,p as assignOps,o as binops,d as compile,m as compileAsync,s as default,f as evalAsync,E as evalExpr,x as evalExprAsync,h as evaluate,a as evaluators,v as registerPlugin,l as unops};
//# sourceMappingURL=jse-eval.modern.js.map

@@ -1,2 +0,2 @@

import n from"jsep";export{default as jsep,default as parse}from"jsep";function e(){return e=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},e.apply(this,arguments)}var t=/*#__PURE__*/function(){function t(n,e){this.context=void 0,this.isAsync=void 0,this.context=n,this.isAsync=e}t.addUnaryOp=function(e,r){n.addUnaryOp(e),t.unops[e]=r},t.addBinaryOp=function(e,r,i,o){var a,s,u;"function"==typeof r?u=r:(a=r,"function"==typeof i?u=i:(s=i,u=o)),n.addBinaryOp(e,a||1,s),t.binops[e]=u},t.addEvaluator=function(n,e){t.evaluators[n]=e},t.registerPlugin=function(){[].slice.call(arguments).forEach(function(n){n.init&&t.parse.plugins.register(n),n.initEval&&n.initEval.call(t,t)})},t.eval=function(n,e){return new t(e).eval(n)},t.evalAsync=function(n,e){try{return Promise.resolve(new t(e,!0).eval(n))}catch(n){return Promise.reject(n)}},t.compile=function(n){return t.eval.bind(null,t.jsep(n))},t.compileAsync=function(n){return t.evalAsync.bind(null,t.jsep(n))},t.evalExpr=function(n,e){return t.compile(n)(e)},t.evalExprAsync=function(n,e){return t.compileAsync(n)(e)};var r=t.prototype;return r.eval=function(n,e){void 0===e&&(e=function(n){return n});var r=t.evaluators[n.type]||t.evaluators.default;if(!r)throw new Error("unknown node type: "+JSON.stringify(n,null,2));return this.evalSyncAsync(r.bind(this)(n,this.context),function(t){return n._value=t,e(t)})},r.evalSyncAsync=function(n,e){return this.isAsync?Promise.resolve(n).then(e):e(n)},r.evalArrayExpression=function(n){return this.evalArray(n.elements)},r.evalArray=function(n){var e=this,t=n.map(function(n){return e.eval(n)}),r=function(e){return e.reduce(function(e,t,r){return"SpreadElement"===n[r].type?[].concat(e,t):(e.push(t),e)},[])};return this.isAsync?Promise.all(t).then(r):r(t)},r.evalBinaryExpression=function(n){var e=this;if("||"===n.operator)return this.eval(n.left,function(t){return t||e.eval(n.right)});if("&&"===n.operator)return this.eval(n.left,function(t){return t&&e.eval(n.right)});var r=[this.eval(n.left),this.eval(n.right)],i=function(e){return t.binops[n.operator](e[0],e[1])};return this.isAsync?Promise.all(r).then(i):i(r)},r.evalCompoundExpression=function(n){var e=this;return this.isAsync?n.body.reduce(function(n,t){return n.then(function(){return e.eval(t)})},Promise.resolve()):n.body.map(function(n){return e.eval(n)})[n.body.length-1]},r.evalCallExpression=function(n){var e=this;return this.evalSyncAsync(this.evalCall(n.callee),function(t){var r=t[0],i=t[1];return e.evalSyncAsync(e.evalArray(n.arguments),function(n){return r.apply(i,n)})})},r.evalCall=function(n){return"MemberExpression"===n.type?this.evalSyncAsync(this.evaluateMember(n),function(e){return t.validateFnAndCall(e[1],e[0],n)}):this.eval(n,function(e){return t.validateFnAndCall(e,n)})},r.evalConditionalExpression=function(n){var e=this;return this.eval(n.test,function(t){return e.eval(t?n.consequent:n.alternate)})},r.evalIdentifier=function(n){return this.context[n.name]},t.evalLiteral=function(n){return n.value},r.evalMemberExpression=function(n){return this.evalSyncAsync(this.evaluateMember(n),function(n){return n[1]})},r.evaluateMember=function(n){var e=this;return this.eval(n.object,function(t){return e.evalSyncAsync(n.computed?e.eval(n.property):n.property.name,function(e){if(/^__proto__|prototype|constructor$/.test(e))throw Error('Access to member "'+e+'" disallowed.');return[t,(n.optional?t||{}:t)[e],e]})})},r.evalThisExpression=function(){return this.context},r.evalUnaryExpression=function(n){return this.eval(n.argument,function(e){return t.unops[n.operator](e)})},r.evalArrowFunctionExpression=function(n){var e=this;return this.isAsync!==n.async?t[n.async?"evalAsync":"eval"](n,this.context):function(){var r=e.evalArrowContext(n,[].slice.call(arguments));return t[n.async?"evalAsync":"eval"](n.body,r)}},r.evalArrowContext=function(n,t){var r=this,i=e({},this.context);return(n.params||[]).forEach(function(n,o){if("AssignmentExpression"===n.type&&(void 0===t[o]&&(t[o]=r.eval(n.right)),n=n.left),"Identifier"===n.type)i[n.name]=t[o];else if("ArrayExpression"===n.type)n.elements.forEach(function(n,e){var a=t[o][e];if("AssignmentExpression"===n.type&&(void 0===a&&(a=r.eval(n.right)),n=n.left),"Identifier"!==n.type)throw new Error("Unexpected arrow function argument");i[n.name]=a});else if("ObjectExpression"===n.type){var a=[];n.properties.forEach(function(n){var s,u=n;if("AssignmentExpression"===u.type&&(u=u.left),"Property"===u.type)s="Identifier"===u.key.type?u.key.name:r.eval(u.key).toString();else if("Identifier"===u.type)s=u.name;else{if("SpreadElement"!==u.type||"Identifier"!==u.argument.type)throw new Error("Unexpected arrow function argument");s=u.argument.name}var c=t[o][s];"SpreadElement"===u.type?(c=e({},t[o]),a.forEach(function(n){delete c[n]})):void 0===c&&"AssignmentExpression"===n.type&&(c=r.eval(n.right)),i[s]=c,a.push(s)})}else{if("SpreadElement"!==n.type||"Identifier"!==n.argument.type)throw new Error("Unexpected arrow function argument");i[n.argument.name]=t.slice(o)}}),i},r.evalAssignmentExpression=function(n){var e=this;return this.evalSyncAsync(this.getContextAndKey(n.left),function(r){var i=r[0],o=r[1];return e.eval(n.right,function(e){return t.assignOps[n.operator](i,o,e)})})},r.evalUpdateExpression=function(n){return this.evalSyncAsync(this.getContextAndKey(n.argument),function(e){return t.evalUpdateOperation(n,e[0],e[1])})},r.evalAwaitExpression=function(n){return t.evalAsync(n.argument,this.context)},t.evalUpdateOperation=function(n,e,t){return n.prefix?"++"===n.operator?++e[t]:--e[t]:"++"===n.operator?e[t]++:e[t]--},r.getContextAndKey=function(n){var e=this;if("MemberExpression"===n.type)return this.evalSyncAsync(this.evaluateMember(n),function(n){return[n[0],n[2]]});if("Identifier"===n.type)return[this.context,n.name];if("ConditionalExpression"===n.type)return this.eval(n.test,function(t){return e.getContextAndKey(t?n.consequent:n.alternate)});throw new Error("Invalid Member Key")},r.evalNewExpression=function(n){var e=this;return this.evalSyncAsync(this.evalCall(n.callee),function(r){var i=r[0];return e.evalSyncAsync(e.evalArray(n.arguments),function(e){return t.construct(i,e,n)})})},r.evalObjectExpression=function(n){var e=this,r={},i=n.properties.map(function(n){if("SpreadElement"===n.type)Object.assign(r,t.eval(n.argument,e.context));else if("Property"===n.type)return e.evalSyncAsync("Identifier"===n.key.type?n.key.name:e.eval(n.key),function(t){return e.eval(n.shorthand?n.key:n.value,function(n){r[t]=n})})});return this.isAsync?Promise.all(i).then(function(){return r}):r},r.evalSpreadElement=function(n){return this.eval(n.argument)},r.evalTaggedTemplateExpression=function(n){var e=[this.evalCall(n.tag),this.evalSyncAsync(this.evalArray(n.quasi.expressions),function(e){return[n.quasi.quasis.map(function(n){return n.value.cooked})].concat(e)})],t=function(n){var e=n[0];return e[0].apply(e[1],n[1])};return this.isAsync?Promise.all(e).then(t):t(e)},r.evalTemplateLiteral=function(n){return this.evalSyncAsync(this.evalArray(n.expressions),function(e){return n.quasis.reduce(function(n,t,r){return n+=t.value.cooked,t.tail||(n+=e[r]),n},"")})},t.construct=function(n,e,r){try{return new(Function.prototype.bind.apply(n,[null].concat(e)))}catch(n){throw new Error(t.nodeFunctionName(r.callee)+" is not a constructor")}},t.validateFnAndCall=function(n,e,r){if("function"!=typeof n){if(!n&&r&&r.optional)return[function(){},e];var i=t.nodeFunctionName(r||e);throw new Error("'"+i+"' is not a function")}return[n,e]},t.nodeFunctionName=function(n){return n&&(n.name||n.property&&n.property.name)},t}();t.jsep=n,t.parse=n,t.evaluate=t.eval,t.evaluators={ArrayExpression:t.prototype.evalArrayExpression,LogicalExpression:t.prototype.evalBinaryExpression,BinaryExpression:t.prototype.evalBinaryExpression,CallExpression:t.prototype.evalCallExpression,Compound:t.prototype.evalCompoundExpression,ConditionalExpression:t.prototype.evalConditionalExpression,Identifier:t.prototype.evalIdentifier,Literal:t.evalLiteral,OptionalMemberExpression:t.prototype.evalMemberExpression,MemberExpression:t.prototype.evalMemberExpression,ThisExpression:t.prototype.evalThisExpression,UnaryExpression:t.prototype.evalUnaryExpression,ArrowFunctionExpression:t.prototype.evalArrowFunctionExpression,AssignmentExpression:t.prototype.evalAssignmentExpression,UpdateExpression:t.prototype.evalUpdateExpression,AwaitExpression:t.prototype.evalAwaitExpression,NewExpression:t.prototype.evalNewExpression,ObjectExpression:t.prototype.evalObjectExpression,SpreadElement:t.prototype.evalSpreadElement,TaggedTemplateExpression:t.prototype.evalTaggedTemplateExpression,TemplateLiteral:t.prototype.evalTemplateLiteral},t.DEFAULT_PRECEDENCE={"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},t.binops={"||":function(n,e){return n||e},"&&":function(n,e){return n&&e},"|":function(n,e){return n|e},"^":function(n,e){return n^e},"&":function(n,e){return n&e},"==":function(n,e){return n==e},"!=":function(n,e){return n!=e},"===":function(n,e){return n===e},"!==":function(n,e){return n!==e},"<":function(n,e){return n<e},">":function(n,e){return n>e},"<=":function(n,e){return n<=e},">=":function(n,e){return n>=e},"<<":function(n,e){return n<<e},">>":function(n,e){return n>>e},">>>":function(n,e){return n>>>e},"+":function(n,e){return n+e},"-":function(n,e){return n-e},"*":function(n,e){return n*e},"/":function(n,e){return n/e},"%":function(n,e){return n%e}},t.unops={"-":function(n){return-n},"+":function(n){return+n},"~":function(n){return~n},"!":function(n){return!n}},t.assignOps={"=":function(n,e,t){return n[e]=t},"*=":function(n,e,t){return n[e]*=t},"**=":function(n,e,t){var r;return n[r=e]=Math.pow(n[r],t)},"/=":function(n,e,t){return n[e]/=t},"%=":function(n,e,t){return n[e]%=t},"+=":function(n,e,t){return n[e]+=t},"-=":function(n,e,t){return n[e]-=t},"<<=":function(n,e,t){return n[e]<<=t},">>=":function(n,e,t){return n[e]>>=t},">>>=":function(n,e,t){return n[e]>>>=t},"&=":function(n,e,t){return n[e]&=t},"^=":function(n,e,t){return n[e]^=t},"|=":function(n,e,t){return n[e]|=t}};var r=t.DEFAULT_PRECEDENCE,i=t.evaluators,o=t.binops,a=t.unops,s=t.assignOps,u=t.addUnaryOp,c=t.addBinaryOp,l=t.addEvaluator,p=t.registerPlugin,f=t.eval,v=t.evalAsync,y=t.compile,h=t.compileAsync,d=t.evalExpr,E=t.evalExprAsync;export{r as DEFAULT_PRECEDENCE,c as addBinaryOp,l as addEvaluator,u as addUnaryOp,s as assignOps,o as binops,y as compile,h as compileAsync,t as default,v as evalAsync,d as evalExpr,E as evalExprAsync,f as evaluate,i as evaluators,p as registerPlugin,a as unops};
import e from"jsep";export{default as jsep,default as parse}from"jsep";function n(){return n=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},n.apply(this,arguments)}function t(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}var r={caseSensitive:!0},i=new Map([["undefined",void 0],["null",null],["true",!0],["false",!1]]),o=/*#__PURE__*/function(){function o(e,n,t){this.context=void 0,this.isAsync=void 0,this.options=void 0,this.context=e,this.isAsync=n,this.options=t||r}o.addUnaryOp=function(n,t){e.addUnaryOp(n),o.unops[n]=t},o.addBinaryOp=function(n,t,r,i){var a,s,u;"function"==typeof t?u=t:(a=t,"function"==typeof r?u=r:(s=r,u=i)),e.addBinaryOp(n,a||1,s),o.binops[n]=u},o.addEvaluator=function(e,n){o.evaluators[e]=n},o.registerPlugin=function(){[].slice.call(arguments).forEach(function(e){e.init&&o.parse.plugins.register(e),e.initEval&&e.initEval.call(o,o)})},o.eval=function(e,n,t){return new o(n,void 0,t).eval(e)},o.evalAsync=function(e,n,t){try{return Promise.resolve(new o(n,!0,t).eval(e))}catch(e){return Promise.reject(e)}},o.compile=function(e){return o.eval.bind(null,o.jsep(e))},o.compileAsync=function(e){return o.evalAsync.bind(null,o.jsep(e))},o.evalExpr=function(e,n){return o.compile(e)(n)},o.evalExprAsync=function(e,n){return o.compileAsync(e)(n)};var a,s,u=o.prototype;return u.eval=function(e,n){void 0===n&&(n=function(e){return e});var t=o.evaluators[e.type]||o.evaluators.default;if(!t)throw new Error("unknown node type: "+JSON.stringify(e,null,2));return this.evalSyncAsync(t.bind(this)(e,this.context),function(t){return e._value=t,n(t)})},u.evalSyncAsync=function(e,n){return this.isAsync?Promise.resolve(e).then(n):n(e)},u.evalArrayExpression=function(e){return this.evalArray(e.elements)},u.evalArray=function(e){var n=this,t=e.map(function(e){return n.eval(e)}),r=function(n){return n.reduce(function(n,t,r){return"SpreadElement"===e[r].type?[].concat(n,t):(n.push(t),n)},[])};return this.isAsync?Promise.all(t).then(r):r(t)},u.evalBinaryExpression=function(e){var n=this;if("||"===e.operator)return this.eval(e.left,function(t){return t||n.eval(e.right)});if("&&"===e.operator)return this.eval(e.left,function(t){return t&&n.eval(e.right)});var t=[this.eval(e.left),this.eval(e.right)],r=function(n){return o.binops[e.operator](n[0],n[1])};return this.isAsync?Promise.all(t).then(r):r(t)},u.evalCompoundExpression=function(e){var n=this;return this.isAsync?e.body.reduce(function(e,t){return e.then(function(){return n.eval(t)})},Promise.resolve()):e.body.map(function(e){return n.eval(e)})[e.body.length-1]},u.evalCallExpression=function(e){var n=this;return this.evalSyncAsync(this.evalCall(e.callee),function(t){var r=t[0],i=t[1];return n.evalSyncAsync(n.evalArray(e.arguments),function(e){return r.apply(i,e)})})},u.evalCall=function(e){return"MemberExpression"===e.type?this.evalSyncAsync(this.evaluateMember(e),function(n){return o.validateFnAndCall(n[1],n[0],e)}):this.eval(e,function(n){return o.validateFnAndCall(n,e)})},u.evalConditionalExpression=function(e){var n=this;return this.eval(e.test,function(t){return n.eval(t?e.consequent:e.alternate)})},u.evalIdentifier=function(e){if(this.caseSensitive)return this.context[e.name];if(0===e.name.localeCompare("this","en",{sensitivity:"base"}))return this.evalThisExpression();var n=o.getLiteralPair(i,e.name,this.caseSensitive);return n?n[1]:o.getValue(this.context,e.name,this.caseSensitive)},o.evalLiteral=function(e){return e.value},u.evalMemberExpression=function(e){return this.evalSyncAsync(this.evaluateMember(e),function(e){return e[1]})},u.evaluateMember=function(e){var n=this;return this.eval(e.object,function(t){return n.evalSyncAsync(e.computed?n.eval(e.property):e.property.name,function(r){if(/^__proto__|prototype|constructor$/.test(r))throw Error('Access to member "'+r+'" disallowed.');var i=o.getValue(e.optional?t||{}:t,r,n.caseSensitive);return[t,i,r]})})},u.evalThisExpression=function(){return this.context},u.evalUnaryExpression=function(e){return this.eval(e.argument,function(n){return o.unops[e.operator](n)})},u.evalArrowFunctionExpression=function(e){var n=this;return this.isAsync!==e.async?o[e.async?"evalAsync":"eval"](e,this.context):function(){var t=n.evalArrowContext(e,[].slice.call(arguments));return o[e.async?"evalAsync":"eval"](e.body,t)}},u.evalArrowContext=function(e,t){var r=this,i=n({},this.context);return(e.params||[]).forEach(function(e,o){if("AssignmentExpression"===e.type&&(void 0===t[o]&&(t[o]=r.eval(e.right)),e=e.left),"Identifier"===e.type)i[e.name]=t[o];else if("ArrayExpression"===e.type)e.elements.forEach(function(e,n){var a=t[o][n];if("AssignmentExpression"===e.type&&(void 0===a&&(a=r.eval(e.right)),e=e.left),"Identifier"!==e.type)throw new Error("Unexpected arrow function argument");i[e.name]=a});else if("ObjectExpression"===e.type){var a=[];e.properties.forEach(function(e){var s,u=e;if("AssignmentExpression"===u.type&&(u=u.left),"Property"===u.type)s="Identifier"===u.key.type?u.key.name:r.eval(u.key).toString();else if("Identifier"===u.type)s=u.name;else{if("SpreadElement"!==u.type||"Identifier"!==u.argument.type)throw new Error("Unexpected arrow function argument");s=u.argument.name}var l=t[o][s];"SpreadElement"===u.type?(l=n({},t[o]),a.forEach(function(e){delete l[e]})):void 0===l&&"AssignmentExpression"===e.type&&(l=r.eval(e.right)),i[s]=l,a.push(s)})}else{if("SpreadElement"!==e.type||"Identifier"!==e.argument.type)throw new Error("Unexpected arrow function argument");i[e.argument.name]=t.slice(o)}}),i},u.evalAssignmentExpression=function(e){var n=this;return this.evalSyncAsync(this.getContextAndKey(e.left),function(t){var r=t[0],i=t[1];return n.eval(e.right,function(n){return o.assignOps[e.operator](r,i,n)})})},u.evalUpdateExpression=function(e){return this.evalSyncAsync(this.getContextAndKey(e.argument),function(n){return o.evalUpdateOperation(e,n[0],n[1])})},u.evalAwaitExpression=function(e){return o.evalAsync(e.argument,this.context)},o.evalUpdateOperation=function(e,n,t){return e.prefix?"++"===e.operator?++n[t]:--n[t]:"++"===e.operator?n[t]++:n[t]--},u.getContextAndKey=function(e){var n=this;if("MemberExpression"===e.type)return this.evalSyncAsync(this.evaluateMember(e),function(e){var t=e[0];return[t,o.getKeyValuePair(t,e[2],n.caseSensitive)[0]]});if("Identifier"===e.type){var t=o.getKeyValuePair(this.context,e.name,this.caseSensitive);return[this.context,t[0]]}if("ConditionalExpression"===e.type)return this.eval(e.test,function(t){return n.getContextAndKey(t?e.consequent:e.alternate)});throw new Error("Invalid Member Key")},u.evalNewExpression=function(e){var n=this;return this.evalSyncAsync(this.evalCall(e.callee),function(t){var r=t[0];return n.evalSyncAsync(n.evalArray(e.arguments),function(n){return o.construct(r,n,e)})})},u.evalObjectExpression=function(e){var n=this,t={},r=e.properties.map(function(e){if("SpreadElement"===e.type)Object.assign(t,o.eval(e.argument,n.context,n.options));else if("Property"===e.type)return n.evalSyncAsync("Identifier"===e.key.type?e.key.name:n.eval(e.key),function(r){return n.eval(e.shorthand?e.key:e.value,function(e){t[r]=e})})});return this.isAsync?Promise.all(r).then(function(){return t}):t},u.evalSpreadElement=function(e){return this.eval(e.argument)},u.evalTaggedTemplateExpression=function(e){var n=[this.evalCall(e.tag),this.evalSyncAsync(this.evalArray(e.quasi.expressions),function(n){return[e.quasi.quasis.map(function(e){return e.value.cooked})].concat(n)})],t=function(e){var n=e[0];return n[0].apply(n[1],e[1])};return this.isAsync?Promise.all(n).then(t):t(n)},u.evalTemplateLiteral=function(e){return this.evalSyncAsync(this.evalArray(e.expressions),function(n){return e.quasis.reduce(function(e,t,r){return e+=t.value.cooked,t.tail||(e+=n[r]),e},"")})},o.construct=function(e,n,t){try{return new(Function.prototype.bind.apply(e,[null].concat(n)))}catch(e){throw new Error(o.nodeFunctionName(t.callee)+" is not a constructor")}},o.validateFnAndCall=function(e,n,t){if("function"!=typeof e){if(!e&&t&&t.optional)return[function(){},n];var r=o.nodeFunctionName(t||n);throw new Error("'"+r+"' is not a function")}return[e,n]},o.nodeFunctionName=function(e){return e&&(e.name||e.property&&e.property.name)},o.getValue=function(e,n,t){return o.getKeyValuePair(e,n,t)[1]},o.getKeyValuePair=function(e,n,t){if(t||"string"!=typeof n)return[n,e[n]];if("string"==typeof n){var r=e;do{var i=Object.getOwnPropertyNames(r);if(Array.isArray(i)){var o=i.find(function(e){return 0===e.localeCompare(n,"en",{sensitivity:"base"})});if(o)return[o,e[o]]}}while(r=Object.getPrototypeOf(r))}return[n,void 0]},o.getLiteralPair=function(e,n,r){if(r)return e[n];for(var i,o=function(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}(e))){r&&(e=r);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e);!(i=o()).done;){var a=i.value,s=a[0],u=a[1];if(0===s.localeCompare(n,"en",{sensitivity:"base"}))return[s,u]}},a=o,(s=[{key:"caseSensitive",get:function(){return!(!this.options||!this.options.caseSensitive)}}])&&function(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(a.prototype,s),Object.defineProperty(a,"prototype",{writable:!1}),o}();o.jsep=e,o.parse=e,o.evaluate=o.eval,o.evaluators={ArrayExpression:o.prototype.evalArrayExpression,LogicalExpression:o.prototype.evalBinaryExpression,BinaryExpression:o.prototype.evalBinaryExpression,CallExpression:o.prototype.evalCallExpression,Compound:o.prototype.evalCompoundExpression,ConditionalExpression:o.prototype.evalConditionalExpression,Identifier:o.prototype.evalIdentifier,Literal:o.evalLiteral,OptionalMemberExpression:o.prototype.evalMemberExpression,MemberExpression:o.prototype.evalMemberExpression,ThisExpression:o.prototype.evalThisExpression,UnaryExpression:o.prototype.evalUnaryExpression,ArrowFunctionExpression:o.prototype.evalArrowFunctionExpression,AssignmentExpression:o.prototype.evalAssignmentExpression,UpdateExpression:o.prototype.evalUpdateExpression,AwaitExpression:o.prototype.evalAwaitExpression,NewExpression:o.prototype.evalNewExpression,ObjectExpression:o.prototype.evalObjectExpression,SpreadElement:o.prototype.evalSpreadElement,TaggedTemplateExpression:o.prototype.evalTaggedTemplateExpression,TemplateLiteral:o.prototype.evalTemplateLiteral},o.DEFAULT_PRECEDENCE={"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},o.binops={"||":function(e,n){return e||n},"&&":function(e,n){return e&&n},"|":function(e,n){return e|n},"^":function(e,n){return e^n},"&":function(e,n){return e&n},"==":function(e,n){return e==n},"!=":function(e,n){return e!=n},"===":function(e,n){return e===n},"!==":function(e,n){return e!==n},"<":function(e,n){return e<n},">":function(e,n){return e>n},"<=":function(e,n){return e<=n},">=":function(e,n){return e>=n},"<<":function(e,n){return e<<n},">>":function(e,n){return e>>n},">>>":function(e,n){return e>>>n},"+":function(e,n){return e+n},"-":function(e,n){return e-n},"*":function(e,n){return e*n},"/":function(e,n){return e/n},"%":function(e,n){return e%n}},o.unops={"-":function(e){return-e},"+":function(e){return+e},"~":function(e){return~e},"!":function(e){return!e}},o.assignOps={"=":function(e,n,t){return e[n]=t},"*=":function(e,n,t){return e[n]*=t},"**=":function(e,n,t){var r;return e[r=n]=Math.pow(e[r],t)},"/=":function(e,n,t){return e[n]/=t},"%=":function(e,n,t){return e[n]%=t},"+=":function(e,n,t){return e[n]+=t},"-=":function(e,n,t){return e[n]-=t},"<<=":function(e,n,t){return e[n]<<=t},">>=":function(e,n,t){return e[n]>>=t},">>>=":function(e,n,t){return e[n]>>>=t},"&=":function(e,n,t){return e[n]&=t},"^=":function(e,n,t){return e[n]^=t},"|=":function(e,n,t){return e[n]|=t}};var a=o.DEFAULT_PRECEDENCE,s=o.evaluators,u=o.binops,l=o.unops,c=o.assignOps,p=o.addUnaryOp,f=o.addBinaryOp,v=o.addEvaluator,y=o.registerPlugin,h=o.eval,d=o.evalAsync,m=o.compile,E=o.compileAsync,x=o.evalExpr,A=o.evalExprAsync;export{a as DEFAULT_PRECEDENCE,f as addBinaryOp,v as addEvaluator,p as addUnaryOp,c as assignOps,u as binops,m as compile,E as compileAsync,o as default,d as evalAsync,x as evalExpr,A as evalExprAsync,h as evaluate,s as evaluators,y as registerPlugin,l as unops};
//# sourceMappingURL=jse-eval.module.js.map

@@ -1,2 +0,2 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("jsep")):"function"==typeof define&&define.amd?define(["exports","jsep"],n):n((e||self).jseEval={},e.jsep)}(this,function(e,n){function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=/*#__PURE__*/t(n);function i(){return i=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},i.apply(this,arguments)}var o=/*#__PURE__*/function(){function e(e,n){this.context=void 0,this.isAsync=void 0,this.context=e,this.isAsync=n}e.addUnaryOp=function(n,t){r.default.addUnaryOp(n),e.unops[n]=t},e.addBinaryOp=function(n,t,i,o){var a,s,u;"function"==typeof t?u=t:(a=t,"function"==typeof i?u=i:(s=i,u=o)),r.default.addBinaryOp(n,a||1,s),e.binops[n]=u},e.addEvaluator=function(n,t){e.evaluators[n]=t},e.registerPlugin=function(){[].slice.call(arguments).forEach(function(n){n.init&&e.parse.plugins.register(n),n.initEval&&n.initEval.call(e,e)})},e.eval=function(n,t){return new e(t).eval(n)},e.evalAsync=function(n,t){try{return Promise.resolve(new e(t,!0).eval(n))}catch(e){return Promise.reject(e)}},e.compile=function(n){return e.eval.bind(null,e.jsep(n))},e.compileAsync=function(n){return e.evalAsync.bind(null,e.jsep(n))},e.evalExpr=function(n,t){return e.compile(n)(t)},e.evalExprAsync=function(n,t){return e.compileAsync(n)(t)};var n=e.prototype;return n.eval=function(n,t){void 0===t&&(t=function(e){return e});var r=e.evaluators[n.type]||e.evaluators.default;if(!r)throw new Error("unknown node type: "+JSON.stringify(n,null,2));return this.evalSyncAsync(r.bind(this)(n,this.context),function(e){return n._value=e,t(e)})},n.evalSyncAsync=function(e,n){return this.isAsync?Promise.resolve(e).then(n):n(e)},n.evalArrayExpression=function(e){return this.evalArray(e.elements)},n.evalArray=function(e){var n=this,t=e.map(function(e){return n.eval(e)}),r=function(n){return n.reduce(function(n,t,r){return"SpreadElement"===e[r].type?[].concat(n,t):(n.push(t),n)},[])};return this.isAsync?Promise.all(t).then(r):r(t)},n.evalBinaryExpression=function(n){var t=this;if("||"===n.operator)return this.eval(n.left,function(e){return e||t.eval(n.right)});if("&&"===n.operator)return this.eval(n.left,function(e){return e&&t.eval(n.right)});var r=[this.eval(n.left),this.eval(n.right)],i=function(t){return e.binops[n.operator](t[0],t[1])};return this.isAsync?Promise.all(r).then(i):i(r)},n.evalCompoundExpression=function(e){var n=this;return this.isAsync?e.body.reduce(function(e,t){return e.then(function(){return n.eval(t)})},Promise.resolve()):e.body.map(function(e){return n.eval(e)})[e.body.length-1]},n.evalCallExpression=function(e){var n=this;return this.evalSyncAsync(this.evalCall(e.callee),function(t){var r=t[0],i=t[1];return n.evalSyncAsync(n.evalArray(e.arguments),function(e){return r.apply(i,e)})})},n.evalCall=function(n){return"MemberExpression"===n.type?this.evalSyncAsync(this.evaluateMember(n),function(t){return e.validateFnAndCall(t[1],t[0],n)}):this.eval(n,function(t){return e.validateFnAndCall(t,n)})},n.evalConditionalExpression=function(e){var n=this;return this.eval(e.test,function(t){return n.eval(t?e.consequent:e.alternate)})},n.evalIdentifier=function(e){return this.context[e.name]},e.evalLiteral=function(e){return e.value},n.evalMemberExpression=function(e){return this.evalSyncAsync(this.evaluateMember(e),function(e){return e[1]})},n.evaluateMember=function(e){var n=this;return this.eval(e.object,function(t){return n.evalSyncAsync(e.computed?n.eval(e.property):e.property.name,function(n){if(/^__proto__|prototype|constructor$/.test(n))throw Error('Access to member "'+n+'" disallowed.');return[t,(e.optional?t||{}:t)[n],n]})})},n.evalThisExpression=function(){return this.context},n.evalUnaryExpression=function(n){return this.eval(n.argument,function(t){return e.unops[n.operator](t)})},n.evalArrowFunctionExpression=function(n){var t=this;return this.isAsync!==n.async?e[n.async?"evalAsync":"eval"](n,this.context):function(){var r=t.evalArrowContext(n,[].slice.call(arguments));return e[n.async?"evalAsync":"eval"](n.body,r)}},n.evalArrowContext=function(e,n){var t=this,r=i({},this.context);return(e.params||[]).forEach(function(e,o){if("AssignmentExpression"===e.type&&(void 0===n[o]&&(n[o]=t.eval(e.right)),e=e.left),"Identifier"===e.type)r[e.name]=n[o];else if("ArrayExpression"===e.type)e.elements.forEach(function(e,i){var a=n[o][i];if("AssignmentExpression"===e.type&&(void 0===a&&(a=t.eval(e.right)),e=e.left),"Identifier"!==e.type)throw new Error("Unexpected arrow function argument");r[e.name]=a});else if("ObjectExpression"===e.type){var a=[];e.properties.forEach(function(e){var s,u=e;if("AssignmentExpression"===u.type&&(u=u.left),"Property"===u.type)s="Identifier"===u.key.type?u.key.name:t.eval(u.key).toString();else if("Identifier"===u.type)s=u.name;else{if("SpreadElement"!==u.type||"Identifier"!==u.argument.type)throw new Error("Unexpected arrow function argument");s=u.argument.name}var l=n[o][s];"SpreadElement"===u.type?(l=i({},n[o]),a.forEach(function(e){delete l[e]})):void 0===l&&"AssignmentExpression"===e.type&&(l=t.eval(e.right)),r[s]=l,a.push(s)})}else{if("SpreadElement"!==e.type||"Identifier"!==e.argument.type)throw new Error("Unexpected arrow function argument");r[e.argument.name]=n.slice(o)}}),r},n.evalAssignmentExpression=function(n){var t=this;return this.evalSyncAsync(this.getContextAndKey(n.left),function(r){var i=r[0],o=r[1];return t.eval(n.right,function(t){return e.assignOps[n.operator](i,o,t)})})},n.evalUpdateExpression=function(n){return this.evalSyncAsync(this.getContextAndKey(n.argument),function(t){return e.evalUpdateOperation(n,t[0],t[1])})},n.evalAwaitExpression=function(n){return e.evalAsync(n.argument,this.context)},e.evalUpdateOperation=function(e,n,t){return e.prefix?"++"===e.operator?++n[t]:--n[t]:"++"===e.operator?n[t]++:n[t]--},n.getContextAndKey=function(e){var n=this;if("MemberExpression"===e.type)return this.evalSyncAsync(this.evaluateMember(e),function(e){return[e[0],e[2]]});if("Identifier"===e.type)return[this.context,e.name];if("ConditionalExpression"===e.type)return this.eval(e.test,function(t){return n.getContextAndKey(t?e.consequent:e.alternate)});throw new Error("Invalid Member Key")},n.evalNewExpression=function(n){var t=this;return this.evalSyncAsync(this.evalCall(n.callee),function(r){var i=r[0];return t.evalSyncAsync(t.evalArray(n.arguments),function(t){return e.construct(i,t,n)})})},n.evalObjectExpression=function(n){var t=this,r={},i=n.properties.map(function(n){if("SpreadElement"===n.type)Object.assign(r,e.eval(n.argument,t.context));else if("Property"===n.type)return t.evalSyncAsync("Identifier"===n.key.type?n.key.name:t.eval(n.key),function(e){return t.eval(n.shorthand?n.key:n.value,function(n){r[e]=n})})});return this.isAsync?Promise.all(i).then(function(){return r}):r},n.evalSpreadElement=function(e){return this.eval(e.argument)},n.evalTaggedTemplateExpression=function(e){var n=[this.evalCall(e.tag),this.evalSyncAsync(this.evalArray(e.quasi.expressions),function(n){return[e.quasi.quasis.map(function(e){return e.value.cooked})].concat(n)})],t=function(e){var n=e[0];return n[0].apply(n[1],e[1])};return this.isAsync?Promise.all(n).then(t):t(n)},n.evalTemplateLiteral=function(e){return this.evalSyncAsync(this.evalArray(e.expressions),function(n){return e.quasis.reduce(function(e,t,r){return e+=t.value.cooked,t.tail||(e+=n[r]),e},"")})},e.construct=function(n,t,r){try{return new(Function.prototype.bind.apply(n,[null].concat(t)))}catch(n){throw new Error(e.nodeFunctionName(r.callee)+" is not a constructor")}},e.validateFnAndCall=function(n,t,r){if("function"!=typeof n){if(!n&&r&&r.optional)return[function(){},t];var i=e.nodeFunctionName(r||t);throw new Error("'"+i+"' is not a function")}return[n,t]},e.nodeFunctionName=function(e){return e&&(e.name||e.property&&e.property.name)},e}();o.jsep=r.default,o.parse=r.default,o.evaluate=o.eval,o.evaluators={ArrayExpression:o.prototype.evalArrayExpression,LogicalExpression:o.prototype.evalBinaryExpression,BinaryExpression:o.prototype.evalBinaryExpression,CallExpression:o.prototype.evalCallExpression,Compound:o.prototype.evalCompoundExpression,ConditionalExpression:o.prototype.evalConditionalExpression,Identifier:o.prototype.evalIdentifier,Literal:o.evalLiteral,OptionalMemberExpression:o.prototype.evalMemberExpression,MemberExpression:o.prototype.evalMemberExpression,ThisExpression:o.prototype.evalThisExpression,UnaryExpression:o.prototype.evalUnaryExpression,ArrowFunctionExpression:o.prototype.evalArrowFunctionExpression,AssignmentExpression:o.prototype.evalAssignmentExpression,UpdateExpression:o.prototype.evalUpdateExpression,AwaitExpression:o.prototype.evalAwaitExpression,NewExpression:o.prototype.evalNewExpression,ObjectExpression:o.prototype.evalObjectExpression,SpreadElement:o.prototype.evalSpreadElement,TaggedTemplateExpression:o.prototype.evalTaggedTemplateExpression,TemplateLiteral:o.prototype.evalTemplateLiteral},o.DEFAULT_PRECEDENCE={"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},o.binops={"||":function(e,n){return e||n},"&&":function(e,n){return e&&n},"|":function(e,n){return e|n},"^":function(e,n){return e^n},"&":function(e,n){return e&n},"==":function(e,n){return e==n},"!=":function(e,n){return e!=n},"===":function(e,n){return e===n},"!==":function(e,n){return e!==n},"<":function(e,n){return e<n},">":function(e,n){return e>n},"<=":function(e,n){return e<=n},">=":function(e,n){return e>=n},"<<":function(e,n){return e<<n},">>":function(e,n){return e>>n},">>>":function(e,n){return e>>>n},"+":function(e,n){return e+n},"-":function(e,n){return e-n},"*":function(e,n){return e*n},"/":function(e,n){return e/n},"%":function(e,n){return e%n}},o.unops={"-":function(e){return-e},"+":function(e){return+e},"~":function(e){return~e},"!":function(e){return!e}},o.assignOps={"=":function(e,n,t){return e[n]=t},"*=":function(e,n,t){return e[n]*=t},"**=":function(e,n,t){var r;return e[r=n]=Math.pow(e[r],t)},"/=":function(e,n,t){return e[n]/=t},"%=":function(e,n,t){return e[n]%=t},"+=":function(e,n,t){return e[n]+=t},"-=":function(e,n,t){return e[n]-=t},"<<=":function(e,n,t){return e[n]<<=t},">>=":function(e,n,t){return e[n]>>=t},">>>=":function(e,n,t){return e[n]>>>=t},"&=":function(e,n,t){return e[n]&=t},"^=":function(e,n,t){return e[n]^=t},"|=":function(e,n,t){return e[n]|=t}};var a=o.DEFAULT_PRECEDENCE,s=o.evaluators,u=o.binops,l=o.unops,c=o.assignOps,p=o.addUnaryOp,f=o.addBinaryOp,v=o.addEvaluator,y=o.registerPlugin,d=o.eval,h=o.evalAsync,E=o.compile,m=o.compileAsync,x=o.evalExpr,A=o.evalExprAsync;Object.defineProperty(e,"jsep",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(e,"parse",{enumerable:!0,get:function(){return r.default}}),e.DEFAULT_PRECEDENCE=a,e.addBinaryOp=f,e.addEvaluator=v,e.addUnaryOp=p,e.assignOps=c,e.binops=u,e.compile=E,e.compileAsync=m,e.default=o,e.evalAsync=h,e.evalExpr=x,e.evalExprAsync=A,e.evaluate=d,e.evaluators=s,e.registerPlugin=y,e.unops=l});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("jsep")):"function"==typeof define&&define.amd?define(["exports","jsep"],n):n((e||self).jseEval={},e.jsep)}(this,function(e,n){function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=/*#__PURE__*/t(n);function i(){return i=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},i.apply(this,arguments)}function o(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}var a={caseSensitive:!0},s=new Map([["undefined",void 0],["null",null],["true",!0],["false",!1]]),u=/*#__PURE__*/function(){function e(e,n,t){this.context=void 0,this.isAsync=void 0,this.options=void 0,this.context=e,this.isAsync=n,this.options=t||a}e.addUnaryOp=function(n,t){r.default.addUnaryOp(n),e.unops[n]=t},e.addBinaryOp=function(n,t,i,o){var a,s,u;"function"==typeof t?u=t:(a=t,"function"==typeof i?u=i:(s=i,u=o)),r.default.addBinaryOp(n,a||1,s),e.binops[n]=u},e.addEvaluator=function(n,t){e.evaluators[n]=t},e.registerPlugin=function(){[].slice.call(arguments).forEach(function(n){n.init&&e.parse.plugins.register(n),n.initEval&&n.initEval.call(e,e)})},e.eval=function(n,t,r){return new e(t,void 0,r).eval(n)},e.evalAsync=function(n,t,r){try{return Promise.resolve(new e(t,!0,r).eval(n))}catch(e){return Promise.reject(e)}},e.compile=function(n){return e.eval.bind(null,e.jsep(n))},e.compileAsync=function(n){return e.evalAsync.bind(null,e.jsep(n))},e.evalExpr=function(n,t){return e.compile(n)(t)},e.evalExprAsync=function(n,t){return e.compileAsync(n)(t)};var n,t,u=e.prototype;return u.eval=function(n,t){void 0===t&&(t=function(e){return e});var r=e.evaluators[n.type]||e.evaluators.default;if(!r)throw new Error("unknown node type: "+JSON.stringify(n,null,2));return this.evalSyncAsync(r.bind(this)(n,this.context),function(e){return n._value=e,t(e)})},u.evalSyncAsync=function(e,n){return this.isAsync?Promise.resolve(e).then(n):n(e)},u.evalArrayExpression=function(e){return this.evalArray(e.elements)},u.evalArray=function(e){var n=this,t=e.map(function(e){return n.eval(e)}),r=function(n){return n.reduce(function(n,t,r){return"SpreadElement"===e[r].type?[].concat(n,t):(n.push(t),n)},[])};return this.isAsync?Promise.all(t).then(r):r(t)},u.evalBinaryExpression=function(n){var t=this;if("||"===n.operator)return this.eval(n.left,function(e){return e||t.eval(n.right)});if("&&"===n.operator)return this.eval(n.left,function(e){return e&&t.eval(n.right)});var r=[this.eval(n.left),this.eval(n.right)],i=function(t){return e.binops[n.operator](t[0],t[1])};return this.isAsync?Promise.all(r).then(i):i(r)},u.evalCompoundExpression=function(e){var n=this;return this.isAsync?e.body.reduce(function(e,t){return e.then(function(){return n.eval(t)})},Promise.resolve()):e.body.map(function(e){return n.eval(e)})[e.body.length-1]},u.evalCallExpression=function(e){var n=this;return this.evalSyncAsync(this.evalCall(e.callee),function(t){var r=t[0],i=t[1];return n.evalSyncAsync(n.evalArray(e.arguments),function(e){return r.apply(i,e)})})},u.evalCall=function(n){return"MemberExpression"===n.type?this.evalSyncAsync(this.evaluateMember(n),function(t){return e.validateFnAndCall(t[1],t[0],n)}):this.eval(n,function(t){return e.validateFnAndCall(t,n)})},u.evalConditionalExpression=function(e){var n=this;return this.eval(e.test,function(t){return n.eval(t?e.consequent:e.alternate)})},u.evalIdentifier=function(n){if(this.caseSensitive)return this.context[n.name];if(0===n.name.localeCompare("this","en",{sensitivity:"base"}))return this.evalThisExpression();var t=e.getLiteralPair(s,n.name,this.caseSensitive);return t?t[1]:e.getValue(this.context,n.name,this.caseSensitive)},e.evalLiteral=function(e){return e.value},u.evalMemberExpression=function(e){return this.evalSyncAsync(this.evaluateMember(e),function(e){return e[1]})},u.evaluateMember=function(n){var t=this;return this.eval(n.object,function(r){return t.evalSyncAsync(n.computed?t.eval(n.property):n.property.name,function(i){if(/^__proto__|prototype|constructor$/.test(i))throw Error('Access to member "'+i+'" disallowed.');var o=e.getValue(n.optional?r||{}:r,i,t.caseSensitive);return[r,o,i]})})},u.evalThisExpression=function(){return this.context},u.evalUnaryExpression=function(n){return this.eval(n.argument,function(t){return e.unops[n.operator](t)})},u.evalArrowFunctionExpression=function(n){var t=this;return this.isAsync!==n.async?e[n.async?"evalAsync":"eval"](n,this.context):function(){var r=t.evalArrowContext(n,[].slice.call(arguments));return e[n.async?"evalAsync":"eval"](n.body,r)}},u.evalArrowContext=function(e,n){var t=this,r=i({},this.context);return(e.params||[]).forEach(function(e,o){if("AssignmentExpression"===e.type&&(void 0===n[o]&&(n[o]=t.eval(e.right)),e=e.left),"Identifier"===e.type)r[e.name]=n[o];else if("ArrayExpression"===e.type)e.elements.forEach(function(e,i){var a=n[o][i];if("AssignmentExpression"===e.type&&(void 0===a&&(a=t.eval(e.right)),e=e.left),"Identifier"!==e.type)throw new Error("Unexpected arrow function argument");r[e.name]=a});else if("ObjectExpression"===e.type){var a=[];e.properties.forEach(function(e){var s,u=e;if("AssignmentExpression"===u.type&&(u=u.left),"Property"===u.type)s="Identifier"===u.key.type?u.key.name:t.eval(u.key).toString();else if("Identifier"===u.type)s=u.name;else{if("SpreadElement"!==u.type||"Identifier"!==u.argument.type)throw new Error("Unexpected arrow function argument");s=u.argument.name}var l=n[o][s];"SpreadElement"===u.type?(l=i({},n[o]),a.forEach(function(e){delete l[e]})):void 0===l&&"AssignmentExpression"===e.type&&(l=t.eval(e.right)),r[s]=l,a.push(s)})}else{if("SpreadElement"!==e.type||"Identifier"!==e.argument.type)throw new Error("Unexpected arrow function argument");r[e.argument.name]=n.slice(o)}}),r},u.evalAssignmentExpression=function(n){var t=this;return this.evalSyncAsync(this.getContextAndKey(n.left),function(r){var i=r[0],o=r[1];return t.eval(n.right,function(t){return e.assignOps[n.operator](i,o,t)})})},u.evalUpdateExpression=function(n){return this.evalSyncAsync(this.getContextAndKey(n.argument),function(t){return e.evalUpdateOperation(n,t[0],t[1])})},u.evalAwaitExpression=function(n){return e.evalAsync(n.argument,this.context)},e.evalUpdateOperation=function(e,n,t){return e.prefix?"++"===e.operator?++n[t]:--n[t]:"++"===e.operator?n[t]++:n[t]--},u.getContextAndKey=function(n){var t=this;if("MemberExpression"===n.type)return this.evalSyncAsync(this.evaluateMember(n),function(n){var r=n[0];return[r,e.getKeyValuePair(r,n[2],t.caseSensitive)[0]]});if("Identifier"===n.type){var r=e.getKeyValuePair(this.context,n.name,this.caseSensitive);return[this.context,r[0]]}if("ConditionalExpression"===n.type)return this.eval(n.test,function(e){return t.getContextAndKey(e?n.consequent:n.alternate)});throw new Error("Invalid Member Key")},u.evalNewExpression=function(n){var t=this;return this.evalSyncAsync(this.evalCall(n.callee),function(r){var i=r[0];return t.evalSyncAsync(t.evalArray(n.arguments),function(t){return e.construct(i,t,n)})})},u.evalObjectExpression=function(n){var t=this,r={},i=n.properties.map(function(n){if("SpreadElement"===n.type)Object.assign(r,e.eval(n.argument,t.context,t.options));else if("Property"===n.type)return t.evalSyncAsync("Identifier"===n.key.type?n.key.name:t.eval(n.key),function(e){return t.eval(n.shorthand?n.key:n.value,function(n){r[e]=n})})});return this.isAsync?Promise.all(i).then(function(){return r}):r},u.evalSpreadElement=function(e){return this.eval(e.argument)},u.evalTaggedTemplateExpression=function(e){var n=[this.evalCall(e.tag),this.evalSyncAsync(this.evalArray(e.quasi.expressions),function(n){return[e.quasi.quasis.map(function(e){return e.value.cooked})].concat(n)})],t=function(e){var n=e[0];return n[0].apply(n[1],e[1])};return this.isAsync?Promise.all(n).then(t):t(n)},u.evalTemplateLiteral=function(e){return this.evalSyncAsync(this.evalArray(e.expressions),function(n){return e.quasis.reduce(function(e,t,r){return e+=t.value.cooked,t.tail||(e+=n[r]),e},"")})},e.construct=function(n,t,r){try{return new(Function.prototype.bind.apply(n,[null].concat(t)))}catch(n){throw new Error(e.nodeFunctionName(r.callee)+" is not a constructor")}},e.validateFnAndCall=function(n,t,r){if("function"!=typeof n){if(!n&&r&&r.optional)return[function(){},t];var i=e.nodeFunctionName(r||t);throw new Error("'"+i+"' is not a function")}return[n,t]},e.nodeFunctionName=function(e){return e&&(e.name||e.property&&e.property.name)},e.getValue=function(n,t,r){return e.getKeyValuePair(n,t,r)[1]},e.getKeyValuePair=function(e,n,t){if(t||"string"!=typeof n)return[n,e[n]];if("string"==typeof n){var r=e;do{var i=Object.getOwnPropertyNames(r);if(Array.isArray(i)){var o=i.find(function(e){return 0===e.localeCompare(n,"en",{sensitivity:"base"})});if(o)return[o,e[o]]}}while(r=Object.getPrototypeOf(r))}return[n,void 0]},e.getLiteralPair=function(e,n,t){if(t)return e[n];for(var r,i=function(e,n){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return o(e,n);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,n):void 0}}(e))){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e);!(r=i()).done;){var a=r.value,s=a[0],u=a[1];if(0===s.localeCompare(n,"en",{sensitivity:"base"}))return[s,u]}},n=e,(t=[{key:"caseSensitive",get:function(){return!(!this.options||!this.options.caseSensitive)}}])&&function(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(n.prototype,t),Object.defineProperty(n,"prototype",{writable:!1}),e}();u.jsep=r.default,u.parse=r.default,u.evaluate=u.eval,u.evaluators={ArrayExpression:u.prototype.evalArrayExpression,LogicalExpression:u.prototype.evalBinaryExpression,BinaryExpression:u.prototype.evalBinaryExpression,CallExpression:u.prototype.evalCallExpression,Compound:u.prototype.evalCompoundExpression,ConditionalExpression:u.prototype.evalConditionalExpression,Identifier:u.prototype.evalIdentifier,Literal:u.evalLiteral,OptionalMemberExpression:u.prototype.evalMemberExpression,MemberExpression:u.prototype.evalMemberExpression,ThisExpression:u.prototype.evalThisExpression,UnaryExpression:u.prototype.evalUnaryExpression,ArrowFunctionExpression:u.prototype.evalArrowFunctionExpression,AssignmentExpression:u.prototype.evalAssignmentExpression,UpdateExpression:u.prototype.evalUpdateExpression,AwaitExpression:u.prototype.evalAwaitExpression,NewExpression:u.prototype.evalNewExpression,ObjectExpression:u.prototype.evalObjectExpression,SpreadElement:u.prototype.evalSpreadElement,TaggedTemplateExpression:u.prototype.evalTaggedTemplateExpression,TemplateLiteral:u.prototype.evalTemplateLiteral},u.DEFAULT_PRECEDENCE={"||":1,"&&":2,"|":3,"^":4,"&":5,"==":6,"!=":6,"===":6,"!==":6,"<":7,">":7,"<=":7,">=":7,"<<":8,">>":8,">>>":8,"+":9,"-":9,"*":10,"/":10,"%":10},u.binops={"||":function(e,n){return e||n},"&&":function(e,n){return e&&n},"|":function(e,n){return e|n},"^":function(e,n){return e^n},"&":function(e,n){return e&n},"==":function(e,n){return e==n},"!=":function(e,n){return e!=n},"===":function(e,n){return e===n},"!==":function(e,n){return e!==n},"<":function(e,n){return e<n},">":function(e,n){return e>n},"<=":function(e,n){return e<=n},">=":function(e,n){return e>=n},"<<":function(e,n){return e<<n},">>":function(e,n){return e>>n},">>>":function(e,n){return e>>>n},"+":function(e,n){return e+n},"-":function(e,n){return e-n},"*":function(e,n){return e*n},"/":function(e,n){return e/n},"%":function(e,n){return e%n}},u.unops={"-":function(e){return-e},"+":function(e){return+e},"~":function(e){return~e},"!":function(e){return!e}},u.assignOps={"=":function(e,n,t){return e[n]=t},"*=":function(e,n,t){return e[n]*=t},"**=":function(e,n,t){var r;return e[r=n]=Math.pow(e[r],t)},"/=":function(e,n,t){return e[n]/=t},"%=":function(e,n,t){return e[n]%=t},"+=":function(e,n,t){return e[n]+=t},"-=":function(e,n,t){return e[n]-=t},"<<=":function(e,n,t){return e[n]<<=t},">>=":function(e,n,t){return e[n]>>=t},">>>=":function(e,n,t){return e[n]>>>=t},"&=":function(e,n,t){return e[n]&=t},"^=":function(e,n,t){return e[n]^=t},"|=":function(e,n,t){return e[n]|=t}};var l=u.DEFAULT_PRECEDENCE,c=u.evaluators,p=u.binops,f=u.unops,v=u.assignOps,y=u.addUnaryOp,d=u.addBinaryOp,h=u.addEvaluator,m=u.registerPlugin,E=u.eval,x=u.evalAsync,g=u.compile,A=u.compileAsync,b=u.evalExpr,w=u.evalExprAsync;Object.defineProperty(e,"jsep",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(e,"parse",{enumerable:!0,get:function(){return r.default}}),e.DEFAULT_PRECEDENCE=l,e.addBinaryOp=d,e.addEvaluator=h,e.addUnaryOp=y,e.assignOps=v,e.binops=p,e.compile=g,e.compileAsync=A,e.default=u,e.evalAsync=x,e.evalExpr=b,e.evalExprAsync=w,e.evaluate=E,e.evaluators=c,e.registerPlugin=m,e.unops=f});
//# sourceMappingURL=jse-eval.umd.js.map
{
"name": "@zvenigora/jse-eval",
"version": "1.5.2",
"version": "1.6.0",
"description": "JavaScript expression parsing and evaluation.",

@@ -5,0 +5,0 @@ "source": "index.ts",

@@ -224,2 +224,15 @@ # jse-eval

### Case-insensitive evaluation
While JavaScript is the case-sensitive language some target audience finds it hard to use. To provide case-insensitive evaluation use `options`.
```javascript
import { parse, evaluate } from 'jse-eval';
const options = {caseSensitive: false};
const ast = parse('A + B / C');
const value = eval(ast, {a: 2, b: 2, c: 5}, options); // 2.4
```
> **_NOTE:_** Options support has not implemented for `compile` function.
### Node Types Supported:

@@ -226,0 +239,0 @@ This project will try to stay current with all JSEP's node types::

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc