toggledbits / lexpjs Goto Github PK
View Code? Open in Web Editor NEWlexpjs is a Lightweight EXPression parser and evaluator for JavaScript
License: MIT License
lexpjs is a Lightweight EXPression parser and evaluator for JavaScript
License: MIT License
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>] )
Useful when binary strings are used to mimic or manipulate device on/off status, such as in VirtualSwitch.
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);
LuaXP, from which this project was born, has an extensive unit test library. Need to bring that here.
On: https://github.com/toggledbits/lexpjs
the phrase:
"...you can carry it down.?a.?long.?list.?of.?member.?names without crashing..."
should read:
"...down?.a?.long?.list?.of?.member?.names..."
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:
, { 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:"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.