JSON DSL for expressing and evaluating business rules. Underwriters use illogical to model business rules for their question sets, enabling distributors to render great user experiences.
This project is designed such that business rules can be shared between the front-end and back-end, serialized in JSON.
# install illogical
npm install @briza/illogical// Import the illogical engine
import Engine from '@briza/illogical'
// Create a new instance of the engine
const engine = new Engine()
// Data context
const ctx = {
name: 'peter',
age: 21,
address: {
city: 'Toronto',
country: 'Canada',
},
}
// Evaluate an expression in the given data context
engine.evaluate(['>', '$age', 20], ctx) // true
// Accessing a property
engine.evaluate(['==', '$address.city', 'Toronto'], ctx) // true
// Data Type Casting
engine.evaluate(['==', '$age.(String)', '21'], ctx) // true
// Evaluate a logical expression
engine.evaluate(['AND', ['>', '$age', 20], ['==', '$name', 'peter']]) // trueUnderstand supported expressions:
- Comparison Expressions
- Logical Expressions
- Arithmetic Expressions
- Evaluation Data Context
- Operand Types
Learn about usages:
Customize the engine and the documentation:
See changelog.md.
See contributing.md.
Illogical is released under the MIT license. See license.txt for details.