You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Converted all examples to ES6
- Added fuller, more realistic examples to the README
- Replaced the basic example with nested-boolean-logic
- Ordered examples in order of complexity
- Removed the Overview
Copy file name to clipboardExpand all lines: README.md
+98-14
Original file line number
Diff line number
Diff line change
@@ -24,17 +24,9 @@ A rules engine expressed in JSON
24
24
$ npm install json-rules-engine
25
25
```
26
26
27
-
## Documentation
27
+
## Basic Example
28
28
29
-
It's best to start with the [overview](./docs/overview.md) to understand the terminology. Next, see the [walkthrough](./docs/overview.md) and try out some [examples](./examples).
30
-
31
-
To dive right in, start with the [basic example](./examples/basic.js).
32
-
33
-
## Example
34
-
35
-
In basketball, a player who commits five personal fouls over the course of a 40-minute game, or six in a 48-minute game, fouls out.
36
-
37
-
This example demonstrates an engine for detecting whether an individual player has fouled out.
29
+
This example demonstrates an engine for detecting whether a basketball player has fouled out (a player who commits five personal fouls over the course of a 40-minute game, or six in a 48-minute game, fouls out).
38
30
39
31
```js
40
32
import { Engine } from'json-rules-engine'
@@ -79,28 +71,120 @@ engine.addRule({
79
71
})
80
72
81
73
/**
82
-
* define the facts
83
-
* note: facts may be loaded asynchronously at runtime; see the advanced example below
74
+
* Define facts the engine will use to evaluate the conditions above.
75
+
* Facts may also be loaded asynchronously at runtime; see the advanced example below
84
76
*/
85
77
let facts = {
86
78
personalFoulCount:6,
87
79
gameDuration:40
88
80
}
89
81
90
-
//run the engine
82
+
//Run the engine to evaluate
91
83
engine
92
84
.run(facts)
93
-
.then(events=> { // run() return events with truthy conditions
85
+
.then(events=> { // run() returns events with truthy conditions
Copy file name to clipboardExpand all lines: docs/facts.md
+3
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,8 @@
1
1
# Facts
2
2
3
+
Facts are methods or constants registered with the engine prior to runtime and referenced within rule conditions. Each fact method should be a pure function that may return a computed value or promise.
4
+
As rule conditions are evaluated during runtime, they retrieve fact values dynamically and use the condition _operator_ to compare the fact result with the condition _value_.
Copy file name to clipboardExpand all lines: docs/rules.md
+2
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# Rules
2
2
3
+
Rules contain a set of _conditions_ and a single _event_. When the engine is run, each rule condition is evaluated. If the results are truthy, the rule's _event_ is triggered.
0 commit comments