silentmatt / expr-eval

Mathematical expression evaluator in JavaScript
http://silentmatt.com/javascript-expression-evaluator/
MIT License
1.18k stars 239 forks source link

Ignore undefined variables #250

Closed Thevyn closed 3 years ago

Thevyn commented 3 years ago

Hi,

Is there a way to throw an error/ignore if one or more variables is undefined?

const formula = 'x > 100 and y > 100';
const variables =  { x: 120, y: undefined };
const v =  { x: 12, y: undefined };

const expr = parser.parse(formula);

console.log(expr.evaluate(variables));  
**output**: throws error Undefined variable y

console.log(expr.evaluate(v)); 
**output**: false, but i want it to throw an error here too.