Skip to content

Latest commit

 

History

History
71 lines (56 loc) · 1.78 KB

README.md

File metadata and controls

71 lines (56 loc) · 1.78 KB

JuiceKit Rules

Build Status Codacy Badge Codacy Badge

JuiceKit Rules is a Javascript rule engine implementation

Installation

npm install @juicekit/rules

Example Usage

Adult Validation

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
});

Adult Female Validation

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
});