Skip to content

juicekit/js-rules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published