UNPKG

fetch-intercept

Version:

Interceptor library for the native fetch command inspired by angular http intercepts.

2 lines 1.55 kB
module.exports=function(r){function t(n){if(e[n])return e[n].exports;var o=e[n]={exports:{},id:n,loaded:!1};return r[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=r,t.c=e,t.p="",t(0)}([function(r,t,e){(function(t){"use strict";var n=e(1);r.exports=n(t)}).call(t,function(){return this}())},function(r,t,e){"use strict";function n(r){if(Array.isArray(r)){for(var t=0,e=Array(r.length);t<r.length;t++)e[t]=r[t];return e}return Array.from(r)}function o(r){for(var t=arguments.length,e=Array(t>1?t-1:0),o=1;o<t;o++)e[o-1]=arguments[o];var u=c.reduce(function(r,t){return[t].concat(r)},[]),i=Promise.resolve(e);return u.forEach(function(r){var t=r.request,e=r.requestError;(t||e)&&(i=i.then(function(r){return t.apply(void 0,n(r))},e))}),i=i.then(function(t){var e=new(Function.prototype.bind.apply(Request,[null].concat(n(t))));return r(e).then(function(r){return r.request=e,r}).catch(function(r){return r.request=e,Promise.reject(r)})}),u.forEach(function(r){var t=r.response,e=r.responseError;(t||e)&&(i=i.then(t,e))}),i}var c=[];r.exports=function(r){if(!r.fetch)try{e(2)}catch(r){throw Error("No fetch available. Unable to register fetch-intercept")}return r.fetch=function(r){return function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return o.apply(void 0,[r].concat(e))}}(r.fetch),{register:function(r){return c.push(r),function(){var t=c.indexOf(r);t>=0&&c.splice(t,1)}},clear:function(){c=[]}}}},function(r,t){r.exports=require("whatwg-fetch")}]); //# sourceMappingURL=node.min.js.map