# js-rule

> JavaScript implementation of the rules engine

Latest version **1.0.5** (published 2022-04-02) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install js-rule
pnpm add js-rule
yarn add js-rule
bun add js-rule
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2022-04-02 |
| First published | 2022-04-01 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=7.0.0 |
| Dependencies | 1 |
| Unpacked size | 25.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | kenny6520 |

## Links

- npm: https://www.npmjs.com/package/js-rule
- Repository: https://github.com/kenny6520/rule-engine
- Homepage: https://github.com/kenny6520/rule-engine#readme
- Issues: https://github.com/kenny6520/rule-engine/issues
- npm.io page: https://npm.io/package/js-rule

## Dependencies (1)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) 7.17.8

## Recent versions

- 1.0.5 (latest) — 2022-04-02
- 1.0.4 — 2022-04-01
- 1.0.3 — 2022-04-01
- 1.0.2 — 2022-04-01
- 1.0.1 — 2022-04-01
- 1.0.0 — 2022-04-01
- 0.0.1 — 2022-04-01

## README

# js-rule

JavaScript implementation of the rules engine

## Features

- [x] Single or multiple `Condition`、`Action`
- [x] Chain call `Rule`, eg: `A->B->C`
- [x] Multiple Condition setting `ANY`, `ALL`, `NONE`
- [ ] Condition setting `NOT`、`INCLUDE`、`EQUAL`、`NOT_EQUAL`、`GREATER`、`GREATER_EQUAL`、`LESS`、`LESS_EQUAL` ...
- [x] Custom Condition Operation

## Install

```bash
npm install js-rule
```

## Usage

**Use the program to indicate**

```javascript
if ((filedA.value === 10) & ["B1", "B2"].includes(filedB.value)) {
  filedC.visible = true;
  filedC.value = "C1";
}
```

**Description using Rule**

```javascript
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

```javascript
// getAllRuleDetails --> format: JSON
engine.getAllRuleDetails();

// getRules --> format: Original Rule
engine.getRules();
```

## DOCS

- [ ] TODO

---
_Source: https://npm.io/package/js-rule · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
