Hello.
It is necessary to calculate the string. Implemented through new Function(str) . The question is: from a security point of view, is it enough to check the method (function) and the absence of assignment operations with a regular check?
var evalute = function (expr, context) { expr = expr.replace(/\s+/g, ''); if (/[^^\+\-\*\/\<\>\=]\(|[^\<\>\!\=]\=[^\=]/.test(expr)) { throw new Error('bad expression '+expr); } return (new Function('return ' + expr).bind(context))(); };