GithubHelp home page GithubHelp logo

toggledbits / lexpjs Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 684 KB

lexpjs is a Lightweight EXPression parser and evaluator for JavaScript

License: MIT License

JavaScript 90.61% HTML 0.75% Makefile 0.28% Yacc 8.35%

lexpjs's Issues

Add array function CHOOSE for lookup

Having found the CHOOSE array function so helpful in LuaXP, it would be nice to see it implemented here in LEXPJS. Example:

CHOOSE ( arg , [<array>] )

Lexpjs does not currently support modification or creation of variables in expressions

It is likely that variable assignments (and in conjunction, compound expressions) would be a useful addition to simplify complex expressions or give callers access to interim results.

For example, a = minval+(maxval-minval)/2 ; a * a would execute two expressions: the first would compute the median of minval and maxval and store it in the context object with the name a; the second would square a; the value returned by run() directly would be the computed value of the last expression, which in this example is the square of a. The interim result created by the first expression would be available by examining the a property in the context object passed to run().

context = { "minval": somevalue, "maxval": someothervalue }
var rr = lexp.evaluate("a = minval+(maxval-minval)/2 ; a * a", context);
// Remember that run() is called for us by evaluate()
console.log("The square of the median is " + rr + ", and the median is " + context.a);

Distance Calculation Function

I would like to measure the distance between 2 latitudes and longitudes for a simple expression that I am creating. I was unable to find any Reactor function for distance so I was going to create my own expression. The function is defined below:

acos(sin(Radians(Lat1))*sin(Radians(Lat2))+cos(Radians(Lat1))*cos(Radians(Lat2))*cos(Radians(Long2)-Radians(Long1)))*6371/1.6
Note: (the 1.6 results in miles and without results in km)

The issue that I have is that Reactor does not currently support "acos" and "radians". I created an expression for radians which is pi/180. Reactor didn't have "pi" so I created a simple expression for it = 22/7. However, I was unable to find a simple calculation to recreate the "acos" function.

Thus, in order of priority, I'd like to request the following functions:

  1. acos - This is the limiting factor at the moment and can not proceed.
  2. radians - Would be good to have something available.
  3. pi - Low priority but would be good to have something available.
  4. distance function - none of the above would be required ;) if done, would be good to offer results in miles and kilometers/meters if possible.

Minor typos (3) in test.js

, { expr: "[1,2,3]", Xxpect: [1,2,3] }
, { expr: "{ alpha: 1, beta: 2, gamma: 3 }", Xxpect: { alpha: 1, beta: 2, gamma: 3 } }
, { expr: "{ 'first': 'a', ['strange id']: 'b', 'Another Strange ID': 'voodoo' }", Xxpect: {} }

Keys should read "expect:" not "Xxpect:"

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.