-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.min.js
1 lines (1 loc) · 4.55 KB
/
index.min.js
1
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.FetchWrapper=t():e.FetchWrapper=t()}(self,(function(){return function(){"use strict";var e={r:function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e,t,r,n,s,o,i){try{var a=e[o](i),u=a.value}catch(e){return void r(e)}a.done?t(u):Promise.resolve(u).then(n,s)}function n(e){return function(){var t=this,n=arguments;return new Promise((function(s,o){var i=e.apply(t,n);function a(e){r(i,s,o,a,u,"next",e)}function u(e){r(i,s,o,a,u,"throw",e)}a(void 0)}))}}function s(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}e.r(t);var o=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.options=Object.assign({},this.optionDefaults,t),this.options.baseURL.length>0&&"/"===this.options.baseURL[this.options.baseURL.length-1]&&(this.options.baseURL=this.options.baseURL.substr(0,this.options.baseURL.length-1))}var t,r,o,i,a,u,c,p,f;return t=e,(r=[{key:"request",value:(f=n(regeneratorRuntime.mark((function e(t,r){var n,s,o,i,a,u;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=Object.assign({},this.requestDefaults,r),e.prev=1,!(this.options.middleware.before.length>0)){e.next=11;break}s=0;case 4:if(!(s<this.options.middleware.before.length)){e.next=11;break}return e.next=7,this.options.middleware.before[s](n);case 7:r=e.sent;case 8:s++,e.next=4;break;case 11:return o=null,i=t.startsWith("/")?t:"/"+t,t.startsWith("http")||t.startsWith("https")?o=new URL(t):this.options.baseURL.length>0&&(o=new URL(this.options.baseURL+i)),e.next=16,fetch(o.toString(),n);case 16:if(a=e.sent,!(this.options.middleware.after.length>0)){e.next=26;break}u=0;case 19:if(!(u<this.options.middleware.after.length)){e.next=26;break}return e.next=22,this.options.middleware.after[u](a,n);case 22:a=e.sent;case 23:u++,e.next=19;break;case 26:return e.abrupt("return",a);case 29:return e.prev=29,e.t0=e.catch(1),e.abrupt("return",Promise.reject(e.t0));case 32:case"end":return e.stop()}}),e,this,[[1,29]])}))),function(e,t){return f.apply(this,arguments)})},{key:"get",value:(p=n(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.request(t,{method:"GET"});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"post",value:(c=n(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.request(t,{method:"POST",body:JSON.stringify(r)});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return c.apply(this,arguments)})},{key:"put",value:(u=n(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.request(t,{method:"PUT",body:JSON.stringify(r)});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return u.apply(this,arguments)})},{key:"patch",value:(a=n(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.request(t,{method:"PATCH",payload:JSON.stringify(r)});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"delete",value:(i=n(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.request(t,{method:"DELETE"});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"use",value:function(e,t){return e?"before"!==t&&"after"!==t?new Error('Valid pipeline values are "before" or "after"'):void this.options.middleware[t].push(e):new Error("Function required")}},{key:"optionDefaults",get:function(){return{baseURL:"",middleware:{before:[],after:[]}}}},{key:"requestDefaults",get:function(){return{method:"GET",cache:"no-cache",headers:{"Content-Type":"application/json",Accept:"application/json"}}}}])&&s(t.prototype,r),o&&s(t,o),e}();return t.default=o,t}()}));