UNPKG

xior

Version:

A lite http request lib based on fetch with plugins support and similar API to axios.

1 lines 5.98 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xiorErrorRetry=t():e.xiorErrorRetry=t()}(this,(function(){return function(){"use strict";var e={99:function(e,t,r){var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.buildSortedURL=void 0,t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t(1)}),e)}))};const o=n(r(629));t.buildSortedURL=o.default},330:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.DELETE=t.PATCH=t.PUT=t.POST=t.OPTIONS=t.GET=t.HEAD=t.m=t.isArray=t.keys=t.op=t.nullValue=t.undefinedValue=t.O=t.h=t.status=t.addEventListener=t.qs=t.abort=t.json=t.text=t.p=t.f=t.o=void 0,t.o="object",t.f="function",t.p="prototype",t.text="text",t.json="json",t.abort="abort",t.qs="paramsSerializer",t.addEventListener="addEventListener",t.status="status",t.h="headers",t.O=Object,t.undefinedValue=void 0,t.nullValue=null,t.op=t.O[t.p],t.keys=t.O.keys,t.isArray=Array.isArray,t.m="method",t.HEAD="HEAD",t.GET="GET",t.OPTIONS="OPTIONS",t.POST="POST",t.PUT="PUT",t.PATCH="PATCH",t.DELETE="DELETE"},351:function(e,t,r){var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function u(e){try{a(n.next(e))}catch(e){i(e)}}function s(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,s)}a((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e={}){const{retryTimes:t,retryInterval:r,enableRetry:u,onRetry:s}=Object.assign({retryTimes:2,retryInterval:3e3},e);return function(e,a){return l=>n(this,void 0,void 0,(function*(){const{retryTimes:c=t,retryInterval:f=r,enableRetry:d=u,onRetry:p=s}=l;let y=0;return function t(){return n(this,arguments,void 0,(function*(r=!1){var n;if(r&&(null==a?void 0:a.REQI))for(const e of a.REQI)l=yield e(l);try{let t=e(l),r=0;const o=[];for(null===(n=null==a?void 0:a.RESI)||void 0===n||n.forEach((function(e){o.push(e.fn,e.onRejected)}));o.length>r;)t=t.then(o[r++],o[r++]);return l._did=!0,yield t}catch(e){const r=l.method===o.GET||Boolean(l.isGet),n=typeof d,u=n===o.f;let s=o.undefinedValue;if(u&&(s=d(l,e)),s===o.undefinedValue&&(s=u||n===`${o.undefinedValue}`?r:Boolean(d)),y>=c||!s)throw e;y++;const a=typeof f===o.f?f(y,l,e):f;return a&&a>0&&(yield(0,i.delay)(a)),p&&p(l,e,y),t(!0)}}))}()}))}};const o=r(330),i=r(976)},629:function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){const n=t?r(t):"",o=e.includes("?")?"&":"?",i=n?`${e}${o}${n}`:e,[u,s]=i.split("?");if(!s)return i;return`${u}?${s.split("&").sort().join("&")}`}},699:function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.anySignal=function(e,t){const r=new AbortController;function o(e){r.abort(e),u()}const i=[];for(const t of e){if(!0===(null==t?void 0:t.aborted)){o(t.reason);break}if(null==t?void 0:t[n.addEventListener]){const e=()=>{o(t.reason)};i.push((()=>{var r;null===(r=t.removeEventListener)||void 0===r||r.call(t,n.abort,e)})),t[n.addEventListener](n.abort,e)}}function u(){i.forEach((e=>e())),null==t||t()}const s=r.signal;return s.clear=u,s};const n=r(330)},729:function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const n=r(330),o=n.O.getPrototypeOf,i=e=>{if(e!==n.nullValue&&typeof e===n.o){if(typeof o===n.f){const t=o(e);return t===n.op||t===n.nullValue}return n.op.toString.call(e)===`[${n.o} Object]`}return!1};t.merge=(...e)=>e.reduce(((e,r)=>{if((0,n.isArray)(r))throw new TypeError(`Arguments must be ${n.o}s, not arrays.`);return(0,n.keys)(r).forEach((o=>{["__proto__","constructor",n.p].includes(o)||((0,n.isArray)(e[o])&&(0,n.isArray)(r[o])?e[o]=Array.from(new Set(e[o].concat(r[o]))):i(e[o])&&i(r[o])?e[o]=(0,t.merge)(e[o],r[o]):e[o]=r[o])})),e}),{})},976:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&!("get"in o?!t.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,o)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.XiorTimeoutError=t.XiorError=void 0,t.encodeParams=function e(t,r=!0,n=i.nullValue,o){if(t===i.undefinedValue||t===i.nullValue)return"";const u=[],s=r?encodeURIComponent:e=>e,a=(0,i.isArray)(t),{arrayFormat:l,allowDots:c,serializeDate:f}=o||{},d=e=>{if(c&&!a)return`.${e}`;if(a){if("brackets"===l)return"[]";if("repeat"===l)return""}return`[${e}]`};for(const a in t)if(i.op.hasOwnProperty.call(t,a)){let l=t[a];if(l!==i.undefinedValue){const t=n?`${n}${d(a)}`:s(a);if(!isNaN(l)&&l instanceof Date&&(l=f?f(l):l.toISOString()),typeof l===i.o){const n=e(l,r,t,o);""!==n&&u.push(n)}else u.push(`${s(t)}=${s(l)}`)}}return u.join("&")},t.trimUndefined=function e(t){return(0,i.isArray)(t)?t.map(e):(t&&typeof t===i.o&&(0,i.keys)(t).forEach((r=>{const n=t[r];n===i.undefinedValue?delete t[r]:e(n)})),t)},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.joinPath=function(e,t){return e?t?(e.endsWith("/")?e:e+"/")+("/"===t[0]?t.slice(1):t):e:t||""},t.isXiorError=function(e){return(null==e?void 0:e.name)===u||(null==e?void 0:e.name)===s};const i=r(330);o(r(699),t),o(r(729),t),o(r(99),t);const u="XiorError",s="XiorTimeoutError";class a extends Error{constructor(e,t,r){super(e),this.name=u,this.request=t,this.config=t,this.response=r}}t.XiorError=a,t.XiorTimeoutError=class extends a{constructor(e,t,r){super(e,t,r),this.name=s}}}},t={},r=function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}(351);return r.default}()}));