New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

rule-machine

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

rule-machine

Rules Engine for Node.JS

latest
Source
npmnpm
Version
0.0.5
Version published
Maintainers
1
Created
Source

Rule-Machine

Rules Engine for Node.JS

Installation

Using npm:

$ npm install rule-machine

Basic Usage

The following are some basic examples:

var rm = require('./rule-machine.js');
var rule = new rm({
    onlyNewFire : true // Fired only new events (default: true)
});

rule.on('FIRE',function(fired){ //Name of fired rule
    console.log(fired);
});

f = [
    {'id':6,'val':60},
    {'id':7,'val':70},
    {'id':8,'val':80}
];

rule.addFact(f, false); // Add array of facts. And NOT check rules after add

rul =[ 
    {
        name: 'Test1',
        when:[
            'and',
            {id:1, val:{$gte:10}},
            {id:3, val:30}
        ],
        callback: function(name){console.log('Callback for rule '+ name);}
    },{
        name: 'Test2',
        when:[
            'and',
            {id:2, val:{$gt:20}}
        ]
    },{
        name: 'Test3',
        when:[
            'or',
            {id:4, val:{$lt:10}},
            {id:5, lastVal: {$gte:50} }
        ]
    }
];

rule.addRule(rul); // Add array of rules

// add other facts
rule.addFact({'id':1,'val':10}, true); // add fact and check rules after add
rule.addFact({'id':2,'val':2});       // it same 
rule.addFact({'id':3,'val':30});
rule.addFact({'id':4,'val':40});
rule.addFact({'id':5,'val':50}, false); // add fact and NOT check rules after add

rule.modFact({'val':125}, {'id':2}); // modify fact where id=2 and set val=125

rule.modFact({'lastVal':60}, {'id':5}); //modify fact where id=5 and add new property lastVal=60

Keywords

rule

FAQs

Package last updated on 02 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts