1.0.5 • Published 2 years ago

js-rule v1.0.5

Weekly downloads
-
License
-
Repository
github
Last release
2 years ago

js-rule

JavaScript implementation of the rules engine

Features

  • Single or multiple ConditionAction
  • Chain call Rule, eg: A->B->C
  • Multiple Condition setting ANY, ALL, NONE
  • Condition setting NOTINCLUDEEQUALNOT_EQUALGREATERGREATER_EQUALLESSLESS_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
1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.1

2 years ago