JavaScript (TypeScript) math expression evaluator library
- git clone https://github.com/tsv2013/expression-evaluator.git
- cd expression-evaluator
- npm i
- npm test
- npm run build
var ee = new ExpressionEvaluator();
var res1 = ee.evaluate("6 / 2 + 1 + 2*2 - 5");
var res2 = ee.evaluate("false or false");
ExpressionEvaluator.operations["myFunc"] = {
priority: 100,
function: (a, b) => (a+b)/2
}
ExpressionEvaluator.operations["mySq"] = {
priority: 100,
function: a => a*a
}
ExpressionEvaluator.operations["mySecond"] = {
priority: 100,
function: (a, b, c) => b
}
var ee = new ExpressionEvaluator();
var result = ee.evaluate("mySecond(5, myFunc(2,4), mySq(2))");
var ee = new ExpressionEvaluator();
var evaluationContext = { propertyName: 1 };
var result = ee.evaluate("{propertyName} + 1", evaluationContext);