Giter VIP home page Giter VIP logo

expressionparser's People

Contributors

dcollien avatar dependabot[bot] avatar

Stargazers

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

Watchers

 avatar  avatar

expressionparser's Issues

evaluateExpression?

In the Readme.md under the heading Custom Language it's described how to evaluate an expression (with new ExpressionParser(arithmeticLanguage).evaluateExpression(expr)).

However I can't get this to work. Looking in the code I can't even see any evaluateExpression.

Have I misunderstood something, or is the documentation faulty?

Does it use any kind of cache?

Does this lib use any internal cache in order to boost performance, when asked to evaluate the same expression many times?
Ideally, I would like to have method .compileExpression() which will return function from given string expression argument.

Escaping square brackets

I am using expression-parser in combination with jsonpath-plus library to parse json paths and read the data out of a json object based on the term returned. Here is what my parser code looks like:

export function initialiseParser(workerObject: WokerObjectType): ExpressionParser {
  return init(formula, (term: string) => {
    if (term === '$NULL') {
      return '$NULL';
    } else if (term.startsWith('$VALUE:')) {
      const [, key] = term.split('$VALUE:');
      return getJsonData({ path: key, json: workerObject }) ?? '$NULL';
    } else {
      return '$NULL';
    }
  });
}

I am trying to parse the below expression:
$VALUE:Worker_Data.Employment_Data.Worker_Job_Data[?(@.attributes['wd:Primary_Job'] === '1')].Position_Data.Business_Site_Summary_Data.Name

When running this through the parser, I can see the term evaluates to .Position_Data.Business_Site_Summary_Data.Name. The result I would like to achieve is to get out the full expression: Worker_Data.Employment_Data.Worker_Job_Data[?(@.attributes['wd:Primary_Job'] === '1')].Position_Data.Business_Site_Summary_Data.Name.

My gut feeling is that the formula language is recognizing the '[]' and parses it at something else but looking through the docs I am unclear as to what.

I wonder is someone could shed some light on this for me? If formula uses [] for something else, how can I escape the character when using it in the expression? Also open to other solutions. Please let me know if more details are required.

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.