rule-engine
v0.1.0
Published
Simple rule engine that compares two objects using rules written in JavaScript
Downloads
10
Readme
rule-engine
A very simple (stupid?) rule "engine"/rule evaluator that allows you to write rules, in JavaScript, to evaluate whether a rule should be matched based on the two objects and an optional parameter is given.
This is meant to be extremely light-weight and simple, and you should trust that whatever rules that was fed into the "engine" does not have malicious code.
How To Use
Include rule.js in your code
var Rule = require('rule');
Create a new Rule with a name and JavaScript statements.
var rule = new Rule('rule-name', 'return data.name === "hello world";');
In order for rule engine to work, the statement MUST return a true value should the rule is considered a match. (Not truthy, but a boolean true.)
Execute the rule by passing in the data you wanted to use to compare.
var result = rule.isMatch({ name: "hello world", garbage: "data" });