Skip to content

fuzzy-coder/rule-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

Condition and Consequence based async rule-engine in node. This package wraps https://github.com/mithunsatheesh/node-rules APIS and enables sync/async support

What is this repository for?

  • Provides Scalable flow control API. Prevents developer ending up in callback hell and if else mess.

How do I get set up?

  • npm install async-rule-engine

How do I use api?

  • create new RuleEngine instance which validates facts against rules.
  • use either waterfall or enqueue flow control methods and pass in rules.
  • simple rule example :
{
  "condition": function(){
      return this.user.type === 'customer'; // condition should rule should return a boolean value. if true consequence will be executed. fact object will be available under this 
  },
  "consequence": function(){
      this.message = 'Hello Customer';
  }
}
  • Validating facts
const engine = new RuleEngine();
engine.waterfall(rules); // list of rules.
engine.validate({'user':{'type': 'customer'}}, function(data){
    console.log(data.message);
});

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published