logic-rule
Version:
Logical rules
12 lines • 10.7 kB
JavaScript
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(t.LogicRule={})}(this,function(t){"use strict";function n(){throw Error("Dynamic requires are not currently supported by rollup-plugin-commonjs")}var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},r=(function(t,n){n={exports:{}},t(n,n.exports),n.exports}(function(t,r){/*!
* @overview es6-promise - a tiny implementation of Promises/A+.
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
* @license Licensed under MIT license
* See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
* @version v4.2.8+1e68dce6
*/
!function(r,o){t.exports=function(){function t(t){var n=typeof t;return null!==t&&("object"===n||"function"===n)}function r(t){return"function"==typeof t}function o(t){L=t}function i(t){K=t}function u(){return void 0!==D?function(){D(s)}:c()}function c(){var t=setTimeout;return function(){return t(s,1)}}function s(){for(var t=0;t<q;t+=2){(0,H[t])(H[t+1]),H[t]=void 0,H[t+1]=void 0}q=0}function f(t,n){var e=this,r=new this.constructor(l);void 0===r[J]&&E(r);var o=e._state;if(o){var i=arguments[o-1];K(function(){return x(o,r,i,e._result)})}else O(e,r,t,n);return r}function a(t){var n=this;if(t&&"object"==typeof t&&t.constructor===n)return t;var e=new n(l);return m(e,t),e}function l(){}function p(){return new TypeError("You cannot resolve a promise with itself")}function h(){return new TypeError("A promises callback cannot return that same promise.")}function y(t,n,e,r){try{t.call(n,e,r)}catch(t){return t}}function d(t,n,e){K(function(t){var r=!1,o=y(e,n,function(e){r||(r=!0,n!==e?m(t,e):w(t,e))},function(n){r||(r=!0,g(t,n))},"Settle: "+(t._label||" unknown promise"));!r&&o&&(r=!0,g(t,o))},t)}function v(t,n){n._state===V?w(t,n._result):n._state===X?g(t,n._result):O(n,void 0,function(n){return m(t,n)},function(n){return g(t,n)})}function _(t,n,e){n.constructor===t.constructor&&e===f&&n.constructor.resolve===a?v(t,n):void 0===e?w(t,n):r(e)?d(t,n,e):w(t,n)}function m(n,e){if(n===e)g(n,p());else if(t(e)){var r=void 0;try{r=e.then}catch(t){return void g(n,t)}_(n,e,r)}else w(n,e)}function b(t){t._onerror&&t._onerror(t._result),A(t)}function w(t,n){t._state===Q&&(t._result=n,t._state=V,0!==t._subscribers.length&&K(A,t))}function g(t,n){t._state===Q&&(t._state=X,t._result=n,K(b,t))}function O(t,n,e,r){var o=t._subscribers,i=o.length;t._onerror=null,o[i]=n,o[i+V]=e,o[i+X]=r,0===i&&t._state&&K(A,t)}function A(t){var n=t._subscribers,e=t._state;if(0!==n.length){for(var r=void 0,o=void 0,i=t._result,u=0;u<n.length;u+=3)r=n[u],o=n[u+e],r?x(e,r,o,i):o(i);t._subscribers.length=0}}function x(t,n,e,o){
var i=r(e),u=void 0,c=void 0,s=!0;if(i){try{u=e(o)}catch(t){s=!1,c=t}if(n===u)return void g(n,h())}else u=o;n._state!==Q||(i&&s?m(n,u):s===!1?g(n,c):t===V?w(n,u):t===X&&g(n,u))}function j(t,n){try{n(function(n){m(t,n)},function(n){g(t,n)})}catch(n){g(t,n)}}function P(){return Z++}function E(t){t[J]=Z++,t._state=void 0,t._result=void 0,t._subscribers=[]}function C(){return Error("Array Methods must be provided an Array")}function R(t){return new $(this,t).promise}function S(t){var n=this;return new n(Y(t)?function(e,r){for(var o=t.length,i=0;i<o;i++)n.resolve(t[i]).then(e,r)}:function(t,n){return n(new TypeError("You must pass an array to race."))})}function T(t){var n=this,e=new n(l);return g(e,t),e}function k(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function M(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function F(){var t=void 0;if(void 0!==e)t=e;else if("undefined"!=typeof self)t=self;else try{t=Function("return this")()}catch(t){throw Error("polyfill failed because global object is unavailable in this environment")}var n=t.Promise;if(n){var r=null;try{r=Object.prototype.toString.call(n.resolve())}catch(t){}if("[object Promise]"===r&&!n.cast)return}t.Promise=tt}var N=void 0;N=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var Y=N,q=0,D=void 0,L=void 0,K=function(t,n){H[q]=t,H[q+1]=n,2===(q+=2)&&(L?L(s):I())},U="undefined"!=typeof window?window:void 0,W=U||{},z=W.MutationObserver||W.WebKitMutationObserver,B="undefined"==typeof self&&"undefined"!=typeof process&&"[object process]"==={}.toString.call(process),G="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,H=Array(1e3),I=void 0;I=B?function(){return function(){return process.nextTick(s)}}():z?function(){var t=0,n=new z(s),e=document.createTextNode("");return n.observe(e,{characterData:!0
}),function(){e.data=t=++t%2}}():G?function(){var t=new MessageChannel;return t.port1.onmessage=s,function(){return t.port2.postMessage(0)}}():void 0===U&&"function"==typeof n?function(){try{var t=Function("return this")().require("vertx");return D=t.runOnLoop||t.runOnContext,u()}catch(t){return c()}}():c();var J=Math.random().toString(36).substring(2),Q=void 0,V=1,X=2,Z=0,$=function(){function t(t,n){this._instanceConstructor=t,this.promise=new t(l),this.promise[J]||E(this.promise),Y(n)?(this.length=n.length,this._remaining=n.length,this._result=Array(this.length),0===this.length?w(this.promise,this._result):(this.length=this.length||0,this._enumerate(n),0===this._remaining&&w(this.promise,this._result))):g(this.promise,C())}return t.prototype._enumerate=function(t){for(var n=0;this._state===Q&&n<t.length;n++)this._eachEntry(t[n],n)},t.prototype._eachEntry=function(t,n){var e=this._instanceConstructor,r=e.resolve;if(r===a){var o=void 0,i=void 0,u=!1;try{o=t.then}catch(t){u=!0,i=t}if(o===f&&t._state!==Q)this._settledAt(t._state,n,t._result);else if("function"!=typeof o)this._remaining--,this._result[n]=t;else if(e===tt){var c=new e(l);u?g(c,i):_(c,t,o),this._willSettleAt(c,n)}else this._willSettleAt(new e(function(n){return n(t)}),n)}else this._willSettleAt(r(t),n)},t.prototype._settledAt=function(t,n,e){var r=this.promise;r._state===Q&&(this._remaining--,t===X?g(r,e):this._result[n]=e),0===this._remaining&&w(r,this._result)},t.prototype._willSettleAt=function(t,n){var e=this;O(t,void 0,function(t){return e._settledAt(V,n,t)},function(t){return e._settledAt(X,n,t)})},t}(),tt=function(){function t(n){this[J]=P(),this._result=this._state=void 0,this._subscribers=[],l!==n&&("function"!=typeof n&&k(),this instanceof t?j(this,n):M())}return t.prototype.catch=function(t){return this.then(null,t)},t.prototype.finally=function(t){var n=this,e=n.constructor;return r(t)?n.then(function(n){return e.resolve(t()).then(function(){return n})},function(n){return e.resolve(t()).then(function(){throw n})}):n.then(t,t)},t}()
;return tt.prototype.then=f,tt.all=R,tt.race=S,tt.resolve=a,tt.reject=T,tt._setScheduler=o,tt._setAsap=i,tt._asap=K,tt.polyfill=F,tt.Promise=tt,tt.polyfill(),tt}()}()}),function(t){return!!t&&("object"==typeof t||"function"==typeof t)&&"function"==typeof t.then}),o=function(){function t(n){this.rules=[],"function"==typeof n&&(this.checkCb=t.getCheckCb(n))}return t.getCheckCb=function(t){return"function"==typeof t?t:function(){return r(t)?t:!!t}},t.only=function(t){throw Error("only("+t+") method is not implemented")},t.and=function(t,n){throw Error("and("+t+","+n+") method is not implemented")},t.not=function(t){throw Error("not("+t+") method is not implemented")},t.or=function(t,n){throw Error("or("+t+", "+n+") method is not implemented")},t.prototype.add=function(t){this.rules.push(t)},t.prototype.and=function(n){return n?t.and(this,n):this},t.prototype.or=function(n){return n?t.or(this,n):this},t.prototype.not=function(){return t.not(this)},t}(),i=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),u=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return i(n,t),n.prototype.execute=function(){var t=this.rules[0],n=this.rules[1];if(!t||!n)throw Error("The rule cannot be empty");var e=t.execute(),o=n.execute();return r(e)||r(o)?Promise.all([e,o]).then(function(t){return t[0]&&t[1]}):t.execute()&&n.execute()},n}(o);o.and=function(t,n){var e=new u;return e.add(t),e.add(n),e};var c=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),s=function(t){
function n(){return null!==t&&t.apply(this,arguments)||this}return c(n,t),n.prototype.execute=function(){var t=this.rules[0];if(!t)return!1;var n=t.execute();return r(n)?Promise.resolve(n).then(function(t){return!t}):!t.execute()},n}(o);o.not=function(t){var n=new s;return n.add(t),n};var f=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),a=function(t){function n(n){return t.call(this,n)||this}return f(n,t),n.prototype.execute=function(){return this.checkCb()},n}(o);o.only=function(t){return new a(this.getCheckCb(t))};var l=function(){var t=function(n,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])})(n,e)};return function(n,e){function r(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),p=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return l(n,t),n.prototype.execute=function(){var t=this.rules[0],n=this.rules[1];if(!t||!n)throw Error("The rule cannot be empty");var e=t.execute(),o=n.execute();return r(e)||r(o)?Promise.all([e,o]).then(function(t){return t[0]||t[1]}):t.execute()||n.execute()},n}(o);o.or=function(t,n){var e=new p;return e.add(t),e.add(n),e};var h={Rule:o,AndRule:u,OrRule:p,NotRule:s,OnlyRule:a};t.Rule=o,t.AndRule=u,t.OrRule=p,t.NotRule=s,t.OnlyRule=a,t.default=h,Object.defineProperty(t,"__esModule",{value:!0})});