UNPKG

xior

Version:

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

2 lines (1 loc) 2.56 kB
var f="object",S="function",P="prototype",q="text",U="json",b="abort",k="paramsSerializer",E="addEventListener",F="status",V="headers",y=Object,g=void 0,d=null,x=y[P],m=y.keys,p=Array.isArray,z="method",j="HEAD",H="GET",M="OPTIONS",N="POST",_="PUT",G="PATCH",W="DELETE";function Q(e,t){let o=new AbortController;function n(r){o.abort(r),s()}let c=[];for(let r of e){if((r==null?void 0:r.aborted)===!0){n(r.reason);break}if(r!=null&&r[E]){let l=()=>{n(r.reason)};c.push(()=>{var T;(T=r.removeEventListener)==null||T.call(r,b,l)}),r[E](b,l)}}function s(){c.forEach(r=>r()),t==null||t()}let u=o.signal;return u.clear=s,u}var K=y.getPrototypeOf,R=e=>{if(e!==d&&typeof e===f){if(typeof K===S){let t=K(e);return t===x||t===d}return x.toString.call(e)===`[${f} Object]`}return!1},w=(...e)=>e.reduce((t,o)=>{if(p(o))throw new TypeError(`Arguments must be ${f}s, not arrays.`);return m(o).forEach(n=>{["__proto__","constructor",P].includes(n)||(p(t[n])&&p(o[n])?t[n]=Array.from(new Set(t[n].concat(o[n]))):R(t[n])&&R(o[n])?t[n]=w(t[n],o[n]):t[n]=o[n])}),t},{});function D(e,t,o){let n=t?o(t):"",c=e.includes("?")?"&":"?",s=n?`${e}${c}${n}`:e,[u,r]=s.split("?");if(!r)return s;let l=r.split("&").sort().join("&");return`${u}?${l}`}function oe(e){return new Promise(t=>{setTimeout(()=>{t(1)},e)})}function C(e,t=!0,o=d,n){if(e===g||e===d)return"";let c=[],s=t?encodeURIComponent:i=>i,u=p(e),{arrayFormat:r,allowDots:l,serializeDate:T}=n||{},L=i=>{if(l&&!u)return`.${i}`;if(u){if(r==="brackets")return"[]";if(r==="repeat")return""}return`[${i}]`};for(let i in e)if(x.hasOwnProperty.call(e,i)){let a=e[i];if(a!==g){let v=o?`${o}${L(i)}`:s(i);if(!isNaN(a)&&a instanceof Date&&(a=T?T(a):a.toISOString()),typeof a===f){let A=C(a,t,v,n);A!==""&&c.push(A)}else c.push(`${s(v)}=${s(a)}`)}}return c.join("&")}function $(e){return p(e)?e.map($):(e&&typeof e===f&&m(e).forEach(t=>{let o=e[t];o===g?delete e[t]:$(o)}),e)}function ie(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function ae(e,t){return e?t?(e.endsWith("/")?e:e+"/")+(t[0]==="/"?t.slice(1):t):e:t||""}var I="XiorError",X="XiorTimeoutError",O=class extends Error{constructor(t,o,n){super(t),this.name=I,this.request=o,this.config=o,this.response=n}},h=class extends O{constructor(t,o,n){super(t,o,n),this.name=X}};function ce(e){return(e==null?void 0:e.name)===I||(e==null?void 0:e.name)===X}export{f as a,S as b,q as c,U as d,k as e,F as f,V as g,y as h,g as i,d as j,m as k,z as l,j as m,H as n,M as o,N as p,_ as q,G as r,W as s,Q as t,w as u,D as v,oe as w,C as x,$ as y,ie as z,ae as A,O as B,h as C,ce as D};