js-expression-eval
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -1,2 +0,2 @@ | ||
7064881 | ||
1690696566105629000 | ||
7223388 | ||
1690702428039042000 |
@@ -1,7 +0,4 @@ | ||
var $35FHw$acorn = require("acorn"); | ||
var $35FHw$acornwalk = require("acorn-walk"); | ||
var $htXX8$acorn = require("acorn"); | ||
var $htXX8$acornwalk = require("acorn-walk"); | ||
function $parcel$defineInteropFlag(a) { | ||
Object.defineProperty(a, '__esModule', {value: true, configurable: true}); | ||
} | ||
function $parcel$export(e, n, v, s) { | ||
@@ -11,7 +8,5 @@ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); | ||
$parcel$defineInteropFlag(module.exports); | ||
$parcel$export(module.exports, "ExpressionParser", () => $9a1b2acb76b2e255$export$e698c7418fab884c); | ||
$parcel$export(module.exports, "default", () => $4a2a39b881b9ecf7$export$2e2bcd8739ae039); | ||
class $7b16012f8029032d$export$45014ba6deacc088 { | ||
@@ -336,3 +331,3 @@ static evaluate(input, thousandSeparator = ",", decimalSeparator = ".") { | ||
} | ||
return onCallee[index - 1]; | ||
return onCallee[index]; | ||
} | ||
@@ -350,3 +345,3 @@ const array = (0, $8ec873619aeca9c4$export$d812c8e1906863d0)(context.get(args[0])); | ||
} | ||
return array[index - 1]; | ||
return array[index]; | ||
}; | ||
@@ -370,3 +365,3 @@ const $df2cb2ee16c034a5$var$Range = (node, context)=>{ | ||
} | ||
return onCallee.slice(from - 1, to); | ||
return onCallee.slice(from, to); | ||
}; | ||
@@ -397,3 +392,3 @@ const $df2cb2ee16c034a5$var$Sort = (node, context)=>{ | ||
} | ||
return array.indexOf(value) + 1; | ||
return array.indexOf(value); | ||
}; | ||
@@ -1162,7 +1157,3 @@ var $df2cb2ee16c034a5$export$2e2bcd8739ae039 = { | ||
/** | ||
* @class Formula | ||
* @description Scripts Formula class | ||
* @author Praveen N | ||
*/ class $4a2a39b881b9ecf7$var$Formula { | ||
class $9a1b2acb76b2e255$export$e698c7418fab884c { | ||
/** | ||
@@ -1175,3 +1166,3 @@ * @description Creates an instance of Formula. | ||
const processedFormula = (0, $8ec873619aeca9c4$export$3e483299637a8ca8)(formula); | ||
this.formulaAST = $35FHw$acorn.parse(processedFormula, { | ||
this.formulaAST = $htXX8$acorn.parse(processedFormula, { | ||
ecmaVersion: 3 | ||
@@ -1187,3 +1178,3 @@ }); | ||
// Walk through the formula and evaluate each ast node | ||
$35FHw$acornwalk.ancestor(this.formulaAST, (0, $83cdaf4c75cfecc1$export$2e2bcd8739ae039), undefined, this.exeContext); | ||
$htXX8$acornwalk.ancestor(this.formulaAST, (0, $83cdaf4c75cfecc1$export$2e2bcd8739ae039), undefined, this.exeContext); | ||
const resObject = this.exeContext.get(this.formulaAST) || this.exeContext.lastResolvedValue; | ||
@@ -1195,3 +1186,3 @@ return (0, $8ec873619aeca9c4$export$d812c8e1906863d0)(resObject); | ||
const variableNames = new Set(); | ||
$35FHw$acornwalk.simple(this.formulaAST, { | ||
$htXX8$acornwalk.simple(this.formulaAST, { | ||
Identifier: (node)=>{ | ||
@@ -1208,3 +1199,3 @@ if (!variableNames.has(node.name)) identifiers.add(node.name); | ||
const functionNames = []; | ||
$35FHw$acornwalk.simple(this.formulaAST, { | ||
$htXX8$acornwalk.simple(this.formulaAST, { | ||
CallExpression: (node)=>{ | ||
@@ -1220,5 +1211,4 @@ functionNames.push((0, $8e2028b58a0c9087$export$630443adb7e7e89e)(node.callee)); | ||
} | ||
var $4a2a39b881b9ecf7$export$2e2bcd8739ae039 = $4a2a39b881b9ecf7$var$Formula; | ||
//# sourceMappingURL=main.js.map |
@@ -1,3 +0,3 @@ | ||
import {parse as $8bFR1$parse} from "acorn"; | ||
import {ancestor as $8bFR1$ancestor, simple as $8bFR1$simple} from "acorn-walk"; | ||
import {parse as $lwtba$parse} from "acorn"; | ||
import {ancestor as $lwtba$ancestor, simple as $lwtba$simple} from "acorn-walk"; | ||
@@ -328,3 +328,3 @@ function $parcel$export(e, n, v, s) { | ||
} | ||
return onCallee[index - 1]; | ||
return onCallee[index]; | ||
} | ||
@@ -342,3 +342,3 @@ const array = (0, $f4acba4e997cd7e7$export$d812c8e1906863d0)(context.get(args[0])); | ||
} | ||
return array[index - 1]; | ||
return array[index]; | ||
}; | ||
@@ -362,3 +362,3 @@ const $7d360681c714f23a$var$Range = (node, context)=>{ | ||
} | ||
return onCallee.slice(from - 1, to); | ||
return onCallee.slice(from, to); | ||
}; | ||
@@ -389,3 +389,3 @@ const $7d360681c714f23a$var$Sort = (node, context)=>{ | ||
} | ||
return array.indexOf(value) + 1; | ||
return array.indexOf(value); | ||
}; | ||
@@ -1154,7 +1154,3 @@ var $7d360681c714f23a$export$2e2bcd8739ae039 = { | ||
/** | ||
* @class Formula | ||
* @description Scripts Formula class | ||
* @author Praveen N | ||
*/ class $d3e4a59152aaa3b5$var$Formula { | ||
class $5ada30aafb417b64$export$e698c7418fab884c { | ||
/** | ||
@@ -1167,3 +1163,3 @@ * @description Creates an instance of Formula. | ||
const processedFormula = (0, $f4acba4e997cd7e7$export$3e483299637a8ca8)(formula); | ||
this.formulaAST = $8bFR1$parse(processedFormula, { | ||
this.formulaAST = $lwtba$parse(processedFormula, { | ||
ecmaVersion: 3 | ||
@@ -1179,3 +1175,3 @@ }); | ||
// Walk through the formula and evaluate each ast node | ||
$8bFR1$ancestor(this.formulaAST, (0, $4529a3915810b007$export$2e2bcd8739ae039), undefined, this.exeContext); | ||
$lwtba$ancestor(this.formulaAST, (0, $4529a3915810b007$export$2e2bcd8739ae039), undefined, this.exeContext); | ||
const resObject = this.exeContext.get(this.formulaAST) || this.exeContext.lastResolvedValue; | ||
@@ -1187,3 +1183,3 @@ return (0, $f4acba4e997cd7e7$export$d812c8e1906863d0)(resObject); | ||
const variableNames = new Set(); | ||
$8bFR1$simple(this.formulaAST, { | ||
$lwtba$simple(this.formulaAST, { | ||
Identifier: (node)=>{ | ||
@@ -1200,3 +1196,3 @@ if (!variableNames.has(node.name)) identifiers.add(node.name); | ||
const functionNames = []; | ||
$8bFR1$simple(this.formulaAST, { | ||
$lwtba$simple(this.formulaAST, { | ||
CallExpression: (node)=>{ | ||
@@ -1212,6 +1208,5 @@ functionNames.push((0, $9b47f47c819f7524$export$630443adb7e7e89e)(node.callee)); | ||
} | ||
var $d3e4a59152aaa3b5$export$2e2bcd8739ae039 = $d3e4a59152aaa3b5$var$Formula; | ||
export {$d3e4a59152aaa3b5$export$2e2bcd8739ae039 as default}; | ||
export {$5ada30aafb417b64$export$e698c7418fab884c as ExpressionParser}; | ||
//# sourceMappingURL=module.js.map |
@@ -0,1 +1,5 @@ | ||
interface IVariableContext { | ||
[key: string]: IVariableContext | IFormulaObject; | ||
} | ||
type IFormulaObject = string | number | boolean | ((...args: any) => IFormulaObject) | string[]; | ||
/** | ||
@@ -6,3 +10,3 @@ * @class Formula | ||
*/ | ||
export default class Formula { | ||
export class ExpressionParser { | ||
/** | ||
@@ -14,5 +18,3 @@ * @description Creates an instance of Formula. | ||
*/ | ||
constructor(formula: string, variables?: { | ||
[key: string]: any; | ||
}); | ||
constructor(formula: string, variables?: IVariableContext); | ||
/** | ||
@@ -31,4 +33,3 @@ * @description This function evaluate the formula and returns the result | ||
} | ||
export default Formula; | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "js-expression-eval", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "JS expression evaluation package", | ||
@@ -8,3 +8,3 @@ "repository": "https://github.com/praveenn77/js-expression-eval.git", | ||
"license": "MIT", | ||
"source": "src/Formula.ts", | ||
"source": "src/ExpressionParser.ts", | ||
"main": "dist/main.js", | ||
@@ -11,0 +11,0 @@ "module": "dist/module.js", |
@@ -21,7 +21,13 @@ # js-expression-eval | ||
## Import | ||
```javascript | ||
import jsExpressionEval from 'js-expression-eval'; | ||
const { ExpressionParser } = jsExpressionEval; | ||
``` | ||
## Syntax | ||
```javascript | ||
import ExpressionParser from 'js-expression-eval'; | ||
const parser = new ExpressionParser(expression, variables?); | ||
const parser = new ExpressionParser(expression:string, variables); | ||
const result = parser.evaluate(); | ||
@@ -33,3 +39,4 @@ ``` | ||
```javascript | ||
import ExpressionParser from 'js-expression-eval'; | ||
import jsExpressionEval from 'js-expression-eval'; | ||
const { ExpressionParser } = jsExpressionEval; | ||
const parser = new ExpressionParser('2 + 3'); | ||
@@ -43,3 +50,2 @@ const result = parser.evaluate(); | ||
```javascript | ||
import ExpressionParser from 'js-expression-eval'; | ||
const parser = new ExpressionParser('x + y.z', { x: 2, y: { z: 3 } }); | ||
@@ -53,3 +59,2 @@ const result = parser.evaluate(); | ||
```javascript | ||
import ExpressionParser from 'js-expression-eval'; | ||
const parser = new ExpressionParser('A + B', { A: 2, B: () => 3 }); | ||
@@ -63,3 +68,2 @@ const result = parser.evaluate(); | ||
```javascript | ||
import ExpressionParser from 'js-expression-eval'; | ||
const parser = new ExpressionParser('A.B + A.C' , | ||
@@ -66,0 +70,0 @@ { |
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
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
7368641
97
2262