1.1.142 ā€¢ Published 3 years ago

nested-rules-engine v1.1.142

Weekly downloads
153
License
MIT
Repository
github
Last release
3 years ago

Synopsis

A simple Decision tree based Rule Engine described using json files. Rules are executed according to decision tree. Create a set of rules (make them nested as you like) and based on set of inputs run the rules.

Features

  1. Rules expressed in huaman readable JSON
  2. Create new set of inputs or change existing inputs as you traverse rules tree
  3. Do multiple executions or rules set

Installation

npm install nested-rules-engine --save

Basic Example

const {executeEngine} = require('nested-rules-engine');

// Step1: Define your conditional rules
const rules = {
  "you_are_a_human": {
    "you_are_kind": "help_me_find_my_book",
    "you_are_smart": "please_do_my_homework",
  },
  "default": "please_do_my_homework"
};

// Step2: make set of inputs collection
const inputs = {
  "type" : "human",
  "kindnessLevel": 0,
  "intelligence": 10
}

// Step3: Make your custom Functions
const functions = {
  default : () => true,
  you_are_a_human: ({type}) => type === 'human',
  you_are_kind: ({kindnessLevel}) => kindnessLevel > 300,
  you_are_smart: ({intelligence}) => intelligence > 5,
  help_me_find_my_book: () => ({
    payload: 'lets help someone',
    effort: 'finding the book'
  }),
  please_do_my_homework: () => ({
    payload: 'doing homework',
    effort: 'im getting sick'
  })
};

// Step4: Execute Engine
const res = executeEngine(inputs, functions, rules);

// Output res:
/*
{
  result: { payload: 'doing homework', effort: 'im getting sick' },
  logs: []
}
*/

Documentation

Engine Execution Signature:

executeEngine(variables, functions, rules, options);

Inputs

  • variables Collection of values on which rule engine will execute You can change these collection of variables (Add/Edit/Delte them) as you traverse the decision tree of rules.

  • functions Collection of functions that decide which way the tree should be traversed.

    • In case the function indicates a final decision in tree (leaf of decision tree): Output can be anything that you want to see as result
    • In case the function is makes an intermediate decision (branch of decision tree):
      • if output is true: this means this branch should be traversed
      • else: the function will be executed
  • rules Decision Tree that will be traversed by this Rule Engine

  • options there are different options that you can provide to customize the execution nature

    • verbose (boolean): Makes Sure you get enough logs while engine goes through all decision tree
    • multiple (boolean): You can run multiple Decision Trees based on same inputs. Input sets are shared between each tree

Outputs

  • result: Result of the engine execution. format of Result will be defined by you through functions
  • logs: Detailed logs while engine got executed (by default its disabled)

Hard Examples

  1. Example with verbose output, multiple executions Find Here
  2. Example with Creating new set of inputs while engine is executing Find Here

License

MIT

1.1.142

3 years ago

1.1.141

3 years ago

1.1.140

3 years ago

1.1.139

3 years ago

1.1.138

4 years ago

1.1.137

4 years ago

1.1.136

4 years ago

1.1.135

4 years ago

1.1.134

4 years ago

1.1.133

4 years ago

1.1.132

4 years ago

1.1.131

4 years ago

1.1.130

4 years ago

1.1.129

4 years ago

1.1.128

4 years ago

1.1.127

4 years ago

1.1.126

4 years ago

1.1.125

4 years ago

1.1.124

4 years ago

1.1.123

4 years ago

1.1.122

4 years ago

1.1.121

4 years ago

1.1.120

4 years ago

1.1.119

4 years ago

1.1.118

4 years ago

1.1.117

4 years ago

1.1.116

4 years ago

1.1.115

4 years ago

1.1.114

4 years ago

1.1.113

4 years ago

1.1.111

4 years ago

1.1.112

4 years ago

1.1.110

4 years ago

1.1.109

4 years ago

1.1.108

4 years ago

1.1.107

4 years ago

1.1.106

4 years ago

1.1.105

4 years ago

1.1.104

4 years ago

1.1.103

4 years ago

1.1.102

4 years ago

1.1.101

4 years ago

1.1.100

4 years ago

1.1.99

4 years ago

1.1.98

4 years ago

1.1.97

4 years ago

1.1.96

4 years ago

1.1.95

4 years ago

1.1.94

4 years ago

1.1.93

4 years ago

1.1.92

4 years ago

1.1.91

4 years ago

1.1.90

4 years ago

1.1.89

4 years ago

1.1.88

4 years ago

1.1.87

4 years ago

1.1.85

4 years ago

1.1.86

4 years ago

1.1.84

4 years ago

1.1.83

4 years ago

1.1.82

4 years ago

1.1.81

4 years ago

1.1.80

4 years ago

1.1.79

4 years ago

1.1.78

4 years ago

1.1.77

4 years ago

1.1.76

4 years ago

1.1.75

4 years ago

1.1.74

4 years ago

1.1.73

4 years ago

1.1.72

4 years ago

1.1.71

4 years ago

1.1.70

4 years ago

1.1.69

4 years ago

1.1.68

4 years ago

1.1.67

4 years ago

1.1.66

4 years ago

1.1.65

4 years ago

1.1.64

4 years ago

1.1.63

4 years ago

1.1.62

4 years ago

1.1.61

4 years ago

1.1.59

4 years ago

1.1.60

4 years ago

1.1.58

4 years ago

1.1.56

4 years ago

1.1.57

4 years ago

1.1.55

4 years ago

1.1.54

4 years ago

1.1.53

4 years ago

1.1.52

4 years ago

1.1.49

4 years ago

1.1.51

4 years ago

1.1.50

4 years ago

1.1.48

4 years ago

1.1.47

4 years ago

1.1.45

4 years ago

1.1.46

4 years ago

1.1.44

4 years ago

1.1.43

4 years ago

1.1.42

4 years ago

1.1.41

4 years ago

1.1.40

4 years ago

1.1.39

4 years ago

1.1.38

4 years ago

1.1.37

4 years ago

1.1.36

4 years ago

1.1.35

4 years ago

1.1.34

4 years ago

1.1.33

4 years ago

1.1.32

4 years ago

1.1.31

4 years ago

1.1.30

4 years ago

1.1.29

4 years ago

1.1.28

4 years ago

1.1.26

4 years ago

1.1.25

4 years ago

1.1.24

4 years ago

1.1.23

4 years ago

1.1.22

4 years ago

1.1.21

4 years ago

1.1.20

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.10

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.8

4 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0-beta5

5 years ago

1.0.0-beta4

5 years ago

1.0.0-beta3

5 years ago

1.0.0-beta1

5 years ago

1.0.0

5 years ago