xparse
v1.0.0
Published
Flexible expression parser for computing user defined conditionals
Downloads
1,021
Maintainers
Readme
xparse
Flexible expression parser for computing user defined conditionals
You can reference annotated source code here.
Usage
$ npm install xparse
const xparse = require('xparse');
var expr = xparse("25 * 4");
expr() // returns 100
Dynamic Variables
var variables = {
hello: 70
}
var resolver = (key) => variables[key]
var expr = xparse("hello < 25 * 4");
expr(resolver) // returns true (since 70 is less than 25 * 4)
variables.hello = 125
expr(resolver) // returns false (since 125 is not less than 25 * 4)
Dynamic Functions
var functions = {
increment: (arg) => { arg + 1 }
decrement: (arg) => { arg - 1 }
}
var resolver = (key, arg) => { functions[key](arg) }
var expr = xparse("increment(70) < 25 * 4");
expr(resolver) // returns true (since 71 is less than 25 * 4)
functions.increment = (arg) => { arg + 100 }
expr(resolver) // returns false (since 170 is not less than 25 * 4)
License
This software is brought to you by Corenova Technologies. We'd love to hear your feedback. Please feel free to reach me at [email protected] anytime with questions, suggestions, etc.