Socket
Socket
Sign inDemoInstall

xior

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xior - npm Package Compare versions

Comparing version 0.3.13 to 0.4.0

2

dist/index.esm.js

@@ -1,1 +0,1 @@

import{merge as e,encodeParams as t,XiorTimeoutError as r,anySignal as n,isAbsoluteURL as i,joinPath as s,XiorError as o}from"xior/utils";export*from"xior/utils";function a(e,t,r,n,i,s,o){try{var a=e[s](o),u=a.value}catch(e){r(e);return}a.done?t(u):Promise.resolve(u).then(n,i)}function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}let l="application/",c=`${l}x-www-form-urlencoded`,h=`${l}json`;function f(){var r;return r=function*(r){let n=r.paramsSerializer||t,i=!1!==r.encodeURI,s=r.method?r.method.toUpperCase():"GET",o=r.url||"",a=o,l=r.data,f=l,d=(null==r?void 0:r.headers)||{},p=r.params||{},y=function(e="GET"){return["HEAD","GET","OPTIONS"].includes(e)}(s);if(l&&!(l instanceof FormData)){let t="";if(null==r?void 0:r.headers){let e=Object.keys(r.headers).find(e=>"content-type"===e.toLowerCase());e&&(t=r.headers[e],r.headers["Content-Type"]=t,"Content-Type"!==e&&delete r.headers[e])}t||(t=y?c:h,d["Content-Type"]=t),y&&r.params&&(p=e({},l||{},p)),t===h?f=JSON.stringify(l):!y&&t===c&&l&&"object"==typeof l&&(f=n(l))}if(Object.keys(p).length>0){let e=n(p,i);o+=o.includes("?")?`&${e}`:`?${e}`}return u({},r,{data:l,_data:f,url:a,_url:o,method:s,headers:d,isGet:y})},(f=function(){var e=this,t=arguments;return new Promise(function(n,i){var s=r.apply(e,t);function o(e){a(s,n,i,o,u,"next",e)}function u(e){a(s,n,i,o,u,"throw",e)}o(void 0)})}).apply(this,arguments)}function d(e,t,r,n,i,s,o){try{var a=e[s](o),u=a.value}catch(e){r(e);return}a.done?t(u):Promise.resolve(u).then(n,i)}function p(e){return function(){var t=this,r=arguments;return new Promise(function(n,i){var s=e.apply(t,r);function o(e){d(s,n,i,o,a,"next",e)}function a(e){d(s,n,i,o,a,"throw",e)}o(void 0)})}}function y(){return(y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}let v="undefined"!=typeof AbortController;class E{static create(e){return new E(e)}get interceptors(){return{request:{use:(e,t)=>(this.REQI.push(e),e),eject:e=>{this.REQI=this.REQI.filter(t=>t!==e)},clear:()=>{this.REQI=[]}},response:{use:(e,t)=>(this.RESI.push({fn:e,onRejected:t}),e),eject:e=>{this.RESI=this.RESI.filter(t=>t.fn!==e)},clear:()=>{this.RESI=[]}}}}get plugins(){return{use:e=>(this.P.push(e),e),eject:e=>{this.P=this.P.filter(t=>t!==e)},clear:()=>{this.P=[]}}}request(r){var n=this;return p(function*(){let i=e({},n.config||{},n.defaults||{},"string"==typeof r?{url:r}:r||{},{headers:{},params:{}});for(let e of(i.paramsSerializer||(i.paramsSerializer=t),n.REQI))i=yield e(i);let s=n.fetch.bind(n);return n.P.forEach(e=>{s=e(s,n)}),s(i)})()}fetch(e){var t=this;return p(function*(){var a,u;let l,c,h;let d=yield function(e){return f.apply(this,arguments)}(e),{url:p,method:E,headers:m,timeout:R,signal:O,data:g,_data:P,_url:I,isGet:S}=d,j=function(e,t){if(null==e)return{};var r,n,i={},s=Object.keys(e);for(n=0;n<s.length;n++)t.indexOf(r=s[n])>=0||(i[r]=e[r]);return i}(d,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);e._url=I;let w=[];if(R&&v){let t=new AbortController;h=setTimeout(()=>{t.abort(new r(`timeout of ${R}ms exceeded`,e))},R),w.push(t.signal)}O&&w.push(O),l=w[0],w.length>1&&(l=n(w,()=>{clearTimeout(h)}));let T=I||p||"";e.baseURL&&!i(T)&&(T=s(e.baseURL,T));try{c=yield fetch(T,y({body:S?void 0:P},j,{signal:l,method:E,headers:m}))}catch(e){for(let r of t.RESI)r.onRejected&&(yield r.onRejected(e));throw e}finally{h&&clearTimeout(h),null==l||null==(a=l.clear)||a.call(l)}let b={response:c,config:e,status:c.status,statusText:c.statusText,headers:c.headers};if(!c.ok){let r;try{(r=yield c.text())&&(r=JSON.parse(r))}catch(e){}let n=new o(c.status?`Request failed with status code ${c.status}`:"Network error",e,y({data:r},b));for(let e of t.RESI)if(e.onRejected){let t=yield e.onRejected(n);if(null==t?void 0:null==(u=t.response)?void 0:u.ok)return t}throw n}if("HEAD"===E)return y({data:void 0,request:e},b);let{responseType:x}=e;if(!x||["json","text"].includes(x)){let r;try{(r=yield c.text())&&"text"!==x&&(r=JSON.parse(r))}catch(e){}let n={data:r,config:e,request:e,response:c};for(let e of t.RESI)n=yield e.fn(n);return y({data:n.data,request:e},b)}return y({data:void 0,request:e},b)})()}cG(e){return(t,r)=>this.request(r?y({},r,{method:e,url:t}):{method:e,url:t})}cP(e){return(t,r,n)=>this.request(n?y({},n,{method:e,url:t,data:r}):{method:e,url:t,data:r})}get(e,t){return this.cG("GET")(e,t)}head(e,t){return this.cG("HEAD")(e,t)}post(e,t,r){return this.cP("POST")(e,t,r)}put(e,t,r){return this.cP("PUT")(e,t,r)}patch(e,t,r){return this.cP("PATCH")(e,t,r)}delete(e,t){return this.cG("DELETE")(e,t)}options(e,t){return this.cG("OPTIONS")(e,t)}constructor(e){this.REQI=[],this.RESI=[],this.P=[],this.config=e,this.defaults={params:{},headers:{}}}}E.VERSION="0.3.13";let m=Object.assign(E.create(),{create:E.create,VERSION:E.VERSION});export{m as default,E as xior};
import{merge as t,encodeParams as e,XiorTimeoutError as r,anySignal as n,isAbsoluteURL as i,joinPath as s,XiorError as o}from"xior/utils";export*from"xior/utils";function a(t,e,r,n,i,s,o){try{var a=t[s](o),u=a.value}catch(t){r(t);return}a.done?e(u):Promise.resolve(u).then(n,i)}function u(){return(u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}let l="application/",c=`${l}x-www-form-urlencoded`,h=`${l}json`;function f(){var r;return r=function*(r){let n=r.paramsSerializer||e,i=!1!==r.encodeURI,s=r.method?r.method.toUpperCase():"GET",o=r.url||"",a=o,l=r.data,f=l,p=(null==r?void 0:r.headers)||{},d=r.params||{},y=function(t="GET"){return["HEAD","GET","OPTIONS"].includes(t)}(s);if(l&&!(l instanceof FormData)){let e="";if(null==r?void 0:r.headers){let t=Object.keys(r.headers).find(t=>"content-type"===t.toLowerCase());t&&(e=r.headers[t],r.headers["Content-Type"]=e,"Content-Type"!==t&&delete r.headers[t])}e||(e=y?c:h,p["Content-Type"]=e),y&&r.params&&(d=t({},l||{},d)),e===h?f=JSON.stringify(l):!y&&e===c&&l&&"object"==typeof l&&(f=n(l))}if(Object.keys(d).length>0){let t=n(d,i);o+=o.includes("?")?`&${t}`:`?${t}`}return u({},r,{_data:f,_url:o,data:l,url:a,method:s,headers:p,isGet:y})},(f=function(){var t=this,e=arguments;return new Promise(function(n,i){var s=r.apply(t,e);function o(t){a(s,n,i,o,u,"next",t)}function u(t){a(s,n,i,o,u,"throw",t)}o(void 0)})}).apply(this,arguments)}function p(t,e,r,n,i,s,o){try{var a=t[s](o),u=a.value}catch(t){r(t);return}a.done?e(u):Promise.resolve(u).then(n,i)}function d(t){return function(){var e=this,r=arguments;return new Promise(function(n,i){var s=t.apply(e,r);function o(t){p(s,n,i,o,a,"next",t)}function a(t){p(s,n,i,o,a,"throw",t)}o(void 0)})}}function y(){return(y=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}let m="undefined"!=typeof AbortController,v=void 0;function E(){return(E=d(function*(t,e){let r;if(!e||!t.ok||["text","json"].includes(e)){if((r=yield t.text())&&"text"!==e)try{r=JSON.parse(r)}catch(t){}}else"blob"===e?r=yield t.blob():"arraybuffer"===e&&(r=yield t.arrayBuffer());return r})).apply(this,arguments)}class b{static create(t){return new b(t)}get interceptors(){return{request:{use:(t,e,r)=>(this.REQI.push(t),t),eject:t=>{this.REQI=this.REQI.filter(e=>e!==t)},clear:()=>{this.REQI=[]}},response:{use:(t,e)=>(this.RESI.push({fn:t,onRejected:e}),t),eject:t=>{this.RESI=this.RESI.filter(e=>e.fn!==t)},clear:()=>{this.RESI=[]}}}}get plugins(){return{use:t=>(this.P.push(t),t),eject:t=>{this.P=this.P.filter(e=>e!==t)},clear:()=>{this.P=[]}}}request(r){var n=this;return d(function*(){let i=t({},n.config||{},n.defaults||{},"string"==typeof r?{url:r}:r||{},{headers:{},params:{}});for(let t of(i.paramsSerializer||(i.paramsSerializer=e),n.REQI))i=yield t(i);let s=n.fetch.bind(n);return n.P.forEach(t=>{s=t(s,n)}),s(i)})()}fetch(t){var e=this;return d(function*(){let a;let u=yield function(t){return f.apply(this,arguments)}(t),{url:l,method:c,headers:h,timeout:p,signal:b,data:O,_data:P,_url:g,isGet:R}=u,I=function(t,e){if(null==t)return{};var r,n,i={},s=Object.keys(t);for(n=0;n<s.length;n++)e.indexOf(r=s[n])>=0||(i[r]=t[r]);return i}(u,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);t._url=g;let T=[],j=v;if(p&&m){let e=new AbortController;j=setTimeout(()=>{e.abort(new r(`timeout of ${p}ms exceeded`,t))},p),T.push(e.signal)}b&&T.push(b),a=T[0],T.length>1&&(a=n(T,()=>{clearTimeout(j)}));let S=g||l||"";t.baseURL&&!i(S)&&(S=s(t.baseURL,S));let w=0,x=fetch(S,y({body:R?v:P},I,{signal:a,method:c,headers:h})).then(d(function*(e){let{responseType:r}=t,n={data:yield function(t,e){return E.apply(this,arguments)}(e,r),response:e,config:t,request:t,status:e.status,statusText:e.statusText,headers:e.headers};return e.ok?n:Promise.reject(new o(e.status?`Request failed with status code ${e.status}`:"Network error",t,n))})).finally(()=>{var t;j&&clearTimeout(j),null==a||null==(t=a.clear)||t.call(a)}),G=[];for(e.RESI.forEach(function(t){G.push(t.fn,t.onRejected)});G.length>w;)x=x.then(G[w++],G[w++]);return x})()}cG(t){return(e,r)=>this.request(r?y({},r,{method:t,url:e}):{method:t,url:e})}cP(t){return(e,r,n)=>this.request(n?y({},n,{method:t,url:e,data:r}):{method:t,url:e,data:r})}get(t,e){return this.cG("GET")(t,e)}head(t,e){return this.cG("HEAD")(t,e)}post(t,e,r){return this.cP("POST")(t,e,r)}put(t,e,r){return this.cP("PUT")(t,e,r)}patch(t,e,r){return this.cP("PATCH")(t,e,r)}delete(t,e){return this.cG("DELETE")(t,e)}options(t,e){return this.cG("OPTIONS")(t,e)}constructor(t){this.REQI=[],this.RESI=[],this.P=[],this.config=t,this.defaults={params:{},headers:{}}}}b.VERSION="0.4.0";let O=Object.assign(b.create(),{create:b.create,VERSION:b.VERSION});export{O as default,b as xior};

@@ -45,2 +45,17 @@ import { XiorError } from 'xior/utils';

type XiorPlugin = (adapter: (request: XiorRequestConfig) => Promise<XiorResponse>, instance?: XiorInstance) => (request: XiorRequestConfig) => Promise<XiorResponse<any>>;
interface XiorInterceptorOptions {
/** @deprecated useless here */
synchronous?: boolean;
/** @deprecated useless here */
runWhen?: (config: XiorInterceptorRequestConfig) => boolean;
}
interface XiorResponseInterceptorConfig<T = any> {
data: T;
config: XiorInterceptorRequestConfig<T>;
request: XiorInterceptorRequestConfig<T>;
response: Response;
status: number;
statusText: string;
headers: Headers;
}

@@ -58,23 +73,9 @@ type XiorInstance = xior;

RESI: {
fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
onRejected?: (error: XiorError) => any;
fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
/** error: XiorError | Error | TypeError */
onRejected?: null | ((error: XiorError) => any);
}[];
get interceptors(): {
request: {
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | undefined) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void;

@@ -84,49 +85,4 @@ clear: () => void;

response: {
use: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}, onRejected?: ((error: XiorError) => any) | undefined) => (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
eject: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => void;
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void;
clear: () => void;

@@ -171,2 +127,2 @@ };

export { type XiorInstance, type XiorInterceptorRequestConfig, type XiorPlugin, type XiorRequestConfig, type XiorResponse, xiorObj as default, xior };
export { type XiorInstance, type XiorInterceptorOptions, type XiorInterceptorRequestConfig, type XiorPlugin, type XiorRequestConfig, type XiorResponse, type XiorResponseInterceptorConfig, xiorObj as default, xior };

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xior=t():e.xior=t()}(this,(()=>{return e={509:function(e,t,r){"use strict";var o=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var n=Object.getOwnPropertyDescriptor(t,r);n&&!("get"in n?!t.__esModule:n.writable||n.configurable)||(n={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,n)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),n=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||o(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0});const s=r(895);n(r(895),t),n(r(340),t),n(r(121),t);const i=Object.assign(s.xior.create(),{create:s.xior.create,VERSION:s.xior.VERSION});t.default=i},393:function(e,t,r){"use strict";var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.likeGET=void 0;const n=r(121),s="application/",i=`${s}x-www-form-urlencoded`,a=`${s}json`;function c(e="GET"){return["HEAD","GET","OPTIONS"].includes(e)}t.likeGET=c,t.default=function(e){return o(this,void 0,void 0,(function*(){const t=e.paramsSerializer||n.encodeParams,r=!1!==e.encodeURI,o=e.method?e.method.toUpperCase():"GET";let s=e.url||"";const u=s,l=e.data;let d=l;const f=(null==e?void 0:e.headers)||{};let h=e.params||{};const p=c(o);if(l&&!(l instanceof FormData)){let r="";if(null==e?void 0:e.headers){const t=Object.keys(e.headers).find((e=>"content-type"===e.toLowerCase()));t&&(r=e.headers[t],e.headers["Content-Type"]=r,"Content-Type"!==t&&delete e.headers[t])}r||(r=p?i:a,f["Content-Type"]=r),p&&e.params&&(h=(0,n.merge)({},l||{},h)),r===a?d=JSON.stringify(l):!p&&r===i&&l&&"object"==typeof l&&(d=t(l))}if(Object.keys(h).length>0){const e=t(h,r);s+=s.includes("?")?`&${e}`:`?${e}`}return Object.assign(Object.assign({},e),{data:l,_data:d,url:u,_url:s,method:o,headers:f,isGet:p})}))}},340:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},895:function(e,t,r){"use strict";var o=this&&this.__awaiter||function(e,t,r,o){return new(r||(r=Promise))((function(n,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))},n=this&&this.__rest||function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(r[o[n]]=e[o[n]])}return r},s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.xior=void 0;const i=r(121),a=s(r(393)),c="undefined"!=typeof AbortController;class u{static create(e){return new u(e)}constructor(e){this.REQI=[],this.RESI=[],this.P=[],this.config=e,this.defaults={params:{},headers:{}}}get interceptors(){return{request:{use:(e,t)=>(this.REQI.push(e),e),eject:e=>{this.REQI=this.REQI.filter((t=>t!==e))},clear:()=>{this.REQI=[]}},response:{use:(e,t)=>(this.RESI.push({fn:e,onRejected:t}),e),eject:e=>{this.RESI=this.RESI.filter((t=>t.fn!==e))},clear:()=>{this.RESI=[]}}}}get plugins(){return{use:e=>(this.P.push(e),e),eject:e=>{this.P=this.P.filter((t=>t!==e))},clear:()=>{this.P=[]}}}request(e){return o(this,void 0,void 0,(function*(){let t=(0,i.merge)({},this.config||{},this.defaults||{},"string"==typeof e?{url:e}:e||{},{headers:{},params:{}});t.paramsSerializer||(t.paramsSerializer=i.encodeParams);for(const e of this.REQI)t=yield e(t);let r=this.fetch.bind(this);return this.P.forEach((e=>{r=e(r,this)})),r(t)}))}fetch(e){var t,r;return o(this,void 0,void 0,(function*(){const o=yield(0,a.default)(e),{url:s,method:u,headers:l,timeout:d,signal:f,data:h,_data:p,_url:y,isGet:m}=o,b=n(o,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);let g;e._url=y;const O=[];let j;if(d&&c){const t=new AbortController;j=setTimeout((()=>{t.abort(new i.XiorTimeoutError(`timeout of ${d}ms exceeded`,e))}),d),O.push(t.signal)}f&&O.push(f),g=O[0],O.length>1&&(g=(0,i.anySignal)(O,(()=>{clearTimeout(j)})));let v,E=y||s||"";e.baseURL&&!(0,i.isAbsoluteURL)(E)&&(E=(0,i.joinPath)(e.baseURL,E));try{v=yield fetch(E,Object.assign(Object.assign({body:m?void 0:p},b),{signal:g,method:u,headers:l}))}catch(e){for(const t of this.RESI)t.onRejected&&(yield t.onRejected(e));throw e}finally{j&&clearTimeout(j),null===(t=null==g?void 0:g.clear)||void 0===t||t.call(g)}const P={response:v,config:e,status:v.status,statusText:v.statusText,headers:v.headers};if(!v.ok){let t;try{t=yield v.text(),t&&(t=JSON.parse(t))}catch(e){}const o=new i.XiorError(v.status?`Request failed with status code ${v.status}`:"Network error",e,Object.assign({data:t},P));for(const e of this.RESI)if(e.onRejected){const t=yield e.onRejected(o);if(null===(r=null==t?void 0:t.response)||void 0===r?void 0:r.ok)return t}throw o}if("HEAD"===u)return Object.assign({data:void 0,request:e},P);const{responseType:_}=e;if(!_||["json","text"].includes(_)){let t;try{t=yield v.text(),t&&"text"!==_&&(t=JSON.parse(t))}catch(e){}let r={data:t,config:e,request:e,response:v};for(const e of this.RESI)r=yield e.fn(r);return Object.assign({data:r.data,request:e},P)}return Object.assign({data:void 0,request:e},P)}))}cG(e){return(t,r)=>this.request(r?Object.assign(Object.assign({},r),{method:e,url:t}):{method:e,url:t})}cP(e){return(t,r,o)=>this.request(o?Object.assign(Object.assign({},o),{method:e,url:t,data:r}):{method:e,url:t,data:r})}get(e,t){return this.cG("GET")(e,t)}head(e,t){return this.cG("HEAD")(e,t)}post(e,t,r){return this.cP("POST")(e,t,r)}put(e,t,r){return this.cP("PUT")(e,t,r)}patch(e,t,r){return this.cP("PATCH")(e,t,r)}delete(e,t){return this.cG("DELETE")(e,t)}options(e,t){return this.cG("OPTIONS")(e,t)}}t.xior=u,u.VERSION="0.3.13"},602:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const r=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1};t.merge=(...e)=>e.reduce(((e,o)=>{if(Array.isArray(o))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(o).forEach((n=>{["__proto__","constructor","prototype"].includes(n)||(Array.isArray(e[n])&&Array.isArray(o[n])?e[n]=t.merge.options.mergeArrays?t.merge.options.uniqueArrayItems?Array.from(new Set(e[n].concat(o[n]))):[...e[n],...o[n]]:o[n]:r(e[n])&&r(o[n])?e[n]=(0,t.merge)(e[n],o[n]):e[n]=void 0===o[n]?t.merge.options.allowUndefinedOverrides?o[n]:e[n]:o[n])})),e}),{});const o={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};t.merge.options=o,t.merge.withOptions=(e,...r)=>{t.merge.options=Object.assign(Object.assign({},o),e);const n=(0,t.merge)(...r);return t.merge.options=o,n}},121:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var o=r(602);class n extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}Object.defineProperty(t,"merge",{enumerable:!0,get:function(){return o.merge}}),t.XiorError=n,t.XiorTimeoutError=class extends n{constructor(e,t,r){super(e),this.name="XiorTimeoutError",this.request=t,this.config=t,this.response=r}},t.anySignal=function(e,t){let r=new globalThis.AbortController;function o(e){r.abort(e),s()}let n=[];for(let t of e){if(!0===(null==t?void 0:t.aborted)){o(t.reason);break}if(null!=(null==t?void 0:t.addEventListener)){let e=()=>{o(t.reason)};n.push((()=>{null!=(null==t?void 0:t.removeEventListener)&&t.removeEventListener("abort",e)})),t.addEventListener("abort",e)}}function s(){n.forEach((e=>{e()})),null==t||t()}let i=r.signal;return i.clear=s,i},t.buildSortedURL=function(e,t,r){let o=t?r(t):"";o&&(o=e+(e.includes("?")?"&":"?")+o);let[n,s]=o.split("?");return s?`${n}?${s.split("&").sort().join("&")}`:o||e},t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))},t.encodeParams=function e(t,r=!0,o=null){if(null==t)return"";let n=[],s=r?encodeURIComponent:e=>e;for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let a=t[i],c=o?`${o}[${s(i)}]`:s(i);if("object"==typeof a){let t=e(a,r,c);""!==t&&n.push(t)}else Array.isArray(a)?a.forEach(((e,t)=>{let r=`${c}[${t}]`;n.push(`${s(r)}=${s(e)}`)})):n.push(`${s(c)}=${s(a)}`)}return n.join("&")},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},t.joinPath=function(e,t){return t?(e.endsWith("/")?e:e+"/")+("/"===t[0]?t.slice(1):t):e}}},t={},function r(o){var n=t[o];if(void 0!==n)return n.exports;var s=t[o]={exports:{}};return e[o].call(s.exports,s,s.exports,r),s.exports}(509).default;var e,t}));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.xior=t():e.xior=t()}(this,(()=>{return e={509:function(e,t,r){"use strict";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});const i=r(895);o(r(895),t),o(r(340),t),o(r(121),t);const s=Object.assign(i.xior.create(),{create:i.xior.create,VERSION:i.xior.VERSION});t.default=s},393:function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{u(n.next(e))}catch(e){i(e)}}function a(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.likeGET=void 0;const o=r(121),i="application/",s=`${i}x-www-form-urlencoded`,a=`${i}json`;function u(e="GET"){return["HEAD","GET","OPTIONS"].includes(e)}t.likeGET=u,t.default=function(e){return n(this,void 0,void 0,(function*(){const t=e.paramsSerializer||o.encodeParams,r=!1!==e.encodeURI,n=e.method?e.method.toUpperCase():"GET";let i=e.url||"";const c=i,l=e.data;let d=l;const f=(null==e?void 0:e.headers)||{};let h=e.params||{};const p=u(n);if(l&&!(l instanceof FormData)){let r="";if(null==e?void 0:e.headers){const t=Object.keys(e.headers).find((e=>"content-type"===e.toLowerCase()));t&&(r=e.headers[t],e.headers["Content-Type"]=r,"Content-Type"!==t&&delete e.headers[t])}r||(r=p?s:a,f["Content-Type"]=r),p&&e.params&&(h=(0,o.merge)({},l||{},h)),r===a?d=JSON.stringify(l):!p&&r===s&&l&&"object"==typeof l&&(d=t(l))}if(Object.keys(h).length>0){const e=t(h,r);i+=i.includes("?")?`&${e}`:`?${e}`}return Object.assign(Object.assign({},e),{_data:d,_url:i,data:l,url:c,method:n,headers:f,isGet:p})}))}},340:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0})},895:function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{u(n.next(e))}catch(e){i(e)}}function a(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))},o=this&&this.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r},i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.xior=void 0;const s=r(121),a=i(r(393)),u="undefined"!=typeof AbortController,c=void 0;class l{static create(e){return new l(e)}constructor(e){this.REQI=[],this.RESI=[],this.P=[],this.config=e,this.defaults={params:{},headers:{}}}get interceptors(){return{request:{use:(e,t,r)=>(this.REQI.push(e),e),eject:e=>{this.REQI=this.REQI.filter((t=>t!==e))},clear:()=>{this.REQI=[]}},response:{use:(e,t)=>(this.RESI.push({fn:e,onRejected:t}),e),eject:e=>{this.RESI=this.RESI.filter((t=>t.fn!==e))},clear:()=>{this.RESI=[]}}}}get plugins(){return{use:e=>(this.P.push(e),e),eject:e=>{this.P=this.P.filter((t=>t!==e))},clear:()=>{this.P=[]}}}request(e){return n(this,void 0,void 0,(function*(){let t=(0,s.merge)({},this.config||{},this.defaults||{},"string"==typeof e?{url:e}:e||{},{headers:{},params:{}});t.paramsSerializer||(t.paramsSerializer=s.encodeParams);for(const e of this.REQI)t=yield e(t);let r=this.fetch.bind(this);return this.P.forEach((e=>{r=e(r,this)})),r(t)}))}fetch(e){return n(this,void 0,void 0,(function*(){const t=yield(0,a.default)(e),{url:r,method:i,headers:l,timeout:d,signal:f,data:h,_data:p,_url:y,isGet:m}=t,b=o(t,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);let g;e._url=y;const v=[];let O=c;if(d&&u){const t=new AbortController;O=setTimeout((()=>{t.abort(new s.XiorTimeoutError(`timeout of ${d}ms exceeded`,e))}),d),v.push(t.signal)}f&&v.push(f),g=v[0],v.length>1&&(g=(0,s.anySignal)(v,(()=>{clearTimeout(O)})));let j=y||r||"";e.baseURL&&!(0,s.isAbsoluteURL)(j)&&(j=(0,s.joinPath)(e.baseURL,j));let E=0,P=fetch(j,Object.assign(Object.assign({body:m?c:p},b),{signal:g,method:i,headers:l})).then((t=>n(this,void 0,void 0,(function*(){const{responseType:r}=e,o=yield function(e,t){return n(this,void 0,void 0,(function*(){let r;if(t&&e.ok&&!["text","json"].includes(t))"blob"===t?r=yield e.blob():"arraybuffer"===t&&(r=yield e.arrayBuffer());else if(r=yield e.text(),r&&"text"!==t)try{r=JSON.parse(r)}catch(e){}return r}))}(t,r),i={data:o,response:t,config:e,request:e,status:t.status,statusText:t.statusText,headers:t.headers};if(!t.ok){const r=new s.XiorError(t.status?`Request failed with status code ${t.status}`:"Network error",e,i);return Promise.reject(r)}return i})))).finally((()=>{var e;O&&clearTimeout(O),null===(e=null==g?void 0:g.clear)||void 0===e||e.call(g)}));const _=[];for(this.RESI.forEach((function(e){_.push(e.fn,e.onRejected)}));_.length>E;)P=P.then(_[E++],_[E++]);return P}))}cG(e){return(t,r)=>this.request(r?Object.assign(Object.assign({},r),{method:e,url:t}):{method:e,url:t})}cP(e){return(t,r,n)=>this.request(n?Object.assign(Object.assign({},n),{method:e,url:t,data:r}):{method:e,url:t,data:r})}get(e,t){return this.cG("GET")(e,t)}head(e,t){return this.cG("HEAD")(e,t)}post(e,t,r){return this.cP("POST")(e,t,r)}put(e,t,r){return this.cP("PUT")(e,t,r)}patch(e,t,r){return this.cP("PATCH")(e,t,r)}delete(e,t){return this.cG("DELETE")(e,t)}options(e,t){return this.cG("OPTIONS")(e,t)}}t.xior=l,l.VERSION="0.4.0"},602:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.merge=void 0;const r=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}return"[object Object]"===Object.prototype.toString.call(e)}return!1};t.merge=(...e)=>e.reduce(((e,n)=>{if(Array.isArray(n))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(n).forEach((o=>{["__proto__","constructor","prototype"].includes(o)||(Array.isArray(e[o])&&Array.isArray(n[o])?e[o]=t.merge.options.mergeArrays?t.merge.options.uniqueArrayItems?Array.from(new Set(e[o].concat(n[o]))):[...e[o],...n[o]]:n[o]:r(e[o])&&r(n[o])?e[o]=(0,t.merge)(e[o],n[o]):e[o]=void 0===n[o]?t.merge.options.allowUndefinedOverrides?n[o]:e[o]:n[o])})),e}),{});const n={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};t.merge.options=n,t.merge.withOptions=(e,...r)=>{t.merge.options=Object.assign(Object.assign({},n),e);const o=(0,t.merge)(...r);return t.merge.options=n,o}},121:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=r(602);class o extends Error{constructor(e,t,r){super(e),this.name="XiorError",this.request=t,this.config=t,this.response=r}}Object.defineProperty(t,"merge",{enumerable:!0,get:function(){return n.merge}}),t.XiorError=o,t.XiorTimeoutError=class extends o{constructor(e,t,r){super(e),this.name="XiorTimeoutError",this.request=t,this.config=t,this.response=r}},t.anySignal=function(e,t){let r=new globalThis.AbortController;function n(e){r.abort(e),i()}let o=[];for(let t of e){if(!0===(null==t?void 0:t.aborted)){n(t.reason);break}if(null!=(null==t?void 0:t.addEventListener)){let e=()=>{n(t.reason)};o.push((()=>{null!=(null==t?void 0:t.removeEventListener)&&t.removeEventListener("abort",e)})),t.addEventListener("abort",e)}}function i(){o.forEach((e=>{e()})),null==t||t()}let s=r.signal;return s.clear=i,s},t.buildSortedURL=function(e,t,r){let n=t?r(t):"";n&&(n=e+(e.includes("?")?"&":"?")+n);let[o,i]=n.split("?");return i?`${o}?${i.split("&").sort().join("&")}`:n||e},t.delay=function(e){return new Promise((t=>{setTimeout((()=>{t("ok")}),e)}))},t.encodeParams=function e(t,r=!0,n=null){if(null==t)return"";let o=[],i=r?encodeURIComponent:e=>e;for(let s in t)if(Object.prototype.hasOwnProperty.call(t,s)){let a=t[s],u=n?`${n}[${i(s)}]`:i(s);if("object"==typeof a){let t=e(a,r,u);""!==t&&o.push(t)}else Array.isArray(a)?a.forEach(((e,t)=>{let r=`${u}[${t}]`;o.push(`${i(r)}=${i(e)}`)})):o.push(`${i(u)}=${i(a)}`)}return o.join("&")},t.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},t.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},t.joinPath=function(e,t){return t?(e.endsWith("/")?e:e+"/")+("/"===t[0]?t.slice(1):t):e}}},t={},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}(509).default;var e,t}));

