1.0.5 • Published 2 years ago
js-rule v1.0.5
js-rule
JavaScript implementation of the rules engine
Features
- Single or multiple
Condition
、Action
- Chain call
Rule
, eg:A->B->C
- Multiple Condition setting
ANY
,ALL
,NONE
- Condition setting
NOT
、INCLUDE
、EQUAL
、NOT_EQUAL
、GREATER
、GREATER_EQUAL
、LESS
、LESS_EQUAL
... - Custom Condition Operation
Install
npm install js-rule
Usage
Use the program to indicate
if ((filedA.value === 10) & ["B1", "B2"].includes(filedB.value)) {
filedC.visible = true;
filedC.value = "C1";
}
Description using Rule
import { Engine, Rule, ConditionOperationEnum } from "js-rule";
const engine = new Engine();
// Add a rule where Condition is ANY
// ANY: Action is triggered whenever a Condition holds
const rule = new Rule(ConditionOperationEnum.ANY);
/* set condition */
// When the value of 'FiledA' is equal to 10 and the value of 'FieldB' contains "B1" or "B2" is discarded
rule.condition.addCondition("FieldA", "EQUAL", 10);
rule.condition.addCondition("FieldB", "INCLUDE", ["B1", "B1"]);
/* set action */
rule.action.addAction("FieldC", {
show: true,
value: "C1",
});
// register rule
engine.addRule(rule);
Submit data
// getAllRuleDetails --> format: JSON
engine.getAllRuleDetails();
// getRules --> format: Original Rule
engine.getRules();
DOCS
- TODO