verdict
A lightweight decision tree/rules engine.
Features
- Support for complex branching logic
- Support for
and
/or
boolean logic - Wide range of operators supported
- Support for "fallback" values so paths don't "fall through the cracks" once an initial condition is met
Installation
Install with yarn
:
yarn add verdict
Usage
; // Create a new DecisionTree; // Start by adding a child to the tree. Because the child doesn't specify a// `value`, it's assumed to be a "branch" node which means that it's expected to// have one or more children (at some point).; // Follow the same process for adding another descendent (grandchild in this// case). Note that it's not necessary to have this as a separate step. We// easily could have included a `children` property within our first payload// that we passed to `addChild` and included the grandchild there.child.addChild; ; console.logtree.evaluatedata; // Yay! I'm a leaf node!
If you're not interested in creating a decision tree, you can import Rule
from
the package and use it on its own.
Inspiration
This library was inspired by verdict.js.