JuiceKit Rules is a Javascript rule engine implementation
npm install @juicekit/rules
const adultRules = new Rules();
adultRules.register({
Name: 'Adult',
Description: '',
condition: (facts) => {
return facts.get('age') >= 18;
}
});
const person = new Facts();
person.set('age', 18);
adultRules.verify(person).subscribe((rule) => {
// rule being validated
}, (rule) => {
// failed rule
}, () => {
// completed successfully
});
const adultFemaleRules = new Rules();
adultFemaleRules.register({
Name: 'Adult',
Description: '',
condition: (facts) => {
return facts.get('age') >= 18;
}
});
adultFemaleRules.register({
Name: 'Female',
Description: '',
condition: (facts) => {
return facts.get('gender') === 'F' || facts.get('gender') === 'Female';
}
});
const person = new Facts();
person.set('age', 18);
person.set('gender', 'F');
adultFemaleRules.verify(person).subscribe((rule) => {
// rule being validated
}, (rule) => {
// failed rule
}, () => {
// completed successfully
});