@@ -64,4 +64,4 @@ [Go back](./README.md)

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/mock.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/plugins/mock.umd.js"></script>

@@ -83,4 +83,4 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.13/plugins/mock.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/plugins/mock.umd.js"></script>

@@ -87,0 +87,0 @@ <!-- Usage -->

{
"name": "xior",
"version": "0.3.13",
"version": "0.4.0",
"description": "A lite request lib based on fetch with plugin support and similar API to axios.",

@@ -5,0 +5,0 @@ "repository": "suhaotian/xior",

@@ -23,23 +23,9 @@ import { XiorError } from 'xior/utils';

RESI: {
fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
onRejected?: (error: XiorError) => any;
fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
/** error: XiorError | Error | TypeError */
onRejected?: null | ((error: XiorError) => any);
}[];
get interceptors(): {
request: {
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | undefined) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void;

@@ -49,49 +35,4 @@ clear: () => void;

response: {
use: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}, onRejected?: ((error: XiorError) => any) | undefined) => (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
eject: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => void;
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void;
clear: () => void;

@@ -172,2 +113,17 @@ };

type XiorPlugin = (adapter: (request: XiorRequestConfig) => Promise<XiorResponse>, instance?: XiorInstance) => (request: XiorRequestConfig) => Promise<XiorResponse<any>>;
interface XiorInterceptorOptions {
/** @deprecated useless here */
synchronous?: boolean;
/** @deprecated useless here */
runWhen?: (config: XiorInterceptorRequestConfig) => boolean;
}
interface XiorResponseInterceptorConfig<T = any> {
data: T;
config: XiorInterceptorRequestConfig<T>;
request: XiorInterceptorRequestConfig<T>;
response: Response;
status: number;
statusText: string;
headers: Headers;
}

@@ -174,0 +130,0 @@ type XiorPromise = Promise<XiorResponse>;

@@ -14,23 +14,9 @@ import { XiorError } from 'xior/utils';

RESI: {
fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
onRejected?: (error: XiorError) => any;
fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
/** error: XiorError | Error | TypeError */
onRejected?: null | ((error: XiorError) => any);
}[];
get interceptors(): {
request: {
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | undefined) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void;

@@ -40,49 +26,4 @@ clear: () => void;

response: {
use: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}, onRejected?: ((error: XiorError) => any) | undefined) => (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
eject: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => void;
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void;
clear: () => void;

@@ -163,2 +104,17 @@ };

type XiorPlugin = (adapter: (request: XiorRequestConfig) => Promise<XiorResponse>, instance?: XiorInstance) => (request: XiorRequestConfig) => Promise<XiorResponse<any>>;
interface XiorInterceptorOptions {
/** @deprecated useless here */
synchronous?: boolean;
/** @deprecated useless here */
runWhen?: (config: XiorInterceptorRequestConfig) => boolean;
}
interface XiorResponseInterceptorConfig<T = any> {
data: T;
config: XiorInterceptorRequestConfig<T>;
request: XiorInterceptorRequestConfig<T>;
response: Response;
status: number;
statusText: string;
headers: Headers;
}

@@ -165,0 +121,0 @@ type XiorDedupeOptions = {

@@ -23,23 +23,9 @@ import { XiorError } from 'xior/utils';

RESI: {
fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
onRejected?: (error: XiorError) => any;
fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
/** error: XiorError | Error | TypeError */
onRejected?: null | ((error: XiorError) => any);
}[];
get interceptors(): {
request: {
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | undefined) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void;

@@ -49,49 +35,4 @@ clear: () => void;

response: {
use: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}, onRejected?: ((error: XiorError) => any) | undefined) => (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
eject: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => void;
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void;
clear: () => void;

@@ -172,2 +113,17 @@ };

type XiorPlugin = (adapter: (request: XiorRequestConfig) => Promise<XiorResponse>, instance?: XiorInstance) => (request: XiorRequestConfig) => Promise<XiorResponse<any>>;
interface XiorInterceptorOptions {
/** @deprecated useless here */
synchronous?: boolean;
/** @deprecated useless here */
runWhen?: (config: XiorInterceptorRequestConfig) => boolean;
}
interface XiorResponseInterceptorConfig<T = any> {
data: T;
config: XiorInterceptorRequestConfig<T>;
request: XiorInterceptorRequestConfig<T>;
response: Response;
status: number;
statusText: string;
headers: Headers;
}

@@ -174,0 +130,0 @@ type XiorErrorCacheOptions = {

@@ -14,23 +14,9 @@ import { XiorError } from 'xior/utils';

RESI: {
fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
onRejected?: (error: XiorError) => any;
fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
/** error: XiorError | Error | TypeError */
onRejected?: null | ((error: XiorError) => any);
}[];
get interceptors(): {
request: {
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | undefined) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void;

@@ -40,49 +26,4 @@ clear: () => void;

response: {
use: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}, onRejected?: ((error: XiorError) => any) | undefined) => (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
eject: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => void;
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void;
clear: () => void;

@@ -163,2 +104,17 @@ };

type XiorPlugin = (adapter: (request: XiorRequestConfig) => Promise<XiorResponse>, instance?: XiorInstance) => (request: XiorRequestConfig) => Promise<XiorResponse<any>>;
interface XiorInterceptorOptions {
/** @deprecated useless here */
synchronous?: boolean;
/** @deprecated useless here */
runWhen?: (config: XiorInterceptorRequestConfig) => boolean;
}
interface XiorResponseInterceptorConfig<T = any> {
data: T;
config: XiorInterceptorRequestConfig<T>;
request: XiorInterceptorRequestConfig<T>;
response: Response;
status: number;
statusText: string;
headers: Headers;
}

@@ -165,0 +121,0 @@ type ErrorRetryOptions = {

@@ -14,23 +14,9 @@ import { XiorError } from 'xior/utils';

RESI: {
fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
onRejected?: (error: XiorError) => any;
fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
/** error: XiorError | Error | TypeError */
onRejected?: null | ((error: XiorError) => any);
}[];
get interceptors(): {
request: {
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | undefined) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void;

@@ -40,49 +26,4 @@ clear: () => void;

response: {
use: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}, onRejected?: ((error: XiorError) => any) | undefined) => (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
eject: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => void;
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void;
clear: () => void;

@@ -163,2 +104,17 @@ };

type XiorPlugin = (adapter: (request: XiorRequestConfig) => Promise<XiorResponse>, instance?: XiorInstance) => (request: XiorRequestConfig) => Promise<XiorResponse<any>>;
interface XiorInterceptorOptions {
/** @deprecated useless here */
synchronous?: boolean;
/** @deprecated useless here */
runWhen?: (config: XiorInterceptorRequestConfig) => boolean;
}
interface XiorResponseInterceptorConfig<T = any> {
data: T;
config: XiorInterceptorRequestConfig<T>;
request: XiorInterceptorRequestConfig<T>;
response: Response;
status: number;
statusText: string;
headers: Headers;
}

@@ -165,0 +121,0 @@ interface AsymmetricMatcher {

@@ -14,23 +14,9 @@ import { XiorError } from 'xior/utils';

RESI: {
fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
onRejected?: (error: XiorError) => any;
fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
/** error: XiorError | Error | TypeError */
onRejected?: null | ((error: XiorError) => any);
}[];
get interceptors(): {
request: {
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | undefined) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void;

@@ -40,49 +26,4 @@ clear: () => void;

response: {
use: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}, onRejected?: ((error: XiorError) => any) | undefined) => (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
eject: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => void;
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void;
clear: () => void;

@@ -163,2 +104,17 @@ };

type XiorPlugin = (adapter: (request: XiorRequestConfig) => Promise<XiorResponse>, instance?: XiorInstance) => (request: XiorRequestConfig) => Promise<XiorResponse<any>>;
interface XiorInterceptorOptions {
/** @deprecated useless here */
synchronous?: boolean;
/** @deprecated useless here */
runWhen?: (config: XiorInterceptorRequestConfig) => boolean;
}
interface XiorResponseInterceptorConfig<T = any> {
data: T;
config: XiorInterceptorRequestConfig<T>;
request: XiorInterceptorRequestConfig<T>;
response: Response;
status: number;
statusText: string;
headers: Headers;
}

@@ -165,0 +121,0 @@ interface XiorProgressOptions {

@@ -23,23 +23,9 @@ import { XiorError } from 'xior/utils';

RESI: {
fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
onRejected?: (error: XiorError) => any;
fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
/** error: XiorError | Error | TypeError */
onRejected?: null | ((error: XiorError) => any);
}[];
get interceptors(): {
request: {
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | undefined) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
use: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig, onRejected?: ((error: any) => any) | null | undefined, options?: XiorInterceptorOptions) => (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig;
eject: (fn: (config: XiorInterceptorRequestConfig) => Promise<XiorInterceptorRequestConfig> | XiorInterceptorRequestConfig) => void;

@@ -49,49 +35,4 @@ clear: () => void;

response: {
use: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}, onRejected?: ((error: XiorError) => any) | undefined) => (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
};
eject: (fn: (config: {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => Promise<{
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}> | {
data: any;
config: XiorInterceptorRequestConfig;
request: XiorInterceptorRequestConfig;
response: Response;
}) => void;
use: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig, onRejected?: ((error: XiorError) => any) | null | undefined) => (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig;
eject: (fn: (config: XiorResponseInterceptorConfig) => Promise<XiorResponseInterceptorConfig> | XiorResponseInterceptorConfig) => void;
clear: () => void;

@@ -172,2 +113,17 @@ };

type XiorPlugin = (adapter: (request: XiorRequestConfig) => Promise<XiorResponse>, instance?: XiorInstance) => (request: XiorRequestConfig) => Promise<XiorResponse<any>>;
interface XiorInterceptorOptions {
/** @deprecated useless here */
synchronous?: boolean;
/** @deprecated useless here */
runWhen?: (config: XiorInterceptorRequestConfig) => boolean;
}
interface XiorResponseInterceptorConfig<T = any> {
data: T;
config: XiorInterceptorRequestConfig<T>;
request: XiorInterceptorRequestConfig<T>;
response: Response;
status: number;
statusText: string;
headers: Headers;
}

@@ -174,0 +130,0 @@ type XiorPromise = Promise<XiorResponse>;

@@ -124,3 +124,3 @@ [![Build](https://github.com/suhaotian/xior/actions/workflows/check.yml/badge.svg)](https://github.com/suhaotian/xior/actions/workflows/check.yml)

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/dist/xior.umd.js"></script>

@@ -140,3 +140,3 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/dist/xior.umd.js"></script>

@@ -321,2 +321,3 @@ <!-- Usage -->

}
return Promise.reject(error);
}

@@ -665,5 +666,5 @@ );

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/error-retry.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/plugins/error-retry.umd.js"></script>

@@ -681,6 +682,6 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://unpkg.com/xior@0.3.13/plugins/error-retry.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/plugins/error-retry.umd.js"></script>

@@ -778,5 +779,5 @@ <!-- Usage -->

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/throttle.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/plugins/throttle.umd.js"></script>

@@ -794,6 +795,6 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://unpkg.com/xior@0.3.13/plugins/throttle.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/plugins/throttle.umd.js"></script>

@@ -853,5 +854,5 @@ <!-- Usage -->

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/dedupe.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/plugins/dedupe.umd.js"></script>

@@ -869,6 +870,6 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://unpkg.com/xior@0.3.13/plugins/dedupe.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/plugins/dedupe.umd.js"></script>

@@ -935,5 +936,5 @@ <!-- Usage -->

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/error-cache.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/plugins/error-cache.umd.js"></script>

@@ -951,6 +952,6 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://unpkg.com/xior@0.3.13/plugins/error-cache.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/plugins/error-cache.umd.js"></script>

@@ -1100,5 +1101,5 @@ <!-- Usage -->

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/progress.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/plugins/progress.umd.js"></script>

@@ -1116,6 +1117,6 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://unpkg.com/xior@0.3.13/plugins/progress.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/plugins/progress.umd.js"></script>

@@ -1227,5 +1228,5 @@ <!-- Usage -->

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.13/plugins/mock.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.4.0/plugins/mock.umd.js"></script>

@@ -1243,6 +1244,6 @@ <!-- Usage -->

```html
<script src="https://unpkg.com/xior@0.3.13/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/dist/xior.umd.js"></script>
<!-- Load plugin -->
<script src="https://unpkg.com/xior@0.3.13/plugins/mock.umd.js"></script>
<script src="https://unpkg.com/xior@0.4.0/plugins/mock.umd.js"></script>

@@ -1354,5 +1355,33 @@ <!-- Usage -->

> Currently in `xior`, when `responseType` is set to `'stream', 'document', 'arraybuffer', 'blob', or 'original'`, Xior will return the original fetch response.
When `{responseType: 'blob'| 'arraybuffer'}`:
```ts
xior.get('https://exmaple.com/some/api', { responseType: 'blob' }).then((response) => {
console.log(response.data); // response.data is a Blob
});
// Same with
fetch('https://exmaple.com/some/api')
.then((response) => response.blob())
.then((data) => {
console.log(data); // is a Blob
});
```
```ts
xior.get('https://exmaple.com/some/api', { responseType: 'arraybuffer' }).then((response) => {
console.log(response.data); // response.data is a ArrayBuffer
});
// Same with
fetch('https://exmaple.com/some/api')
.then((response) => response.arraybuffer())
.then((data) => {
console.log(data); // is a ArrayBuffer
});
```
**But when `responseType` set to `'stream', 'document' or 'original'`, Xior will return the original fetch response:**
```ts
fetch('https://exmaple.com/some/api').then((response) => {

@@ -1363,4 +1392,4 @@ console.log(response);

// same with
xior.get('https://exmaple.com/some/api', { responseType: 'blob' }).then((res) => {
console.log(res.response); // res.data will be undefined
xior.get('https://exmaple.com/some/api', { responseType: 'stream' }).then((res) => {
console.log(res.response); // But res.data will be undefined
});

@@ -1367,0 +1396,0 @@ ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc