# axiom-rule-engine

> --- #### Author : Axiom ##### Created on : 2th Nov 2015 --- This Rules Engine is used to bind the rules and gets the result based on rules. It have 'RulesEngine()' function which returns 'RE' Object. You req

Latest version **1.0.4** (published 2019-06-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install axiom-rule-engine
pnpm add axiom-rule-engine
yarn add axiom-rule-engine
bun add axiom-rule-engine
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2019-06-04 |
| First published | 2016-06-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 16 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | darshit@byteprophecy.com |
| Maintainers | darshit-shah |

## Links

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

## Dependencies (1)

- [axiom-assert-helper](https://npm.io/package/axiom-assert-helper.md) *

## Recent versions

- 1.0.4 (latest) — 2019-06-04
- 1.0.3 — 2018-09-14
- 1.0.2 — 2018-09-12
- 1.0.1 — 2016-06-15
- 1.0.0 — 2016-06-15

## README

# Rules Engine
---
#### Author : Axiom
##### Created on : 2th Nov 2015
<!-- ##### Update Date : 24th Nov 2015 -->
---
This Rules Engine is used to bind the rules and gets the result based on rules. It have 'RulesEngine()' function which returns 'RE' Object. You require to import 'assertHelper.js' file for use this rules engine library.It is also require user to set **defaultResult** before using getResult() method.
- Create Instance Of RulesEngine
- Useful Functions
  - addRule()
  - removeRule()
  - getResult()
  - print()
  - getRule()
  - getAllRules()
- variable
  - defaultResult

## Create Instance Of RulesEngine
`To use RulesEngine Library  you require to create RulesEngine instance through that you can call it's functions.`

- Example

  ```javascript
  var RulesEngine = new RulesEngine();
  ```
`Here 'RulesEngine' is instance through this you can Call RulesEngine functions.`

## addRule(rule,result)
  `This method is used to add rules into 'RulesEngine' Object.It returns index of current rule into 'RulesEngine' object`

Parameter Name | Descriptions
:------------- | :------------------------------------------------------------------------
rule           | This contains array of JSON objects that defines rule
result         | This contains JSON objects that defines result with respect to given rule

- Attributes for rule and result Object

| Parameter | Attributes     | DataType | Possible Values|
| :------------- | :------------- |:------------- |:------------- |
| rule       | field       | string              |  Any   |
|        | filterType       | string              |  between, in, notin, lt, lteq, gt, gteq, eq, nteq   |
|        | value       | array              |  Any   |
| result | Any       | Any              |  Any   |

- Example

  ```javascript
  RulesEngine.addRule([{field:"growth",filterType:"between",value:[26, 35]},
                        {field:"slope",filterType:"between",value:[26,35]}],
                          {'Color': '#1A9850','Comment': 'Between'});
  ```

  Here,rule is binded for <br/>

  1> growth is Between 26 to 35.  <br/>

  2> slope is Between 26 to 35.

  with result 'Color'='#1A9850' and 'Comment'='Between'

--------------------------------------------------------------------------------

## removeRule(index)
`This method is used to remove the rule from specific index of 'RulesEngine' object.`

Parameter Name | Descriptions
:------------- | :-----------------------------------------------------
index          | This defines index of rules into 'RulesEngine' object

- Example

```javascript
    RulesEngine.removeRule(0);
```
  Here, It will remove first rule from index 0 of 'RulesEngine' object.

--------------------------------------------------------------------------------

## getResult(values)
`This method compare the given value with predefined rules and gives result object based on comaprision`

Parameter Name | Descriptions
:------------- | :--------------------------------------------------------------------------
values         | This defines JSON object which contains values to be compare against rules.

- Example

```javascript
RulesEngine.addRule([{field:"growth",filterType:"between",value:[26, 35]},
                      {field:"slope",filterType:"between",value:[26,35]}],
                        {'Color': '#1A9850','Comment': 'Between'});

retRestult=RulesEngine.getResult({growth:26,slope:29});

```

Here,<br/>

retRestult.Color contains '#1A9850' and retRestult.Comment contains 'Between'

---

## print()
`This method print Entire rules with result and also defaultResult.`

- Example

```javascript
RulesEngine.print()
```
---
### defaultResult
`defaultResult variable defines default result when no rules mathced.You must require to set default result before use getResult method.`

- Example
```javascript
RulesEngine.defaultResult={'Color': '#D73027','Comment': 'Default Message'};
```

---

## getRule(index)
`This method is used to get rule from specific index.`

Parameter Name | Descriptions
:------------- | :-----------------------------------------------------
index          | This defines index of rules into 'RulesEngine' object

- Example

```javascript
RulesEngine.getRule(0)
```
  Here, It will return first rule from index 0 of 'RulesEngine' object.

---

## getAllRules()
`This method is used to get all rules of 'RulesEngine' object.`

- Example

```javascript
RulesEngine.getAllRules()
```
  Here, It will return all rules of 'RulesEngine' object.

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