exprjs
javascript expressions language for safe eval in browser or nodejs built off of customization of acorn: http://marijnhaverbeke.nl/acorn/
Getting Started.
An alternative to eval() supporting javascript syntax for expressiveness and safe execution
Just add exprjs to your package.json, npm install or include lib/expr.js in html script with requirejs
Example:
var P = ; var parser = ; var obj1 = one: two:three:1 var obj2 = { return arguments0 ; } ; var obj3 = one: two:three:3 var parsed = parser; // returns true var result = parser; // using different object input, returns false result = parser; // assignment parsed = parser; result = parser; // mathematical expressions parsed = parser; result = parser;
parse() constructs the AST parse tree (can be saved off). It can be run repeatedly with run() providing different arguments like obj1, obj2, etc. The properties and functions of these are the only ones in scope.