Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.6 to 0.3.7

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;let h=yield function(e){return f.apply(this,arguments)}(e),{url:d,method:p,headers:E,timeout:m,signal:O,data:R,_data:g,_url:P,isGet:I}=h,S=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}(h,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);e._url=P;let T=[];if(m&&v){let t=new AbortController;c=setTimeout(()=>{t.abort(new r(`timeout of ${m}ms exceeded`,e))},m),T.push(t.signal)}O&&T.push(O),l=T[0],T.length>1&&(l=n(T,()=>{clearTimeout(c)}));let b=P||d||"";e.baseURL&&!i(b)&&(b=s(e.baseURL,b));let j=yield fetch(b,y({body:I?void 0:g},S,{signal:l,method:p,headers:E}));c&&clearTimeout(c),null==l||null==(a=l.clear)||a.call(l);let w={response:j,config:e,status:j.status,statusText:j.statusText,headers:j.headers};if(!j.ok){let r;try{(r=yield j.text())&&(r=JSON.parse(r))}catch(e){}let n=new o(j.status?`Request failed with status code ${j.status}`:"Network error",e,y({data:r},w));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"===p)return y({data:void 0,request:e},w);let{responseType:x}=e;if(!x||["json","text"].includes(x)){let r;try{(r=yield j.text())&&"text"!==x&&(r=JSON.parse(r))}catch(e){}let n={data:r,config:e,request:e,response:j};for(let e of t.RESI)n=yield e.fn(n);return y({data:n.data,request:e},w)}return y({data:void 0,request:e},w)})()}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.6";let m=Object.assign(E.create(),{create:E.create,VERSION:E.VERSION});export{m as default,E as xior};
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;let h=yield function(e){return f.apply(this,arguments)}(e),{url:d,method:p,headers:E,timeout:m,signal:O,data:R,_data:g,_url:P,isGet:I}=h,S=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}(h,["url","method","headers","timeout","signal","data","_data","_url","isGet"]);e._url=P;let T=[];if(m&&v){let t=new AbortController;c=setTimeout(()=>{t.abort(new r(`timeout of ${m}ms exceeded`,e))},m),T.push(t.signal)}O&&T.push(O),l=T[0],T.length>1&&(l=n(T,()=>{clearTimeout(c)}));let b=P||d||"";e.baseURL&&!i(b)&&(b=s(e.baseURL,b));let j=yield fetch(b,y({body:I?void 0:g},S,{signal:l,method:p,headers:E}));c&&clearTimeout(c),null==l||null==(a=l.clear)||a.call(l);let w={response:j,config:e,status:j.status,statusText:j.statusText,headers:j.headers};if(!j.ok){let r;try{(r=yield j.text())&&(r=JSON.parse(r))}catch(e){}let n=new o(j.status?`Request failed with status code ${j.status}`:"Network error",e,y({data:r},w));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"===p)return y({data:void 0,request:e},w);let{responseType:x}=e;if(!x||["json","text"].includes(x)){let r;try{(r=yield j.text())&&"text"!==x&&(r=JSON.parse(r))}catch(e){}let n={data:r,config:e,request:e,response:j};for(let e of t.RESI)n=yield e.fn(n);return y({data:n.data,request:e},w)}return y({data:void 0,request:e},w)})()}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.7";let m=Object.assign(E.create(),{create:E.create,VERSION:E.VERSION});export{m as default,E as 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{u(o.next(e))}catch(e){s(e)}}function a(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}u((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 u(e="GET"){return["HEAD","GET","OPTIONS"].includes(e)}t.likeGET=u,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 c=s,l=e.data;let d=l;const f=(null==e?void 0:e.headers)||{};let h=e.params||{};const p=u(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:c,_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{u(o.next(e))}catch(e){s(e)}}function a(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}u((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)),u="undefined"!=typeof AbortController;class c{static create(e){return new c(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:c,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 v;if(d&&u){const t=new AbortController;v=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(v)})));let j=y||s||"";e.baseURL&&!(0,i.isAbsoluteURL)(j)&&(j=(0,i.joinPath)(e.baseURL,j));const E=yield fetch(j,Object.assign(Object.assign({body:m?void 0:p},b),{signal:g,method:c,headers:l}));v&&clearTimeout(v),null===(t=null==g?void 0:g.clear)||void 0===t||t.call(g);const P={response:E,config:e,status:E.status,statusText:E.statusText,headers:E.headers};if(!E.ok){let t;try{t=yield E.text(),t&&(t=JSON.parse(t))}catch(e){}const o=new i.XiorError(E.status?`Request failed with status code ${E.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"===c)return Object.assign({data:void 0,request:e},P);const{responseType:_}=e;if(!_||["json","text"].includes(_)){let t;try{t=yield E.text(),t&&"text"!==_&&(t=JSON.parse(t))}catch(e){}let r={data:t,config:e,request:e,response:E};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=c,c.VERSION="0.3.6"},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:"?"+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],u=o?`${o}[${s(i)}]`:s(i);if("object"==typeof a){let t=e(a,r,u);""!==t&&n.push(t)}else Array.isArray(a)?a.forEach(((e,t)=>{let r=`${u}[${t}]`;n.push(`${s(r)}=${s(e)}`)})):n.push(`${s(u)}=${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.startsWith("/")?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 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{u(o.next(e))}catch(e){s(e)}}function a(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}u((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 u(e="GET"){return["HEAD","GET","OPTIONS"].includes(e)}t.likeGET=u,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 c=s,l=e.data;let d=l;const f=(null==e?void 0:e.headers)||{};let h=e.params||{};const p=u(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:c,_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{u(o.next(e))}catch(e){s(e)}}function a(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,a)}u((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)),u="undefined"!=typeof AbortController;class c{static create(e){return new c(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:c,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 v;if(d&&u){const t=new AbortController;v=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(v)})));let j=y||s||"";e.baseURL&&!(0,i.isAbsoluteURL)(j)&&(j=(0,i.joinPath)(e.baseURL,j));const E=yield fetch(j,Object.assign(Object.assign({body:m?void 0:p},b),{signal:g,method:c,headers:l}));v&&clearTimeout(v),null===(t=null==g?void 0:g.clear)||void 0===t||t.call(g);const P={response:E,config:e,status:E.status,statusText:E.statusText,headers:E.headers};if(!E.ok){let t;try{t=yield E.text(),t&&(t=JSON.parse(t))}catch(e){}const o=new i.XiorError(E.status?`Request failed with status code ${E.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"===c)return Object.assign({data:void 0,request:e},P);const{responseType:_}=e;if(!_||["json","text"].includes(_)){let t;try{t=yield E.text(),t&&"text"!==_&&(t=JSON.parse(t))}catch(e){}let r={data:t,config:e,request:e,response:E};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=c,c.VERSION="0.3.7"},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:"?"+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],u=o?`${o}[${s(i)}]`:s(i);if("object"==typeof a){let t=e(a,r,u);""!==t&&n.push(t)}else Array.isArray(a)?a.forEach(((e,t)=>{let r=`${u}[${t}]`;n.push(`${s(r)}=${s(e)}`)})):n.push(`${s(u)}=${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.startsWith("/")?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}));

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

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

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

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

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

{
"name": "xior",
"version": "0.3.6",
"version": "0.3.7",
"description": "A lite request lib based on fetch with plugins support, and axios similar API",

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

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

!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.xiorErrorCache=r():e.xiorErrorCache=r()}(this,(()=>{return e={431:function(e,r,t){"use strict";var o=this&&this.__awaiter||function(e,r,t,o){return new(t||(t=Promise))((function(n,i){function s(e){try{a(o.next(e))}catch(e){i(e)}}function u(e){try{a(o.throw(e))}catch(e){i(e)}}function a(e){var r;e.done?n(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(s,u)}a((o=o.apply(e,r||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0});const n=t(121),i={},s={get:e=>i[e],set(e,r){i[e]=r}};r.default=function(e={}){const{enableCache:r,defaultCache:t=s}=e;return function(e){return i=>o(this,void 0,void 0,(function*(){const{enableCache:o=r,defaultCache:s=t,paramsSerializer:u}=i,a="GET"===i.method||i.isGet,c=typeof o;if(!("undefined"===c?a:"function"===c?o(i):Boolean(o)))return e(i);const l=s,f=(0,n.buildSortedURL)(i.url&&(0,n.isAbsoluteURL)(i.url)?i.url:(0,n.joinPath)(i.baseURL||"",i.url||""),{a:i.data,b:i.params},u);try{const r=yield e(i);return l.set(f,r),r}catch(e){const r=l.get(f);if(r)return r.fromCache=!0,r.error=e,r;throw e}}))}}},602:(e,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.merge=void 0;const t=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const r=Object.getPrototypeOf(e);return r===Object.prototype||null===r}return"[object Object]"===Object.prototype.toString.call(e)}return!1};r.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]=r.merge.options.mergeArrays?r.merge.options.uniqueArrayItems?Array.from(new Set(e[n].concat(o[n]))):[...e[n],...o[n]]:o[n]:t(e[n])&&t(o[n])?e[n]=(0,r.merge)(e[n],o[n]):e[n]=void 0===o[n]?r.merge.options.allowUndefinedOverrides?o[n]:e[n]:o[n])})),e}),{});const o={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};r.merge.options=o,r.merge.withOptions=(e,...t)=>{r.merge.options=Object.assign(Object.assign({},o),e);const n=(0,r.merge)(...t);return r.merge.options=o,n}},121:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0});var o=t(602);class n extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}Object.defineProperty(r,"merge",{enumerable:!0,get:function(){return o.merge}}),r.XiorError=n,r.XiorTimeoutError=class extends n{constructor(e,r,t){super(e),this.name="XiorTimeoutError",this.request=r,this.config=r,this.response=t}},r.anySignal=function(e,r){let t=new globalThis.AbortController;function o(e){t.abort(e),i()}let n=[];for(let r of e){if(!0===(null==r?void 0:r.aborted)){o(r.reason);break}if(null!=(null==r?void 0:r.addEventListener)){let e=()=>{o(r.reason)};n.push((()=>{null!=(null==r?void 0:r.removeEventListener)&&r.removeEventListener("abort",e)})),r.addEventListener("abort",e)}}function i(){n.forEach((e=>{e()})),null==r||r()}let s=t.signal;return s.clear=i,s},r.buildSortedURL=function(e,r,t){let o=r?t(r):"";o&&(o=e+(e.includes("?")?"&"+o:"?"+o));let[n,i]=o.split("?");return i?`${n}?${i.split("&").sort().join("&")}`:o||e},r.delay=function(e){return new Promise((r=>{setTimeout((()=>{r("ok")}),e)}))},r.encodeParams=function e(r,t=!0,o=null){if(null==r)return"";let n=[],i=t?encodeURIComponent:e=>e;for(let s in r)if(Object.prototype.hasOwnProperty.call(r,s)){let u=r[s],a=o?`${o}[${i(s)}]`:i(s);if("object"==typeof u){let r=e(u,t,a);""!==r&&n.push(r)}else Array.isArray(u)?u.forEach(((e,r)=>{let t=`${a}[${r}]`;n.push(`${i(t)}=${i(e)}`)})):n.push(`${i(a)}=${i(u)}`)}return n.join("&")},r.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},r.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},r.joinPath=function(e,r){return r?(e.endsWith("/")?e:e+"/")+(r.startsWith("/")?r.slice(1):r):e}}},r={},function t(o){var n=r[o];if(void 0!==n)return n.exports;var i=r[o]={exports:{}};return e[o].call(i.exports,i,i.exports,t),i.exports}(431).default;var e,r}));
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.xiorErrorCache=r():e.xiorErrorCache=r()}(this,(()=>{return e={431:function(e,r,t){"use strict";var o=this&&this.__awaiter||function(e,r,t,o){return new(t||(t=Promise))((function(n,i){function s(e){try{a(o.next(e))}catch(e){i(e)}}function u(e){try{a(o.throw(e))}catch(e){i(e)}}function a(e){var r;e.done?n(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(s,u)}a((o=o.apply(e,r||[])).next())}))};Object.defineProperty(r,"__esModule",{value:!0});const n=t(121),i={},s={get:e=>i[e],set(e,r){i[e]=r}};r.default=function(e={}){const{enableCache:r,defaultCache:t=s,useCacheFirst:i,onCacheRequest:u}=e;return function(e){return s=>o(this,void 0,void 0,(function*(){const{enableCache:a=r,defaultCache:l=t,useCacheFirst:c=i,onCacheRequest:d=u,paramsSerializer:f}=s,p="GET"===s.method||s.isGet,h=typeof a;if(!("undefined"===h?p:"function"===h?a(s):Boolean(a)))return e(s);const m=l,y=(0,n.buildSortedURL)(s.url&&(0,n.isAbsoluteURL)(s.url)?s.url:(0,n.joinPath)(s.baseURL||"",s.url||""),{a:s.data,b:s.params},f);try{if(c){const r=m.get(y);if(m.set(y,{loading:!0,res:null==r?void 0:r.res}),null==r?void 0:r.res)return(null==r?void 0:r.loading)||(null==d||d(s),(()=>{o(this,void 0,void 0,(function*(){try{const r=yield e(s);m.set(y,{loading:!1,res:r})}catch(e){const r=m.get(y);c&&m.set(y,{loading:!1,res:null==r?void 0:r.res})}}))})()),r.res.fromCache=!0,null==r?void 0:r.res}const r=yield e(s);return m.set(y,{loading:!1,res:r}),r}catch(e){const r=m.get(y);if(c&&m.set(y,{loading:!1,res:null==r?void 0:r.res}),null==r?void 0:r.res)return r.res.fromCache=!0,r.res.error=e,r.res;throw e}}))}}},602:(e,r)=>{"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.merge=void 0;const t=e=>{if("object"==typeof e&&null!==e){if("function"==typeof Object.getPrototypeOf){const r=Object.getPrototypeOf(e);return r===Object.prototype||null===r}return"[object Object]"===Object.prototype.toString.call(e)}return!1};r.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]=r.merge.options.mergeArrays?r.merge.options.uniqueArrayItems?Array.from(new Set(e[n].concat(o[n]))):[...e[n],...o[n]]:o[n]:t(e[n])&&t(o[n])?e[n]=(0,r.merge)(e[n],o[n]):e[n]=void 0===o[n]?r.merge.options.allowUndefinedOverrides?o[n]:e[n]:o[n])})),e}),{});const o={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};r.merge.options=o,r.merge.withOptions=(e,...t)=>{r.merge.options=Object.assign(Object.assign({},o),e);const n=(0,r.merge)(...t);return r.merge.options=o,n}},121:(e,r,t)=>{Object.defineProperty(r,"__esModule",{value:!0});var o=t(602);class n extends Error{constructor(e,r,t){super(e),this.name="XiorError",this.request=r,this.config=r,this.response=t}}Object.defineProperty(r,"merge",{enumerable:!0,get:function(){return o.merge}}),r.XiorError=n,r.XiorTimeoutError=class extends n{constructor(e,r,t){super(e),this.name="XiorTimeoutError",this.request=r,this.config=r,this.response=t}},r.anySignal=function(e,r){let t=new globalThis.AbortController;function o(e){t.abort(e),i()}let n=[];for(let r of e){if(!0===(null==r?void 0:r.aborted)){o(r.reason);break}if(null!=(null==r?void 0:r.addEventListener)){let e=()=>{o(r.reason)};n.push((()=>{null!=(null==r?void 0:r.removeEventListener)&&r.removeEventListener("abort",e)})),r.addEventListener("abort",e)}}function i(){n.forEach((e=>{e()})),null==r||r()}let s=t.signal;return s.clear=i,s},r.buildSortedURL=function(e,r,t){let o=r?t(r):"";o&&(o=e+(e.includes("?")?"&"+o:"?"+o));let[n,i]=o.split("?");return i?`${n}?${i.split("&").sort().join("&")}`:o||e},r.delay=function(e){return new Promise((r=>{setTimeout((()=>{r("ok")}),e)}))},r.encodeParams=function e(r,t=!0,o=null){if(null==r)return"";let n=[],i=t?encodeURIComponent:e=>e;for(let s in r)if(Object.prototype.hasOwnProperty.call(r,s)){let u=r[s],a=o?`${o}[${i(s)}]`:i(s);if("object"==typeof u){let r=e(u,t,a);""!==r&&n.push(r)}else Array.isArray(u)?u.forEach(((e,r)=>{let t=`${a}[${r}]`;n.push(`${i(t)}=${i(e)}`)})):n.push(`${i(a)}=${i(u)}`)}return n.join("&")},r.isAbsoluteURL=function(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)},r.isXiorError=function(e){return"XiorError"===e.name||"XiorTimeoutError"===e.name},r.joinPath=function(e,r){return r?(e.endsWith("/")?e:e+"/")+(r.startsWith("/")?r.slice(1):r):e}}},r={},function t(o){var n=r[o];if(void 0!==n)return n.exports;var i=r[o]={exports:{}};return e[o].call(i.exports,i,i.exports,t),i.exports}(431).default;var e,r}));

@@ -173,6 +173,13 @@ import { XiorError } from 'xior/utils';

/**
* check if we need enable cache, default only `GET` method or`isGet: true` enable cache
* check if we need enable cache, default only `GET` method or`isGet: true` enable cache @error-cache-plugin
*/
enableCache?: boolean | ((config?: XiorRequestConfig) => boolean);
defaultCache?: ICacheLike<XiorResponse>;
defaultCache?: ICacheLike<{
loading?: boolean;
res?: XiorResponse;
}>;
/** if `useCacheFirst: true` and have cache, will return the cache response first, then run fetching in the background @error-cache-plugin */
useCacheFirst?: boolean;
/** for logging purpose @error-cache-plugin */
onCacheRequest?: (config?: XiorRequestConfig) => void;
};

@@ -179,0 +186,0 @@ /** @ts-ignore */

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

import{buildSortedURL as t,isAbsoluteURL as e,joinPath as r}from"xior/utils";function n(t,e,r,n,o,u,i){try{var a=t[u](i),l=a.value}catch(t){r(t);return}a.done?e(l):Promise.resolve(l).then(n,o)}let o={},u={get:t=>o[t],set(t,e){o[t]=e}};function i(o={}){let{enableCache:i,defaultCache:a=u}=o;return function(o){var u;return u=function*(n){let{enableCache:u=i,defaultCache:l=a,paramsSerializer:c}=n,f="GET"===n.method||n.isGet,h=typeof u;if(!("undefined"===h?f:"function"===h?u(n):!!u))return o(n);let s=t(n.url&&e(n.url)?n.url:r(n.baseURL||"",n.url||""),{a:n.data,b:n.params},c);try{let t=yield o(n);return l.set(s,t),t}catch(e){let t=l.get(s);if(t)return t.fromCache=!0,t.error=e,t;throw e}},function(){var t=this,e=arguments;return new Promise(function(r,o){var i=u.apply(t,e);function a(t){n(i,r,o,a,l,"next",t)}function l(t){n(i,r,o,a,l,"throw",t)}a(void 0)})}}}export{i as default};
import{buildSortedURL as e,isAbsoluteURL as r,joinPath as t}from"xior/utils";function n(e,r,t,n,l,o,i){try{var u=e[o](i),a=u.value}catch(e){t(e);return}u.done?r(a):Promise.resolve(a).then(n,l)}function l(e){return function(){var r=this,t=arguments;return new Promise(function(l,o){var i=e.apply(r,t);function u(e){n(i,l,o,u,a,"next",e)}function a(e){n(i,l,o,u,a,"throw",e)}u(void 0)})}}let o={},i={get:e=>o[e],set(e,r){o[e]=r}};function u(n={}){let{enableCache:o,defaultCache:u=i,useCacheFirst:a,onCacheRequest:s}=n;return function(n){return l(function*(i){let{enableCache:c=o,defaultCache:d=u,useCacheFirst:f=a,onCacheRequest:h=s,paramsSerializer:v}=i,g="GET"===i.method||i.isGet,m=typeof c;if(!("undefined"===m?g:"function"===m?c(i):!!c))return n(i);let y=e(i.url&&r(i.url)?i.url:t(i.baseURL||"",i.url||""),{a:i.data,b:i.params},v);try{if(f){let e=d.get(y);if(d.set(y,{loading:!0,res:null==e?void 0:e.res}),null==e?void 0:e.res)return(null==e?void 0:e.loading)||(null==h||h(i),l(function*(){try{let e=yield n(i);d.set(y,{loading:!1,res:e})}catch(r){let e=d.get(y);f&&d.set(y,{loading:!1,res:null==e?void 0:e.res})}})()),e.res.fromCache=!0,null==e?void 0:e.res}let e=yield n(i);return d.set(y,{loading:!1,res:e}),e}catch(r){let e=d.get(y);if(f&&d.set(y,{loading:!1,res:null==e?void 0:e.res}),null==e?void 0:e.res)return e.res.fromCache=!0,e.res.error=r,e.res;throw r}})}}export{u as default};

@@ -120,3 +120,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.6/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.7/dist/xior.umd.js"></script>

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

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

@@ -503,5 +503,5 @@ <!-- Usage -->

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

@@ -519,6 +519,6 @@ <!-- Usage -->

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

@@ -613,5 +613,5 @@ <!-- Usage -->

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

@@ -629,6 +629,6 @@ <!-- Usage -->

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

@@ -688,5 +688,5 @@ <!-- Usage -->

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

@@ -704,6 +704,6 @@ <!-- Usage -->

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

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

defaultCache?: ICacheLike<XiorPromise>;
useCacheFirst?: boolean;
}): XiorPlugin;

@@ -734,6 +735,7 @@ ```

| Param | Type | Default value | Description |
| ------------ | -------------------------------------------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| enableCache | boolean \| ((config: Xiorconfig) => boolean) | (config) => config.method === 'GET' \|\| config.isGet | Default only enabled in `GET` request |
| defaultCache | CacheLike | lru(Inifinite, 0) | will used for storing requests by default, except you define a custom Cache with your request config, use `tiny-lru` module |
| Param | Type | Default value | Description |
| ------------- | -------------------------------------------- | ----------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| enableCache | boolean \| ((config: Xiorconfig) => boolean) | (config) => config.method === 'GET' \|\| config.isGet | Default only enabled in `GET` request |
| defaultCache | CacheLike | lru(Inifinite, 0) | will used for storing requests by default, except you define a custom Cache with your request config, use `tiny-lru` module |
| useCacheFirst | boolean | false | If `useCacheFirst: true` and there's a cache, it will return the cached response first, then run fetching in the background. This is useful when the response takes a long time, and the data is unnecessary in real-time. |

@@ -768,5 +770,5 @@ Basic usage:

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

@@ -784,6 +786,6 @@ <!-- Usage -->

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

@@ -923,5 +925,5 @@ <!-- Usage -->

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

@@ -939,6 +941,6 @@ <!-- Usage -->

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

@@ -1050,5 +1052,5 @@ <!-- Usage -->

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

@@ -1066,6 +1068,6 @@ <!-- Usage -->

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

@@ -1072,0 +1074,0 @@ <!-- Usage -->

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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