New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
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 1.7.0 to 1.7.1

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;if("string"==typeof t){for(var i=t.split("."),s=this.facts,o=0;o<i.length-1&&void 0!==(s=s[i[o]]);o++);return void 0!==s&&(s[i[i.length-1]]=n),this.evaluatedRules={},this.run().always(function(){r.resolve()}),r}},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){if(this.isEvaluatingFlg)return void 0!==this.events[e].bound._evaluation_event&&(this.events[e].bound._evaluation_event(this.facts),!0);for(var t in this.events[e].bound)this.events[e].bound[t](this.facts);return!1},t.prototype.on=function(e,t,n){void 0===this.events[e]&&this.addEvent(e),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});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,l=!1;"string"!=typeof u?o.reject():("!"===u.charAt(0)&&(l=!0,u=u.slice(1)),void 0!==n.rulesMap[u]&&!1===l?i(n.rulesMap[u]).done(function(){o.resolve()}).fail(function(){o.reject()}):void 0!==n.rulesMap[u]&&!0===l?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])&&(t=!0);s.resolve()}).fail(function(){n.evaluatedRules[i.name]=!1,s.reject()})}).fail(function(){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(){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.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.prototype.getFacts=function(e){for(var t=e.split("."),n=this.facts,r=0;r<t.length;r++)if(void 0===(n=n[t[r]]))return;return n},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()}).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});
{
"name": "rulesenginejs",
"version": "1.7.0",
"version": "1.7.1",
"description": "A simple front-end rules engine",

@@ -9,3 +9,4 @@ "main": "dist/rulesengine.min.js",

"build": "npm test && ./node_modules/minify/bin/minify.js ./src/RulesEngine.js > ./dist/rulesengine.min.js",
"debug": "./node_modules/mocha/bin/mocha --inspect-brk test.js"
"debug": "./node_modules/mocha/bin/mocha --inspect-brk test.js",
"publish": "npm run build && npm publish && git push origin master"
},

@@ -12,0 +13,0 @@ "author": "tetratorus",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc