How to use json-rules-engine - 6 common examples

To help you get started, we’ve selected a few json-rules-engine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mathcoll / t6 / t6decisionrules.js View on Github external
t6decisionrules.checkRulesFromUser = function(user_id, payload) {
	payload.user_id = user_id;
	rules = dbRules.getCollection("rules");
	
	var query = {
	"$and": [
			{ "user_id": { "$eq": user_id } },
			{ "active": true },
		]
	}
	var r = rules.chain().find(query).data();
	
	let engine = new Engine();
	if ( r.length > 0 ) {
		r.forEach(function(theRule) {
			theRule.rule.event.params.rule_id = theRule.id;
			engine.addRule(new Rule(theRule.rule));
		});
	}
	
	//conditions.facts = [user_id, environment, dtepoch, value, flow, datetime]
	//conditions.operators = [isDayTime:, user_id:, environment:, dtepoch:, value:, flow:, datetime:]
	//https://github.com/CacheControl/json-rules-engine/blob/master/docs/rules.md#operators
	
	// Event Condition example: 
	// {"all":[{"fact":"dtepoch","operator":"isDayTime","value":true}]}
	engine.addOperator("isDayTime", (factValue, jsonValue) => {
		var factLatitude = payload.latitude?payload.latitude:localization.latitude; // TODO: we should use https://github.com/CacheControl/json-rules-engine/blob/master/docs/rules.md#condition-helpers-params
		var factLongitude = payload.longitude?payload.longitude:localization.longitude;
github RxNT / react-jsonschema-form-conditionals / src / engine / CacheControlEngineFactory.js View on Github external
createEngine(rules) {
    this.rules = rules;
    this.engine = new Engine();
    rules.forEach(rule => this.engine.addRule(rule));
  }
github RxNT / react-jsonschema-form-conditionals / src / engine / CacheControlRulesEngine.js View on Github external
createEngine(rules) {
    this.rules = rules;
    this.engine = new Engine();
    rules.forEach(rule => this.engine.addRule(rule));
  }
github RxNT / react-jsonschema-form-conditionals / src / engine / CacheControlRulesEngine.js View on Github external
createEngine(rules) {
    this.rules = rules;
    this.engine = new Engine();
    rules.forEach(rule => this.engine.addRule(rule));
  }
github mathcoll / t6 / t6decisionrules.js View on Github external
r.forEach(function(theRule) {
			theRule.rule.event.params.rule_id = theRule.id;
			engine.addRule(new Rule(theRule.rule));
		});
	}

json-rules-engine

Rules Engine expressed in simple json

ISC
Latest version published 2 days ago

Package Health Score

85 / 100
Full package analysis

Popular json-rules-engine functions