@briza/illogical
v2.0.2
Published
A micro conditional javascript engine used to parse the raw logical and comparison expressions, evaluate the expression in the given data context, and provide access to a text form of the given expressions.
Downloads
1,590
Readme
This project is designed such that business rules can be shared between the front-end and back-end, serialized in JSON.
🚀 Get Started
# 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']]) // true🖼️ Resources
Understand supported expressions:
Learn about usages:
Customize the engine and the documentation:
📖 Changelog
See changelog.md.
🤝 Contributing
See contributing.md.
📜 License
Illogical is released under the MIT license. See license.txt for details.
