Skip to content
forked from juicekit/js-rules

A javascript/typescript rule engine implementation

Notifications You must be signed in to change notification settings

ynunez/js-rules

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 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

A javascript/typescript rule engine implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.6%
  • JavaScript 1.4%