This repository has been archived by the owner on May 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
1 lines (1 loc) · 7.84 KB
/
index.js
1
var e,t;e=this,t=function(e){function t(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((t=>Object.getOwnPropertyDescriptor(e,t).enumerable))),r.push.apply(r,n)}return r}function r(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?t(Object(n),!0).forEach((t=>{a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):t(Object(n)).forEach((t=>{Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function n(e){return n='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?e=>typeof e:e=>e&&'function'==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?'symbol':typeof e,n(e)}function o(e,t){if(!(e instanceof t))throw new TypeError('Cannot call a class as a function')}function i(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,c(n.key),n)}}function u(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),Object.defineProperty(e,'prototype',{writable:!1}),e}function a(e,t,r){return(t=c(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){return(e=>{if(Array.isArray(e))return e})(e)||((e,t)=>{var r=null==e?null:'undefined'!=typeof Symbol&&e[Symbol.iterator]||e['@@iterator'];if(null!=r){var n,o,i,u,a=[],l=!0,s=!1;try{if(i=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;l=!1}else for(;!(l=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(e){s=!0,o=e}finally{try{if(!l&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(s)throw o}}return a}})(e,t)||((e,t)=>{if(e){if('string'==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return'Object'===r&&e.constructor&&(r=e.constructor.name),'Map'===r||'Set'===r?Array.from(e):'Arguments'===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}})(e,t)||(()=>{throw new TypeError('Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.')})()}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function c(e){var t=((e,t)=>{if('object'!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||'default');if('object'!=typeof n)return n;throw new TypeError('@@toPrimitive must return a primitive value.')}return('string'===t?String:Number)(e)})(e,'string');return'symbol'==typeof t?t:String(t)}var h='Accept',f='Authorization',y='Content-Type',d='application/json',p='text/plain',b=new RegExp(d,'i');function v(e){if(e.headers.raw){var t=e.headers.raw();return Object.keys(t).reduce(((e,r)=>(e[r]=Array.isArray(t[r])?t[r].join(', '):t[r],e)),{})}return Array.from(e.headers.entries()).reduce(((e,t)=>(e[t[0]]=t[1],e)),{})}function m(e){return Object.entries(e).filter((e=>{var t=l(e,2)[1];return Boolean(t)})).map((e=>{var t=l(e,2),r=t[0],n=t[1];return''.concat(r,'=').concat(encodeURIComponent(n))})).join('&')}function g(e,t){return{status:e.status,headers:v(e),data:t}}function O(e){return b.test(e.headers.get(y))?e.json():e.text()}function j(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:O;return t=>e(t).then((e=>g(t,e)))}function k(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:O;return e.status<400?Promise.resolve(e):t(e).then((t=>{throw g(e,t)}))}function w(e,t,r){var o=[],i=!!Array.isArray(t)&&t;return JSON.stringify(e,((e,t)=>{if(''===e||!i||-1!==i.indexOf(e)){if('object'===n(t)&&null!==t){if(-1!==o.indexOf(t))return'[Circular]';o.push(t)}return t}}),r)}function T(e){try{return JSON.parse(e),!0}catch(e){return!1}}var P=function(){function e(t){var r,n=this;o(this,e),'undefined'!=typeof AbortController&&(this.controller=new AbortController,r=this.controller.signal),this.full=!1,this.queryParams={},this.params={headers:{},signal:r},t&&(this.baseURL=t.baseURL,t.headers&&Object.entries(t.headers).forEach((e=>{var t=l(e,2),r=t[0],o=t[1];return n.header(r,o)})),t.auth&&this.auth(t.auth),t.contentJson&&this.contentJson(),t.contentText&&this.contentText(),t.acceptJson&&this.acceptJson(),t.acceptText&&this.acceptText(),t.method&&this.method(t.method),t.query&&this.query(t.query),'function'==typeof t.contentHandler&&this.contentHandler(t.contentHandler),'function'==typeof t.errorHandler&&this.errorHandler(t.errorHandler),t.abortHandler&&this.abortHandler(t.abortHandler),t.fullResponse&&this.fullResponse())}return u(e,[{key:'url',value:function(e){return this.baseURL?this.url=''.concat(this.baseURL).concat(e):this.url=e,this}},{key:'query',value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.queryParams=r(r({},this.queryParams),e),this}},{key:'header',value:function(e,t){return this.params.headers[e]=t,this}},{key:'auth',value:function(e){return this.header(f,e)}},{key:'contentJson',value:function(){return this.header(y,d)}},{key:'contentText',value:function(){return this.header(y,p)}},{key:'guessContentType',value:function(e){return T(e)?this.contentJson():this.contentText()}},{key:'acceptJson',value:function(){return this.header(h,d)}},{key:'acceptText',value:function(){return this.header(h,p)}},{key:'contentHandler',value:function(e){return this.content=e,this}},{key:'errorHandler',value:function(e){return this.error=e,this}},{key:'abortHandler',value:function(e){return this.abort=e,this}},{key:'fullResponse',value:function(){return this.full=!0,this}},{key:'body',value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(void 0!==e){var r=e;if('object'===n(e)?r=w(e):'string'!=typeof e&&(r=String(e)),this.params.body=r,t&&!this.params.headers['Content-Type'])return this.guessContentType(r)}return this}},{key:'method',value:function(e){return this.params.method=e,this}},{key:'get',value:function(e){return this.method('GET').query(e).send()}},{key:'post',value:function(e){return this.body(e).method('POST').send()}},{key:'put',value:function(e){return this.body(e).method('PUT').send()}},{key:'patch',value:function(e){return this.body(e).method('PATCH').send()}},{key:'delete',value:function(){return this.method('DELETE').send()}},{key:'send',value:function(){var e=this.url,t=this.content;if(this.queryParams){var r=m(this.queryParams);r&&(-1===e.indexOf('?')?e+='?':e+='&',e+=r)}return this.full&&(t=j(t)),function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:O,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:k;return fetch(e,t).then((e=>o(e,n))).then(n).catch((e=>{if('AbortError'!==e.name||!r)throw e;r(e)}))}(e,this.params,this.abort,t,this.error)}},{key:'abort',value:function(){this.controller?this.controller.abort():console.warn('cannot abort fetch: no AbortController available.')}}]),e}(),E=function(){function e(){o(this,e)}return u(e,null,[{key:'withDefault',value:e=>{function t(){return new P(e)}return{url:e=>t().url(e),get:(e,r)=>t().url(e).get(r),post:(e,r)=>t().url(e).post(r),put:(e,r)=>t().url(e).put(r),patch:(e,r)=>t().url(e).patch(r),delete:e=>t().url(e).delete()}}},{key:'url',value:e=>(new P).url(e)},{key:'get',value:(e,t)=>(new P).url(e).get(t)},{key:'post',value:(e,t)=>(new P).url(e).post(t)},{key:'put',value:(e,t)=>(new P).url(e).put(t)},{key:'patch',value:(e,t)=>(new P).url(e).patch(t)},{key:'delete',value:e=>(new P).url(e).delete()}]),e}();e.ACCEPT_TYPE_HEADER=h,e.AUTHORIZATION_HEADER=f,e.CONTENT_TYPE_HEADER=y,e.MEDIA_TYPE_JSON=d,e.MEDIA_TYPE_TEXT=p,e.contentHandler=O,e.default=E,e.encode=m,e.errorHandler=k,e.fullContent=g,e.getReadContentFull=j,e.isJson=T,e.readHeaders=v,e.stringify=w,Object.defineProperty(e,'__esModule',{value:!0})},'object'==typeof exports&&'undefined'!=typeof module?t(exports,require('isomorphic-fetch')):'function'==typeof define&&define.amd?define(['exports','isomorphic-fetch'],t):t((e='undefined'!=typeof globalThis?globalThis:e||self).funtch={});