text: !function(e,t){"use strict";"function"==typeof define&&define.amd?define(function(){return t(e)}):"object"==typeof module&&"object"==typeof module.exports?module.exports=t(e):e.Belofte=t(e)}("undefined"!=typeof window?window:global,function(e){"use strict";var t=Object.defineProperty,n=Object.defineProperties,r=Array.prototype.slice,i=Array.isArray,o=function(){},c=function(e){return"function"==typeof e},u=function(e){return null!==e&&("object"==typeof e||"function"==typeof e)},l=function(e){return void 0===e||null===e},s=c(e.setImmediate)?function(t){e.setImmediate(t)}:"object"==typeof e.process&&c(e.process.nextTick)?function(t){e.process.nextTick(t)}:function(t){e.setTimeout(t,0)},f=function(e,t){if(!c(e))throw new TypeError(e+" is not a function");var n=r.call(arguments,2);s(function(){e.apply(t,n)})},a=function(e){return m.resolve(e)},_=function(e){return m.reject(e)},d=function(e){n(e,{_isPromise:{value:!0},_onFulfilled:{value:[]},_onRejected:{value:[]},_resolve:{value:function(e){p(this)||(n(this,{_state:{value:"fulfilled"},_value:{value:e}}),this._onFulfilled.length>0&&f(function(e){this._onFulfilled.forEach(function(t){t(e)}),this._onFulfilled.length=0,this._onRejected.length=0},this,e))}.bind(e),configurable:!0},_reject:{value:function(e){p(this)||(n(this,{_state:{value:"rejected"},_reason:{value:e}}),this._onRejected.length>0&&f(function(e){this._onRejected.forEach(function(t){t(e)}),this._onFulfilled.length=0,this._onRejected.length=0},this,e))}.bind(e),configurable:!0},_state:{value:"pending",configurable:!0},_value:{value:void 0,configurable:!0},_reason:{value:void 0,configurable:!0}})},h=function(e){return"pending"===e._state},v=function(e){return"fulfilled"===e._state},j=function(e){return"rejected"===e._state},p=function(e){return"fulfilled"===e._state||"rejected"===e._state},y=function(e){return!0===e._isPromise&&i(e._onFulfilled)&&i(e._onRejected)&&c(e._resolve)&&c(e._reject)&&(t=e._state,-1!==["pending","fulfilled","rejected"].indexOf(String(t)))&&e.hasOwnProperty("_value")&&e.hasOwnProperty("_reason");var t},w=function(e){return e instanceof m&&y(e)},g=function(e,t,r){var i,o,l,s,a,_,d=!1;if(e===t)e._reject(new TypeError("Chaining cycle detected for promise"));else if(w(t))v(t)?f(function(){e._resolve(t._value)}):j(t)?f(function(){e._reject(t._reason)}):h(t)&&(i=t._resolve,a=t._reject,n(t,{_resolve:{value:function(t){i.call(this,t),e._resolve(t)}.bind(t)},_reject:{value:function(t){a.call(this,t),e._reject(t)}.bind(t)}}));else if(u(t))try{o=t.then,c(o)?(l=function(t){d||(d=!0,g(e,t,!0))},s=function(t){d||(d=!0,e._reject(t))},_=function(){try{o.call(t,l,s)}catch(t){d||(d=!0,e._reject(t))}},r?f(_):_()):e._resolve(t)}catch(t){e._reject(t)}else e._resolve(t)},b={extend:function(e){if(l(e))throw new TypeError("Target object can't be null or undefined");var t,r,i;for(e=Object(e),t=1;t<arguments.length;++t)r=arguments[t],l(r)||(r=Object(r),i=Object.getOwnPropertyNames(r).reduce(function(e,t){return e[t]=Object.getOwnPropertyDescriptor(r,t),e},{}),n(e,i));return e}},m=function e(t){if(!(this instanceof e)||w(this))throw new TypeError(String(this)+" is not a promise");if(!c(t))throw new TypeError("Promise resolver "+String(t)+" is not a function");d(this),g(this,{then:t})};b.extend(m,{resolve:function(e){if(w(e))return e;var t=new m(o);return g(t,e,!0),t},reject:function(e){var t=new m(o);return t._reject(e),t},race:function(e){var t,i,s=new m(o),a=0,_=!1;if(l(e))return s._reject(new TypeError("First argument of Promise.race can not be undefined or null")),s;for(t=(e=r.call(e)).length,i=function(e){var t,r;w(e)?v(e)?_||(_=!0,f(function(){s._resolve(e._value)})):j(e)?_||(_=!0,f(function(){s._reject(e._reason)})):h(e)&&(t=e._resolve,r=e._reject,n(e,{_resolve:{value:function(e){t.call(this,e),_||(_=!0,s._resolve(e))}.bind(e)},_reject:{value:function(e){r.call(this,e),_||(_=!0,s._reject(e))}.bind(e)}})):u(e)&&c(e.then)?f(function(){try{e.then(function(e){_||(_=!0,g(s,e,!0))},function(e){_||(_=!0,s._reject(e))})}catch(e){_||(_=!0,s._reject(e))}}):_||(_=!0,f(function(){s._resolve(e)}))};a<t;++a)i(e[a]);return s},all:function(e){var i,s,a,_=new m(o),d=0,p=0;if(l(e))return _._reject(new TypeError("First argument of Promise.all can not be undefined or null")),_;if(e=r.call(e),i=e.length,a=new Array(i),0===i)return _._resolve(a),_;for(s=function(e,r){var o,l;w(e)?v(e)?(a[r]=e._value,++d===i&&f(function(){_._resolve(a)})):j(e)?f(function(){_._reject(e._reason)}):h(e)&&(o=e._resolve,l=e._reject,n(e,{_resolve:{value:function(e){o.call(this,e),a[r]=e,++d===i&&_._resolve(a)}.bind(e)},_reject:{value:function(e){l.call(this,e),_._reject(e)}.bind(e)}})):u(e)&&c(e.then)?f(function(){var n=!1;try{e.then(function(e){if(!n){n=!0;var o=_._resolve;t(_,"_resolve",{value:function(e){a[r]=e,++d===i&&o.call(this,a)}.bind(_)}),g(_,e,!0)}},function(e){n||(n=!0,_._reject(e))})}catch(e){n||(n=!0,_._reject(e))}}):(a[r]=e,++d===i&&f(function(){_._resolve(a)}))};p<i;++p)s(e[p],p);return _},defer:function(){return new P}}),b.extend(m.prototype,{then:function(e,t){if(!w(this))throw new TypeError(this+" is not a promise");e=c(e)?e:a,t=c(t)?t:_;var n,r,i=new m(o);return n=function(t){var n;try{n=e(t),g(i,n,!0)}catch(e){i._reject(e)}},r=function(e){var n;try{n=t(e),g(i,n,!0)}catch(e){i._reject(e)}},h(this)?(this._onFulfilled.push(n),this._onRejected.push(r)):v(this)?f(n,void 0,this._value):j(this)&&f(r,void 0,this._reason),i},catch:function(e){if(!c(this.then))throw new TypeError("(var).then is not a function");return this.then(void 0,e)},toString:function(){if(!w(this))throw new TypeError(this+" is not a promise");switch(this._state){case"pending":return"Promise { <pending> }";case"fulfilled":return"Promise { "+this._value+" }";case"rejected":return"Promise { <rejected> "+this._reason+" }"}}});var P=function(){this.promise=new m(o)};return b.extend(P.prototype,{resolve:function(e){g(this.promise,e,!0)},reject:function(e){this.promise._reject(e)}}),b.extend(b,{Promise:m,isPromise:w,isPending:h,isFulfilled:v,isRejected:j,isSettled:p,getState:function(e){return w(e)?e._state:null},getValue:function(e){return w(e)?e._value:null},getReason:function(e){return w(e)?e._reason:null},resolve:function(e){return m.resolve(e)},reject:function(e){return m.reject(e)},Deferred:P,defer:function(){return new P},resolved:function(e){return m.resolve(e)},rejected:function(e){return m.reject(e)},deferred:function(){return new P},runAsync:f}),b});