Is there a way to parse math equations as input using JavaScript?
for example, when a user enters "10-25" as input, it is parsed to -15
I tried using eval, which works, but it allows users to run all JavaScript code, not just math equations.
If it's possible, I'd like to also allow some functions, like sin(), cos(), and degreesToRadians(), but not all functions.
examples
"5" //returns 5
"12-20" //returns -8
"3/2" //returns 1.5
"sin(3.14)" //returns 0.00159265292
"sin(degreesToRadians(180/2)) * 10" //returns 10
"alert('hi')" //doesn't work