Dynamic Rules
the most fun and fast way to eval javascript objects
Usage
- Passing an object and rules, getting the result.
const dynamicRules = require('dynamic-rules');
const myModel = {
amount: 118,
subtotal: 100,
taxes: 18,
typeDocument: {
name: 'INVOICE',
},
};
const config = {
condition: 'model.typeDocument.name === "INVOICE"',
formula: '(model.subtotal * model.amount) + 10',
};
const result = dynamicRules.execute(myModel, config);
console.log(result);
- Merging the result into your object
const dynamicRules = require('dynamic-rules');
const myModel = {
amount: 118,
subtotal: 100,
taxes: 18,
typeDocument: {
name: 'INVOICE',
},
};
const config = {
merge: true,
condition: 'model.typeDocument.name === "INVOICE"',
formula: '(model.subtotal * model.amount) + 10',
};
const result = dynamicRules.execute(myModel, config);
console.log(result);