Skip to content

Commit a5aaf1a

Browse files
authored
Merge pull request #245 from CacheControl/update-readme
README: Promote docs and examples to top; add json-rule-editor in Rel…
2 parents d6e4557 + 03a69ff commit a5aaf1a

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

README.md

+37-25
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88

99
A rules engine expressed in JSON
1010

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+
1124
## Synopsis
1225

1326
```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
1932
* Fast by default, faster with configuration; priority levels and cache settings for fine tuning performance
2033
* Secure; no use of eval()
2134
* Isomorphic; runs in node and browser
22-
* Lightweight & extendable; 12kb gzipped w/few dependencies
35+
* Lightweight & extendable; 17kb gzipped w/few dependencies
2336

2437
## Installation
2538

2639
```bash
2740
$ npm install json-rules-engine
2841
```
2942

43+
## Docs
44+
45+
- [engine](./docs/engine.md)
46+
- [rules](./docs/rules.md)
47+
- [almanac](./docs/almanac.md)
48+
- [facts](./docs/facts.md)
49+
50+
## Examples
51+
52+
See the [Examples](./examples), which demonstrate the major features and capabilities.
53+
3054
## Basic Example
3155

3256
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 = {
130154
fact: 'account-information',
131155
operator: 'equal',
132156
value: 'microsoft',
133-
path: '.company' // access the 'company' property of "account-information"
157+
path: '$.company' // access the 'company' property of "account-information"
134158
}, {
135159
fact: 'account-information',
136160
operator: 'in',
137161
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"
139163
}, {
140164
fact: 'account-information',
141165
operator: 'contains', // the 'ptoDaysTaken' property (an array) must contain '2016-12-25'
142166
value: '2016-12-25',
143-
path: '.ptoDaysTaken' // access the 'ptoDaysTaken' property of "account-information"
167+
path: '$.ptoDaysTaken' // access the 'ptoDaysTaken' property of "account-information"
144168
}]
145169
},
146170
event: {
@@ -184,40 +208,28 @@ engine
184208

185209
This is available in the [examples](./examples/03-dynamic-facts.js)
186210

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 = new Rule(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-
206211
## Debugging
207212

208213
To see what the engine is doing under the hood, debug output can be turned on via:
209214

210-
#### Node
215+
### Node
211216

212217
```bash
213218
DEBUG=json-rules-engine
214219
```
215220

216-
#### Browser
221+
### Browser
217222
```js
218223
// set debug flag in local storage & refresh page to see console output
219224
localStorage.debug = 'json-rules-engine'
220225
```
221226

227+
## Related Projects
228+
229+
https://github.com/vinzdeveloper/json-rule-editor - configuration ui for json-rules-engine:
230+
231+
<img alt="rule editor 1" src="https://user-images.githubusercontent.com/61467683/82750272-dc0a0e80-9da6-11ea-98ec-3549bf530f4d.png">
232+
233+
222234
## License
223235
[ISC](./LICENSE)

docs/rules.md

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Rules contain a set of _conditions_ and a single _event_. When the engine is ru
2727
* [Numeric operators:](#numeric-operators)
2828
* [Array operators:](#array-operators)
2929
* [Rule Results](#rule-results)
30+
* [Persisting](#persisting)
3031

3132
## Methods
3233

@@ -380,3 +381,17 @@ Rule results are structured similar to rules, with two additional pieces of meta
380381
```
381382
382383
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 = new Rule(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

Comments
 (0)