Hyoka
github.com
Hyoka
1–10 of 20 posts
Re: Hyoka
#2Re: Hyoka
#3I created a lightweight and precise math expression parser and evaluator for JavaScript and TypeScript. it can handle complex arithmetic expressions
What are the security implications of this? Does the code run in the server or my computer? Does it only recognize math functions, or it can also run "alert"?
Re: Hyoka
#4I created a lightweight and precise math expression parser and evaluator for JavaScript and TypeScript. it can handle complex arithmetic expressions
Do you have an online demo, where I can write an expression in a text box and get the result? What are the security implications of this? Does the code run in the server or my computer? Does it only recognize math functions, or it can also run "alert"?
Re: Hyoka
#5I created a lightweight and precise math expression parser and evaluator for JavaScript and TypeScript. it can handle complex arithmetic expressions
Do you have an online demo, where I can write an expression in a text box and get the result? What are the security implications of this? Does the code run in the server or my computer? Does it only recognize math functions, or it can also run "alert"?
Re: Hyoka
#6Earlier quoted context omitted.
Do you have an online demo, where I can write an expression in a text box and get the result? What are the security implications of this? Does the code run in the server or my computer? Does it only recognize math functions, or it can also run "alert"?
hyoka uses a full recursive descent parser to parse expressions into AST, then evaluates to get the final result. it is very secure for math expressions unlike the eval function which can run javascript code. you can try out a demo here https://codesandbox.io/s/naughty-chatterjee-kr3bsc
I was trying to change the expression, but I need to change it twice. At the top where `expression` is defined and at the bottom to show it in the html. Is it possible to "see" what is inside an Expression object?
Re: Hyoka
#7Earlier quoted context omitted.
hyoka uses a full recursive descent parser to parse expressions into AST, then evaluates to get the final result. it is very secure for math expressions unlike the eval function which can run javascript code. you can try out a demo here https://codesandbox.io/s/naughty-chatterjee-kr3bsc
Nice! I was trying to change the expression, but I need to change it twice. At the top where `expression` is defined and at the bottom to show it in the html. Is it possible to "see" what is inside an Expression object?
Re: Hyoka
#8Earlier quoted context omitted.
Do you have an online demo, where I can write an expression in a text box and get the result? What are the security implications of this? Does the code run in the server or my computer? Does it only recognize math functions, or it can also run "alert"?
hyoka uses a full recursive descent parser to parse expressions into AST, then evaluates to get the final result. it is very secure for math expressions unlike the eval function which can run javascript code. you can try out a demo here https://codesandbox.io/s/naughty-chatterjee-kr3bsc
Eg.
const a = 3;
const b = 2;
const expression = new Expression(`${a}*${b}(6/3(5--2))`);
const result = expression.evaluate();
document.getElementById("app").innerHTML = `a*b( 6 / 3( 5 - - 2 ) )= ${result}`;
Edit: formatingRe: Hyoka
#9Earlier quoted context omitted.
hyoka uses a full recursive descent parser to parse expressions into AST, then evaluates to get the final result. it is very secure for math expressions unlike the eval function which can run javascript code. you can try out a demo here https://codesandbox.io/s/naughty-chatterjee-kr3bsc
I would show examples in README on use of it along with string interpolation, as it's not too useful with only constants. Eg. const a = 3; const b = 2; const expression = new Expression(`${a}*${b}(6/3(5--2))`); const result = expression.evaluate(); document.getElementById("app").innerHTML = `a*b( 6 / 3( 5 - - 2 ) )= ${result}`; Edit: formating
const a = 2;
const b = 6;
const c = 3
const expression = new Expression('a \ b * c')
const result = expression.scope({a, b, c}).evaluate();
document.getElementById("app").innerHTML `${a} \ ${b} *
${c}= ${result}`Re: Hyoka
#10Earlier quoted context omitted.
I would show examples in README on use of it along with string interpolation, as it's not too useful with only constants. Eg. const a = 3; const b = 2; const expression = new Expression(`${a}*${b}(6/3(5--2))`); const result = expression.evaluate(); document.getElementById("app").innerHTML = `a*b( 6 / 3( 5 - - 2 ) )= ${result}`; Edit: formating
Nice tip, i'm planning to add an identifier node class so that you can pass a scope with the values to be used during evaluation. Eg. const a = 2; const b = 6; const c = 3 const expression = new Expression('a \ b * c') const result = expression.scope({a, b, c}).evaluate(); document.getElementById("app").innerHTML `${a} \ ${b} * ${c}= ${result}`