You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

rulesenginejs

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rulesenginejs - npm Package Compare versions

Comparing version

to
1.7.3

2

dist/rulesengine.min.js

@@ -1,1 +0,1 @@

!function(e,t){if("function"==typeof define&&define.amd)define(t);else{var n=t();"object"!=typeof module?e[n.name]=n:module.exports=n}}(this,function(){var e;"undefined"==typeof $&&require("jsdom-no-contextify").env("",function(t,n){t?console.error(t):($=require("jquery")(n),e=$)});var t=function(t){this.facts={},this.rules=[],this.rulesMap={},this.evaluatedRules={},this.events={},this.isEvaluatingFlg=!1,void 0!==t&&(e=t)};return t.prototype.constructor=t,t.prototype.updateFacts=function(t,n){var r=e.Deferred();if("object"==typeof t)return this.evaluatedRules={},this.facts=t,this.run().always(function(){r.resolve()}),r},t.prototype.getFacts=function(e){var t=JSON.parse(JSON.stringify(this.facts));if(void 0===e||"string"!=typeof e)return t;for(var n=e.split("."),r=0;r<n.length;r++)if(void 0===(t=t[n[r]]))return;return t},t.prototype.addRule=function(t,n,r){if("string"==typeof t){if("function"!=typeof n?n=function(){return e.Deferred().resolve()}:void 0===(n(this.facts)||{}).then&&(n=function(t){return function(n){var r=e.Deferred();return t(n)?setTimeout(r.resolve,0):setTimeout(r.reject,0),r}}(n)),(Array.isArray(r)||"object"!=typeof r)&&(r={}),void 0===r.priority&&(r.priority=9),Array.isArray(r.events)||(void 0!==r.events?r.events=[r.events]:r.events=[]),void 0===this.rulesMap[t]&&this.rules.push(t),Array.isArray(r.events))for(var i=0;i<r.events.length;i++)"string"==typeof r.events[i]&&this.addEvent(r.events[i]);else"string"==typeof r.events&&this.addEvent(r.events);void 0===this.events[t]&&(this.addEvent(t),Object.defineProperty(this.events[t],"_auto_generated_",{value:!0})),r.events.push(t),this.rulesMap[t]={name:t,events:r.events,test:n,priority:r.priority,conditions:r.conditions}}},t.prototype.addRules=function(e){if(!Array.isArray(e))return!1;for(var t=0;t<e.length;t++)Array.isArray(e[t])&&this.addRule.apply(this,e[t])},t.prototype.removeRule=function(e){for(var t=0;t<this.rules.length;t++)this.rules[t]===e&&this.rules.splice(t,1);delete this.rulesMap[e],this.events[e]&&!0===this.events[e]._auto_generated_&&delete this.events[e]},t.prototype.addEvent=function(e){this.events[e]={bound:{}}},t.prototype.addEvents=function(e){if(!Array.isArray(e))return!1;for(var t=0;t<e.length;t++)Array.isArray(e[t])?this.addEvent.apply(this,e[t]):this.addEvent.call(this,e[t])},t.prototype.removeEvent=function(e){delete this.events[e]},t.prototype.emit=function(e,t){if(t)return void 0!==this.events[e].bound._evaluation_event&&(this.events[e].bound._evaluation_event(this.facts),!0);for(var n in this.events[e].bound)this.events[e].bound[n](this.facts);return!1},t.prototype.on=function(e,t,n){this.events[e].bound[t]=n},t.prototype.off=function(e,t){void 0!==t?delete this.events[e].bound[t]:this.events[e].bound={}},t.prototype.run=function(){var t=!1,n=this;n.rules.sort(function(e,t){return n.rulesMap[e].priority>n.rulesMap[t].priority?1:n.rulesMap[e].priority<n.rulesMap[t].priority?-1:0});var r=function(s){var o=e.Deferred();if(t)return o.resolve();if(void 0===s)return o.resolve();var a=[];if(void 0!==s.all)s.all.forEach(function(e){a.push(r(e))}),e.when.apply(e,a).done(function(){o.resolve()}).fail(function(){o.reject()});else if(void 0!==s.any)s.any.forEach(function(t){a.push(function(){var n=e.Deferred();return r(t).done(function(){n.reject()}).fail(function(){n.resolve()}),n}())}),e.when.apply(e,a).done(function(){o.reject()}).fail(function(){o.resolve()});else{var u=s,v=!1;"string"!=typeof u?o.reject():("!"===u.charAt(0)&&(v=!0,u=u.slice(1)),void 0!==n.rulesMap[u]&&!1===v?i(n.rulesMap[u]).done(function(){o.resolve()}).fail(function(){o.reject()}):void 0!==n.rulesMap[u]&&!0===v?i(n.rulesMap[u]).done(function(){o.reject()}).fail(function(){o.resolve()}):o.reject())}return o},i=function(i){var s=e.Deferred();return t?s.resolve():void 0===i?s.resolve():!0===n.evaluatedRules[i.name]?s.resolve():!1===n.evaluatedRules[i.name]?s.reject():void 0!==n.evaluatedRules[i.name]&&"function"==typeof n.evaluatedRules[i.name].always?(n.evaluatedRules[i.name].done(function(){s.resolve()}).fail(function(){s.reject()}),s):(n.evaluatedRules[i.name]=s,void 0!==i.conditions?r(i.conditions).done(function(){i.test(n.facts).done(function(){n.evaluatedRules[i.name]=!0;for(var e=0;e<i.events.length;e++)!0===n.emit(i.events[e],n.isEvaluatingFlg)&&(t=!0);s.resolve()}).fail(function(){void 0!==((n.events[i.name]||{}).bound||{})._evaluation_event&&(t=!0),n.evaluatedRules[i.name]=!1,s.reject()})}).fail(function(){void 0!==((n.events[i.name]||{}).bound||{})._evaluation_event&&(t=!0),s.reject()}):i.test(n.facts).done(function(){n.evaluatedRules[i.name]=!0;for(var e=0;e<i.events.length;e++)!0===n.emit(i.events[e],n.isEvaluatingFlg)&&(t=!0);s.resolve()}).fail(function(){void 0!==((n.events[i.name]||{}).bound||{})._evaluation_event&&(t=!0),n.evaluatedRules[i.name]=!1,s.reject()}),s)};if(0===Object.keys(n.rulesMap).length)return e.Deferred().resolve();var s=e.Deferred(),o=function(e,t){t(e).always(function(){e<n.rules.length?o(e+1,t):s.resolve()})};return o(0,function(e){return i(n.rulesMap[n.rules[e]])}),s},t.prototype.evaluate=function(t,n){var r,i=e.Deferred(),s=this.facts,o=JSON.stringify(this.evaluatedRules),a=this;return void 0!==n&&(this.facts=n),this.rulesMap[t]&&!0===this.events[t]._auto_generated_&&(r=this.rulesMap[t].priority,this.rulesMap[t].priority=-1/0),this.isEvaluatingFlg=!0,this.evaluatedRules={},this.on(t,"_evaluation_event",function(e){a.off(t,"_evaluation_event"),a.facts=s,a.evaluatedRules=JSON.parse(o),void 0!==r&&(a.rulesMap[t].priority=r),a.isEvaluatingFlg=!1,i.resolve()}),this.run().always(function(){a.off(t,"_evaluation_event"),a.facts=s,a.evaluatedRules=JSON.parse(o),void 0!==r&&(a.rulesMap[t].priority=r),a.isEvaluatingFlg=!1,i.reject()}),i},t});
!function(e,t){if("function"==typeof define&&define.amd)define(t);else{var n=t();"object"!=typeof module?e[n.name]=n:module.exports=n}}(this,function(){var e;"undefined"==typeof $&&require("jsdom-no-contextify").env("",function(t,n){t?console.error(t):($=require("jquery")(n),e=$)});var t=function(t){this.facts={},this.rules=[],this.rulesMap={},this.evaluatedRules={},this.events={},this.isEvaluatingFlg=!1,void 0!==t&&(e=t)};return t.prototype.constructor=t,t.prototype.updateFacts=function(t,n){var r=e.Deferred();if("object"==typeof t)return this.evaluatedRules={},this.facts=t,this.run().always(function(){r.resolve()}),r},t.prototype.getFacts=function(e){var t=JSON.parse(JSON.stringify(this.facts));if(void 0===e||"string"!=typeof e)return t;for(var n=e.split("."),r=0;r<n.length;r++)if(void 0===(t=t[n[r]]))return;return t},t.prototype.addRule=function(t,n,r){if("string"==typeof t){if("function"!=typeof n?n=function(){return e.Deferred().resolve()}:void 0===(n(this.facts)||{}).then&&(n=function(t){return function(n){var r=e.Deferred();return t(n)?setTimeout(r.resolve,0):setTimeout(r.reject,0),r}}(n)),(Array.isArray(r)||"object"!=typeof r)&&(r={}),void 0===r.priority&&(r.priority=9),Array.isArray(r.events)||(void 0!==r.events?r.events=[r.events]:r.events=[]),void 0===this.rulesMap[t]&&this.rules.push(t),Array.isArray(r.events))for(var i=0;i<r.events.length;i++)"string"==typeof r.events[i]&&this.addEvent(r.events[i]);else"string"==typeof r.events&&this.addEvent(r.events);void 0===this.events[t]&&(this.addEvent(t),Object.defineProperty(this.events[t],"_auto_generated_",{value:!0})),r.events.push(t),this.rulesMap[t]={name:t,events:r.events,test:n,priority:r.priority,conditions:r.conditions}}},t.prototype.addRules=function(e){if(!Array.isArray(e))return!1;for(var t=0;t<e.length;t++)Array.isArray(e[t])&&this.addRule.apply(this,e[t])},t.prototype.removeRule=function(e){for(var t=0;t<this.rules.length;t++)this.rules[t]===e&&this.rules.splice(t,1);delete this.rulesMap[e],this.events[e]&&!0===this.events[e]._auto_generated_&&delete this.events[e]},t.prototype.addEvent=function(e){this.events[e]={bound:{}}},t.prototype.addEvents=function(e){if(!Array.isArray(e))return!1;for(var t=0;t<e.length;t++)Array.isArray(e[t])?this.addEvent.apply(this,e[t]):this.addEvent.call(this,e[t])},t.prototype.removeEvent=function(e){delete this.events[e]},t.prototype.emit=function(e,t){if(t)return void 0!==this.events[e].bound._evaluation_event&&(this.events[e].bound._evaluation_event(this.facts),!0);for(var n in this.events[e].bound)this.events[e].bound[n](this.facts);return!1},t.prototype.on=function(e,t,n){this.events[e].bound[t]=n},t.prototype.off=function(e,t){void 0!==t?delete this.events[e].bound[t]:this.events[e].bound={}},t.prototype.run=function(){var t=!1,n=this;n.rules.sort(function(e,t){return n.rulesMap[e].priority>n.rulesMap[t].priority?1:n.rulesMap[e].priority<n.rulesMap[t].priority?-1:0});var r=function(s){var o=e.Deferred();if(t)return o.resolve();if(void 0===s)return o.resolve();var a=[];if(void 0!==s.all)s.all.forEach(function(e){a.push(r(e))}),e.when.apply(e,a).done(function(){o.resolve()}).fail(function(){o.reject()});else if(void 0!==s.any)s.any.forEach(function(t){a.push(function(){var n=e.Deferred();return r(t).done(function(){n.reject()}).fail(function(){n.resolve()}),n}())}),e.when.apply(e,a).done(function(){o.reject()}).fail(function(){o.resolve()});else{var u=s,v=!1;"string"!=typeof u?o.reject():("!"===u.charAt(0)&&(v=!0,u=u.slice(1)),void 0!==n.rulesMap[u]&&!1===v?i(n.rulesMap[u]).done(function(){o.resolve()}).fail(function(){o.reject()}):void 0!==n.rulesMap[u]&&!0===v?i(n.rulesMap[u]).done(function(){o.reject()}).fail(function(){o.resolve()}):o.reject())}return o},i=function(i){var s=e.Deferred();return t?s.resolve():void 0===i?s.resolve():!0===n.evaluatedRules[i.name]?s.resolve():!1===n.evaluatedRules[i.name]?s.reject():void 0!==n.evaluatedRules[i.name]&&"function"==typeof n.evaluatedRules[i.name].always?(n.evaluatedRules[i.name].done(function(){s.resolve()}).fail(function(){s.reject()}),s):(n.evaluatedRules[i.name]=s,void 0!==i.conditions?r(i.conditions).done(function(){i.test(n.facts).done(function(){n.evaluatedRules[i.name]=!0;for(var e=0;e<i.events.length;e++)!0===n.emit(i.events[e],n.isEvaluatingFlg)&&(t=!0);s.resolve(),n.evaluatedRules[i.name]=!0}).fail(function(){void 0!==((n.events[i.name]||{}).bound||{})._evaluation_event&&(t=!0),n.evaluatedRules[i.name]=!1,s.reject(),n.evaluatedRules[i.name]=!1})}).fail(function(){void 0!==((n.events[i.name]||{}).bound||{})._evaluation_event&&(t=!0),s.reject(),n.evaluatedRules[i.name]=!1}):i.test(n.facts).done(function(){for(var e=0;e<i.events.length;e++)!0===n.emit(i.events[e],n.isEvaluatingFlg)&&(t=!0);s.resolve(),n.evaluatedRules[i.name]=!0}).fail(function(){void 0!==((n.events[i.name]||{}).bound||{})._evaluation_event&&(t=!0),s.reject(),n.evaluatedRules[i.name]=!1}),s)};if(0===Object.keys(n.rulesMap).length)return e.Deferred().resolve();var s=e.Deferred(),o=function(e,t){t(e).always(function(){e<n.rules.length?o(e+1,t):s.resolve()})};return o(0,function(e){return i(n.rulesMap[n.rules[e]])}),s},t.prototype.evaluate=function(t,n){var r,i=e.Deferred(),s=this.facts,o=JSON.stringify(this.evaluatedRules),a=this;return void 0!==n&&(this.facts=n),this.rulesMap[t]&&!0===this.events[t]._auto_generated_&&(r=this.rulesMap[t].priority,this.rulesMap[t].priority=-1/0),this.isEvaluatingFlg=!0,this.evaluatedRules={},this.on(t,"_evaluation_event",function(e){a.off(t,"_evaluation_event"),a.facts=s,a.evaluatedRules=JSON.parse(o),void 0!==r&&(a.rulesMap[t].priority=r),a.isEvaluatingFlg=!1,i.resolve()}),this.run().always(function(){a.off(t,"_evaluation_event"),a.facts=s,a.evaluatedRules=JSON.parse(o),void 0!==r&&(a.rulesMap[t].priority=r),a.isEvaluatingFlg=!1,i.reject()}),i},t});
{
"name": "rulesenginejs",
"version": "1.7.2",
"version": "1.7.3",
"description": "A simple front-end rules engine",

@@ -5,0 +5,0 @@ "main": "dist/rulesengine.min.js",

@@ -330,2 +330,3 @@ (function(scope, factory) {

deferred.resolve();
context.evaluatedRules[rule.name] = true;
}).fail(function() {

@@ -335,2 +336,3 @@ if (((context.events[rule.name]||{}).bound||{})._evaluation_event !== undefined) exit = true;

deferred.reject();
context.evaluatedRules[rule.name] = false;
});

@@ -341,2 +343,3 @@ })

deferred.reject();
context.evaluatedRules[rule.name] = false;
});

@@ -346,3 +349,2 @@ } else {

.done(function() {
context.evaluatedRules[rule.name] = true;
for (var j = 0; j < rule.events.length; j++) {

@@ -352,7 +354,8 @@ if (context.emit(rule.events[j], context.isEvaluatingFlg) === true) exit = true;

deferred.resolve();
context.evaluatedRules[rule.name] = true;
})
.fail(function() {
if (((context.events[rule.name]||{}).bound||{})._evaluation_event !== undefined) exit = true;
deferred.reject();
context.evaluatedRules[rule.name] = false;
deferred.reject();
});

@@ -359,0 +362,0 @@ }