xparse

Flexible expression parser for computing user defined conditionals

  • xparse

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
xparse
1.0.07 years ago7 years agoMinified + gzip package size for xparse in KB

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

Apache 2.0
This software is brought to you by Corenova Technologies. We'd love to hear your feedback. Please feel free to reach me at anytime with questions, suggestions, etc.