Giter VIP home page Giter VIP logo

simple-evaluate's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

simple-evaluate's Issues

Parentheses and ternary operators / complex formulae

We stumbled upon another small issue for our evaluations with more complex formulae, hope you can look into it again:

'v1_3==v1_1?1:0+v2_2==v2_1?1:0+v3_1==v3_1?1:0+v4_3==v4_1?1:0'
expected: 1, received: 1 ✅

the same with parentheses
'(v1_3==v1_1?1:0)+(v2_2==v2_1?1:0)+(v3_1==v3_1?1:0)+(v4_3==v4_1?1:0)'
expected: 1, received: 4 ⛔

all conditions match, no parentheses
'v1_3==v1_3?1:0+v2_2==v2_2?1:0+v3_1==v3_1?1:0+v4_3==v4_3?1:0'
expected: 4, received: 1 ⛔

parentheses but all blocks are true
'(g1_1==g1_1?1:0)+(g2_1==g2_1?1:0)+(g3_1==g3_1?1:0)+(g4_1==g4_1?1:0)+(g5_1==g5_1?1:0)'
expected: 5, received: 5 ✅

not all match
'(g1_1==g1_2?1:0)+(g2_1==g2_1?1:0)+(g3_1==g3_4?1:0)+(g4_1==g4_1?1:0)+(g5_1==g5_1?1:0)'
expected: 3, received: 5 ⛔

Thanks in advance!

Support for additional parentheses

Hi there!

Evaluating this formula (-0.02*(1+5+3+1+5+3+1))+(0.07*(3+5+3+3+3+1+3+0))+(0.15*(3+1+5+1+5+3+1))-4.36
will fail with the following error:

Error: operation must be string, but get {"left":{"left":{"left":{"left":{"left":{"left":"1","right":"5","operation":"+"},"right":"3","operation":"+"},"right":"1","operation":"+"},"right":"5","operation":"+"},"right":"3","operation":"+"},"right":"1","operation":"+","grouped":true}

The reason seems to be the additional / unnecessary parentheses if I'm not mistaken;
evaluating it like this: -0.02*(1+5+3+1+5+3+1)+0.07*(3+5+3+3+3+1+3+0)+0.15*(3+1+5+1+5+3+1)-4.36 works fine.

Sometimes additional parentheses are useful for clarity, especially for our team members working with large json files. Ideally this should not throw errors.

Add Support for Templating Strings

Hello,
I would love to see support for templating strings.
This would allow basic support for file templates and easier syntax for evaluating strings.

evaluate({a:22}, "'I am ' + a + ' years old today'")
vs

evaluate({a:22}, "\`I am  ${a} years old today\`")

If you still keep the other restrictions, that's fine, but allowing simple expressions within ${} would be extremely useful.

Modulo Operation (%) seems not to work

When using simple modulo operations like '4 % 2' I always get undefined as result.
It seems that the modulo operation is missing as case in the big switch expressions in compiler.ts and shunting-yard.ts

switch (node.operation) {
            case '*':
                return left * right;
            case '/':
                return left / right;
            case '%':                                   <-- this one is missing         
                return left % right;

Ternary Operator Expression Error

Me again :)

I found an issue regarding the evaluation of ternary operator expressions:

5 == 5 ? 4 : 1 results in 4, good
1 == 1 ? 1 : 0 results in 1, good
0 == 0 ? 0 : 1 results in 1, unexpected; apparently 0 is not equal to 0

just 0 == 0 results in true though, so it must be something with the ternary operator

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.