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
Copy file name to clipboardExpand all lines: README.md
+37-25
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,19 @@
8
8
9
9
A rules engine expressed in JSON
10
10
11
+
*[Synopsis](#synopsis)
12
+
*[Features](#features)
13
+
*[Installation](#installation)
14
+
*[Docs](#docs)
15
+
*[Examples](#examples)
16
+
*[Basic Example](#basic-example)
17
+
*[Advanced Example](#advanced-example)
18
+
*[Debugging](#debugging)
19
+
*[Node](#node)
20
+
*[Browser](#browser)
21
+
*[Related Projects](#related-projects)
22
+
*[License](#license)
23
+
11
24
## Synopsis
12
25
13
26
```json-rules-engine``` is a powerful, lightweight rules engine. Rules are composed of simple json structures, making them human readable and easy to persist.
@@ -19,14 +32,25 @@ A rules engine expressed in JSON
19
32
* Fast by default, faster with configuration; priority levels and cache settings for fine tuning performance
See the [Examples](./examples), which demonstrate the major features and capabilities.
53
+
30
54
## Basic Example
31
55
32
56
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).
@@ -130,17 +154,17 @@ let microsoftRule = {
130
154
fact:'account-information',
131
155
operator:'equal',
132
156
value:'microsoft',
133
-
path:'.company'// access the 'company' property of "account-information"
157
+
path:'$.company'// access the 'company' property of "account-information"
134
158
}, {
135
159
fact:'account-information',
136
160
operator:'in',
137
161
value: ['active', 'paid-leave'], // 'status' can be active or paid-leave
138
-
path:'.status'// access the 'status' property of "account-information"
162
+
path:'$.status'// access the 'status' property of "account-information"
139
163
}, {
140
164
fact:'account-information',
141
165
operator:'contains', // the 'ptoDaysTaken' property (an array) must contain '2016-12-25'
142
166
value:'2016-12-25',
143
-
path:'.ptoDaysTaken'// access the 'ptoDaysTaken' property of "account-information"
167
+
path:'$.ptoDaysTaken'// access the 'ptoDaysTaken' property of "account-information"
144
168
}]
145
169
},
146
170
event: {
@@ -184,40 +208,28 @@ engine
184
208
185
209
This is available in the [examples](./examples/03-dynamic-facts.js)
186
210
187
-
## Docs
188
-
189
-
The examples above provide a simple demonstrations of what `json-rules-engine` can do. To learn more about the advanced features and techniques,
190
-
see the [docs](./docs) and read through the [examples](./examples). There is also a [walkthrough](./docs/walkthrough.md) available.
191
-
192
-
## Persisting Rules
193
-
194
-
Rules may be easily converted to JSON and persisted to a database, file system, or elsewhere. To convert a rule to JSON, simply call the ```rule.toJSON()``` method. Later, a rule may be restored by feeding the json into the Rule constructor.
195
-
196
-
```js
197
-
// save somewhere...
198
-
let jsonString =rule.toJSON()
199
-
200
-
// ...later:
201
-
let rule =newRule(jsonString)
202
-
```
203
-
204
-
_Why aren't "fact" methods persistable?_ This is by design, for several reasons. Firstly, facts are by definition business logic bespoke to your application, and therefore lie outside the scope of this library. Secondly, many times this request indicates a design smell; try thinking of other ways to compose the rules and facts to accomplish the same objective. Finally, persisting fact methods would involve serializing javascript code, and restoring it later via ``eval()``. If you have a strong desire for this feature, the [node-rules](https://github.com/mithunsatheesh/node-rules) project supports this (though be aware the capability is enabled via ``eval()``.
205
-
206
211
## Debugging
207
212
208
213
To see what the engine is doing under the hood, debug output can be turned on via:
209
214
210
-
####Node
215
+
### Node
211
216
212
217
```bash
213
218
DEBUG=json-rules-engine
214
219
```
215
220
216
-
####Browser
221
+
### Browser
217
222
```js
218
223
// set debug flag in local storage & refresh page to see console output
219
224
localStorage.debug='json-rules-engine'
220
225
```
221
226
227
+
## Related Projects
228
+
229
+
https://github.com/vinzdeveloper/json-rule-editor - configuration ui for json-rules-engine:
Copy file name to clipboardExpand all lines: docs/rules.md
+15
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,7 @@ Rules contain a set of _conditions_ and a single _event_. When the engine is ru
27
27
*[Numeric operators:](#numeric-operators)
28
28
*[Array operators:](#array-operators)
29
29
*[Rule Results](#rule-results)
30
+
*[Persisting](#persisting)
30
31
31
32
## Methods
32
33
@@ -380,3 +381,17 @@ Rule results are structured similar to rules, with two additional pieces of meta
380
381
```
381
382
382
383
A demonstration can be found in the [rule-results](../examples/09-rule-results.js) example.
384
+
385
+
## Persisting
386
+
387
+
Rules may be easily converted to JSON and persisted to a database, file system, or elsewhere. To convert a rule to JSON, simply call the ```rule.toJSON()``` method. Later, a rule may be restored by feeding the json into the Rule constructor.
388
+
389
+
```js
390
+
// save somewhere...
391
+
let jsonString =rule.toJSON()
392
+
393
+
// ...later:
394
+
let rule =newRule(jsonString)
395
+
```
396
+
397
+
_Why aren't "fact" methods persistable?_ This is by design, for several reasons. Firstly, facts are by definition business logic bespoke to your application, and therefore lie outside the scope of this library. Secondly, many times this request indicates a design smell; try thinking of other ways to compose the rules and facts to accomplish the same objective. Finally, persisting fact methods would involve serializing javascript code, and restoring it later via ``eval()``.
0 commit comments