RunKit + npm: node-rules

node v8.17.0
version: 1.0.0
endpointsharetweet
var RuleEngine = require("node-rules"); /* Creating Rule Engine instance */ var R = new RuleEngine(); /* Add a rule */ var rule = { "condition": function (R) { R.when(this.transactionTotal < 500); }, "consequence": function (R) { this.result = false; this.reason = "The transaction was blocked as it was less than 500"; R.stop(); } }; /* Register Rule */ R.register(rule); /* Add a Fact with less than 500 as transaction, and this should be blocked */ var fact = { "name": "user4", "application": "MOB2", "transactionTotal": 400, "cardType": "Credit Card" }; /* Check if the engine blocks it! */ R.execute(fact, function (data) { if (data.result) { console.log("Valid transaction"); } else { console.log("Blocked Reason:" + data.reason); } });
Created from: https://npm.runkit.com/node-rules
Loading…

no comments

    sign in to comment