I'm looking at the alternative that can substitute the use of eval() and new Function() javascript techniques. I'm developing a solution build with javascript and the platform on which it is built (Salesforce) recently has announced they're introducing CSP (content security policy) that will block the use of eval(), and other unsafe functions.My solution is using eval function to evaluate string expressions and do some other magic stuff. I'm looking for some alternative, ideally without writing my own parser.As I have mentioned, I use eval to evaluate expressions. Expressions that should be to be supported are usually like:String comparison eval('something' == 'something')      // return trueCalculations eval(2 + 2 * 3)  // return 8&& and || support eval(1 == 1 && 'cat' == 'dog')      // return falseConditional operators,at least ternary eval((1 == 2 ? 'dog' : 'cat'))       // return catfull if-else would be really great: eval(if(1 == 2) { 'dog' } else if (1 == 3) { 'dog' } else { 'nothing' })                         // return nothingSome basic Math class methods, e.g.: eval(Math.ceil(12.313));   // return 13Capabilities that would be really great to haveInject variable new Function(var item = this; item.number = 10;, item); // item is variable defined outside of eval and I want to dynamically modify it within eval()Inject function definition eval(invert('123')) // return 321, invert() is a function defined somewhere elseI'm looking for something that is:Relatively close to Javascript syntax (but I would accept if it would be some different language that can be interpreted by some js library compliant with CSP)Not too much dependent on other librariesCan be loaded without node.js etc (standalone js library)
Alternative for eval() in javascript for expression evaluation
javascript;parsing;computation expressions