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.5 to 0.3.6

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))}return Object.keys(p).length>0&&(o+=o.includes("?")?`&${n(p,i)}`:`?${n(p,i)}`),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.5";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.6";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))}return Object.keys(h).length>0&&(s+=s.includes("?")?`&${t(h,r)}`:`?${t(h,r)}`),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.5"},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.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}));

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

```html
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.4/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.4/plugins/mock.umd.js"></script>
<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>

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

```html
<script src="https://unpkg.com/xior@0.3.4/dist/xior.umd.js"></script>
<script src="https://unpkg.com/xior@0.3.4/plugins/mock.umd.js"></script>
<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>

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

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

@@ -11,4 +11,2 @@ "repository": "suhaotian/xior",

"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"module": "./dist/index.esm.js",
"exports": {

@@ -19,3 +17,3 @@ ".": {

"import": "./dist/index.mjs",
"module": "./dist/index.mjs"
"module": "./dist/index.esm.js"
},

@@ -22,0 +20,0 @@ "./utils": {

/*! For license information please see throttle.umd.js.LICENSE.txt */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.xiorThrottle=e():t.xiorThrottle=e()}(this,(()=>{return t={272:function(t,e,r){"use strict";var s=this&&this.__awaiter||function(t,e,r,s){return new(r||(r=Promise))((function(i,n){function o(t){try{u(s.next(t))}catch(t){n(t)}}function l(t){try{u(s.throw(t))}catch(t){n(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,l)}u((s=s.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const i=r(455),n=r(121);e.default=function(t={}){const{enableThrottle:e,threshold:r=1e3,throttleCache:o=(0,i.lru)(10)}=t,l=o;return function(t){const i=(e,r)=>{const i=(()=>s(this,void 0,void 0,(function*(){try{const s=yield t(r);return l.set(e,{timestamp:Date.now(),value:Promise.resolve(s)}),s}catch(t){throw"delete"in l?l.delete(e):l.del(e),t}})))();return l.set(e,{timestamp:Date.now(),value:i}),i};return o=>s(this,void 0,void 0,(function*(){const{paramsSerializer:s,threshold:u=r,enableThrottle:a=e}=o,h="GET"===o.method||o.isGet,c=typeof a;if("undefined"===c?h:"function"===c?a(o):Boolean(a)){const t=(0,n.buildSortedURL)(o.url&&(0,n.isAbsoluteURL)(o.url)?o.url:(0,n.joinPath)(o.baseURL||"",o.url||""),{a:o.data,b:o.params},s),e=Date.now(),r=l.get(t)||{timestamp:e};if(e-r.timestamp<=u){const t=r.value;if(t)return t}return i(t,o)}return t(o)}))}}},455:(t,e)=>{"use strict";class r{constructor(t=0,e=0,r=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=r,this.size=0,this.ttl=e}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){const e=this.items[t];delete this.items[t],this.size--,null!==e.prev&&(e.prev.next=e.next),null!==e.next&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),this.last===e&&(this.last=e.prev)}return this}entries(t=this.keys()){return t.map((t=>[t,this.get(t)]))}evict(t=!1){if(t||this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}expiresAt(t){let e;return this.has(t)&&(e=this.items[t].expiry),e}get(t){let e;if(this.has(t)){const r=this.items[t];this.ttl>0&&r.expiry<=Date.now()?this.delete(t):(e=r.value,this.set(t,e,!0))}return e}has(t){return t in this.items}keys(){const t=[];let e=this.first;for(;null!==e;)t.push(e.key),e=e.next;return t}set(t,e,r=!1,s=this.resetTtl){let i;if(r||this.has(t)){if(i=this.items[t],i.value=e,!1===r&&s&&(i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==i){const t=this.last,e=i.next,r=i.prev;this.first===i&&(this.first=i.next),i.next=null,i.prev=this.last,t.next=i,null!==r&&(r.next=e),null!==e&&(e.prev=r)}}else this.max>0&&this.size===this.max&&this.evict(!0),i=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},1==++this.size?this.first=i:this.last.next=i;return this.last=i,this}values(t=this.keys()){return t.map((t=>this.get(t)))}}e.LRU=r,e.lru=function(t=1e3,e=0,s=!1){if(isNaN(t)||t<0)throw new TypeError("Invalid max value");if(isNaN(e)||e<0)throw new TypeError("Invalid ttl value");if("boolean"!=typeof s)throw new TypeError("Invalid resetTtl value");return new r(t,e,s)}},602:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.merge=void 0;const r=t=>{if("object"==typeof t&&null!==t){if("function"==typeof Object.getPrototypeOf){const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}return"[object Object]"===Object.prototype.toString.call(t)}return!1};e.merge=(...t)=>t.reduce(((t,s)=>{if(Array.isArray(s))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(s).forEach((i=>{["__proto__","constructor","prototype"].includes(i)||(Array.isArray(t[i])&&Array.isArray(s[i])?t[i]=e.merge.options.mergeArrays?e.merge.options.uniqueArrayItems?Array.from(new Set(t[i].concat(s[i]))):[...t[i],...s[i]]:s[i]:r(t[i])&&r(s[i])?t[i]=(0,e.merge)(t[i],s[i]):t[i]=void 0===s[i]?e.merge.options.allowUndefinedOverrides?s[i]:t[i]:s[i])})),t}),{});const s={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};e.merge.options=s,e.merge.withOptions=(t,...r)=>{e.merge.options=Object.assign(Object.assign({},s),t);const i=(0,e.merge)(...r);return e.merge.options=s,i}},121:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var s=r(602);class i extends Error{constructor(t,e,r){super(t),this.name="XiorError",this.request=e,this.config=e,this.response=r}}Object.defineProperty(e,"merge",{enumerable:!0,get:function(){return s.merge}}),e.XiorError=i,e.XiorTimeoutError=class extends i{constructor(t,e,r){super(t),this.name="XiorTimeoutError",this.request=e,this.config=e,this.response=r}},e.anySignal=function(t,e){let r=new globalThis.AbortController;function s(t){r.abort(t),n()}let i=[];for(let e of t){if(!0===(null==e?void 0:e.aborted)){s(e.reason);break}if(null!=(null==e?void 0:e.addEventListener)){let t=()=>{s(e.reason)};i.push((()=>{null!=(null==e?void 0:e.removeEventListener)&&e.removeEventListener("abort",t)})),e.addEventListener("abort",t)}}function n(){i.forEach((t=>{t()})),null==e||e()}let o=r.signal;return o.clear=n,o},e.buildSortedURL=function(t,e,r){let s=e?r(e):"";s&&(s=t+(t.includes("?")?"&"+s:"?"+s));let[i,n]=s.split("?");return n?`${i}?${n.split("&").sort().join("&")}`:s||t},e.delay=function(t){return new Promise((e=>{setTimeout((()=>{e("ok")}),t)}))},e.encodeParams=function t(e,r=!0,s=null){if(null==e)return"";let i=[],n=r?encodeURIComponent:t=>t;for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o)){let l=e[o],u=s?`${s}[${n(o)}]`:n(o);if("object"==typeof l){let e=t(l,r,u);""!==e&&i.push(e)}else Array.isArray(l)?l.forEach(((t,e)=>{let r=`${u}[${e}]`;i.push(`${n(r)}=${n(t)}`)})):i.push(`${n(u)}=${n(l)}`)}return i.join("&")},e.isAbsoluteURL=function(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)},e.isXiorError=function(t){return"XiorError"===t.name||"XiorTimeoutError"===t.name},e.joinPath=function(t,e){return e?(t.endsWith("/")?t:t+"/")+(e.startsWith("/")?e.slice(1):e):t}}},e={},function r(s){var i=e[s];if(void 0!==i)return i.exports;var n=e[s]={exports:{}};return t[s].call(n.exports,n,n.exports,r),n.exports}(272).default;var t,e}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.xiorThrottle=e():t.xiorThrottle=e()}(this,(()=>{return t={272:function(t,e,r){"use strict";var s=this&&this.__awaiter||function(t,e,r,s){return new(r||(r=Promise))((function(i,n){function o(t){try{u(s.next(t))}catch(t){n(t)}}function l(t){try{u(s.throw(t))}catch(t){n(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(o,l)}u((s=s.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const i=r(455),n=r(121);e.default=function(t={}){const{enableThrottle:e,threshold:r=1e3,throttleCache:o=(0,i.lru)(10),onThrottle:l}=t,u=o;return function(t){const i=(e,r)=>{const i=(()=>s(this,void 0,void 0,(function*(){try{const s=yield t(r);return u.set(e,{timestamp:Date.now(),value:Promise.resolve(s)}),s}catch(t){throw"delete"in u?u.delete(e):u.del(e),t}})))();return u.set(e,{timestamp:Date.now(),value:i}),i};return o=>s(this,void 0,void 0,(function*(){const{paramsSerializer:s,threshold:a=r,enableThrottle:h=e,onThrottle:c=l}=o,f="GET"===o.method||o.isGet,p=typeof h;if("undefined"===p?f:"function"===p?h(o):Boolean(h)){const t=(0,n.buildSortedURL)(o.url&&(0,n.isAbsoluteURL)(o.url)?o.url:(0,n.joinPath)(o.baseURL||"",o.url||""),{a:o.data,b:o.params},s),e=Date.now(),r=u.get(t)||{timestamp:e},l=r.value;return l&&e-r.timestamp<=a?(null==c||c(o),l):i(t,o)}return t(o)}))}}},455:(t,e)=>{"use strict";class r{constructor(t=0,e=0,r=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=r,this.size=0,this.ttl=e}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){const e=this.items[t];delete this.items[t],this.size--,null!==e.prev&&(e.prev.next=e.next),null!==e.next&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),this.last===e&&(this.last=e.prev)}return this}entries(t=this.keys()){return t.map((t=>[t,this.get(t)]))}evict(t=!1){if(t||this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}expiresAt(t){let e;return this.has(t)&&(e=this.items[t].expiry),e}get(t){let e;if(this.has(t)){const r=this.items[t];this.ttl>0&&r.expiry<=Date.now()?this.delete(t):(e=r.value,this.set(t,e,!0))}return e}has(t){return t in this.items}keys(){const t=[];let e=this.first;for(;null!==e;)t.push(e.key),e=e.next;return t}set(t,e,r=!1,s=this.resetTtl){let i;if(r||this.has(t)){if(i=this.items[t],i.value=e,!1===r&&s&&(i.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==i){const t=this.last,e=i.next,r=i.prev;this.first===i&&(this.first=i.next),i.next=null,i.prev=this.last,t.next=i,null!==r&&(r.next=e),null!==e&&(e.prev=r)}}else this.max>0&&this.size===this.max&&this.evict(!0),i=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},1==++this.size?this.first=i:this.last.next=i;return this.last=i,this}values(t=this.keys()){return t.map((t=>this.get(t)))}}e.LRU=r,e.lru=function(t=1e3,e=0,s=!1){if(isNaN(t)||t<0)throw new TypeError("Invalid max value");if(isNaN(e)||e<0)throw new TypeError("Invalid ttl value");if("boolean"!=typeof s)throw new TypeError("Invalid resetTtl value");return new r(t,e,s)}},602:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.merge=void 0;const r=t=>{if("object"==typeof t&&null!==t){if("function"==typeof Object.getPrototypeOf){const e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}return"[object Object]"===Object.prototype.toString.call(t)}return!1};e.merge=(...t)=>t.reduce(((t,s)=>{if(Array.isArray(s))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return Object.keys(s).forEach((i=>{["__proto__","constructor","prototype"].includes(i)||(Array.isArray(t[i])&&Array.isArray(s[i])?t[i]=e.merge.options.mergeArrays?e.merge.options.uniqueArrayItems?Array.from(new Set(t[i].concat(s[i]))):[...t[i],...s[i]]:s[i]:r(t[i])&&r(s[i])?t[i]=(0,e.merge)(t[i],s[i]):t[i]=void 0===s[i]?e.merge.options.allowUndefinedOverrides?s[i]:t[i]:s[i])})),t}),{});const s={allowUndefinedOverrides:!0,mergeArrays:!0,uniqueArrayItems:!0};e.merge.options=s,e.merge.withOptions=(t,...r)=>{e.merge.options=Object.assign(Object.assign({},s),t);const i=(0,e.merge)(...r);return e.merge.options=s,i}},121:(t,e,r)=>{Object.defineProperty(e,"__esModule",{value:!0});var s=r(602);class i extends Error{constructor(t,e,r){super(t),this.name="XiorError",this.request=e,this.config=e,this.response=r}}Object.defineProperty(e,"merge",{enumerable:!0,get:function(){return s.merge}}),e.XiorError=i,e.XiorTimeoutError=class extends i{constructor(t,e,r){super(t),this.name="XiorTimeoutError",this.request=e,this.config=e,this.response=r}},e.anySignal=function(t,e){let r=new globalThis.AbortController;function s(t){r.abort(t),n()}let i=[];for(let e of t){if(!0===(null==e?void 0:e.aborted)){s(e.reason);break}if(null!=(null==e?void 0:e.addEventListener)){let t=()=>{s(e.reason)};i.push((()=>{null!=(null==e?void 0:e.removeEventListener)&&e.removeEventListener("abort",t)})),e.addEventListener("abort",t)}}function n(){i.forEach((t=>{t()})),null==e||e()}let o=r.signal;return o.clear=n,o},e.buildSortedURL=function(t,e,r){let s=e?r(e):"";s&&(s=t+(t.includes("?")?"&"+s:"?"+s));let[i,n]=s.split("?");return n?`${i}?${n.split("&").sort().join("&")}`:s||t},e.delay=function(t){return new Promise((e=>{setTimeout((()=>{e("ok")}),t)}))},e.encodeParams=function t(e,r=!0,s=null){if(null==e)return"";let i=[],n=r?encodeURIComponent:t=>t;for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o)){let l=e[o],u=s?`${s}[${n(o)}]`:n(o);if("object"==typeof l){let e=t(l,r,u);""!==e&&i.push(e)}else Array.isArray(l)?l.forEach(((t,e)=>{let r=`${u}[${e}]`;i.push(`${n(r)}=${n(t)}`)})):i.push(`${n(u)}=${n(l)}`)}return i.join("&")},e.isAbsoluteURL=function(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)},e.isXiorError=function(t){return"XiorError"===t.name||"XiorTimeoutError"===t.name},e.joinPath=function(t,e){return e?(t.endsWith("/")?t:t+"/")+(e.startsWith("/")?e.slice(1):e):t}}},e={},function r(s){var i=e[s];if(void 0!==i)return i.exports;var n=e[s]={exports:{}};return t[s].call(n.exports,n,n.exports,r),n.exports}(272).default;var t,e}));

@@ -184,2 +184,3 @@ import { XiorError } from 'xior/utils';

throttleCache?: ICacheLike<RecordedCache>;
onThrottle?: (config: XiorRequestConfig) => void;
};

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

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

import{lru as t}from"tiny-lru";import{buildSortedURL as e,isAbsoluteURL as r,joinPath as n}from"xior/utils";function o(t,e,r,n,o,i,u){try{var l=t[i](u),a=l.value}catch(t){r(t);return}l.done?e(a):Promise.resolve(a).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise(function(n,i){var u=t.apply(e,r);function l(t){o(u,n,i,l,a,"next",t)}function a(t){o(u,n,i,l,a,"throw",t)}l(void 0)})}}function u(o={}){let{enableThrottle:u,threshold:l=1e3,throttleCache:a=t(10)}=o;return function(t){let o=(e,r)=>{let n=i(function*(){try{let n=yield t(r);return a.set(e,{timestamp:Date.now(),value:Promise.resolve(n)}),n}catch(t){throw"delete"in a?a.delete(e):a.del(e),t}})();return a.set(e,{timestamp:Date.now(),value:n}),n};return i(function*(i){let{paramsSerializer:f,threshold:s=l,enableThrottle:m=u}=i,c="GET"===i.method||i.isGet,d=typeof m;if("undefined"===d?c:"function"===d?m(i):!!m){let t=e(i.url&&r(i.url)?i.url:n(i.baseURL||"",i.url||""),{a:i.data,b:i.params},f),u=Date.now(),l=a.get(t)||{timestamp:u};if(u-l.timestamp<=s){let t=l.value;if(t)return t}return o(t,i)}return t(i)})}}export{u as default};
import{lru as t}from"tiny-lru";import{buildSortedURL as e,isAbsoluteURL as r,joinPath as n}from"xior/utils";function o(t,e,r,n,o,u,i){try{var l=t[u](i),a=l.value}catch(t){r(t);return}l.done?e(a):Promise.resolve(a).then(n,o)}function u(t){return function(){var e=this,r=arguments;return new Promise(function(n,u){var i=t.apply(e,r);function l(t){o(i,n,u,l,a,"next",t)}function a(t){o(i,n,u,l,a,"throw",t)}l(void 0)})}}function i(o={}){let{enableThrottle:i,threshold:l=1e3,throttleCache:a=t(10),onThrottle:s}=o;return function(t){let o=(e,r)=>{let n=u(function*(){try{let n=yield t(r);return a.set(e,{timestamp:Date.now(),value:Promise.resolve(n)}),n}catch(t){throw"delete"in a?a.delete(e):a.del(e),t}})();return a.set(e,{timestamp:Date.now(),value:n}),n};return u(function*(u){let{paramsSerializer:f,threshold:m=l,enableThrottle:c=i,onThrottle:d=s}=u,h="GET"===u.method||u.isGet,p=typeof c;if("undefined"===p?h:"function"===p?c(u):!!c){let t=e(u.url&&r(u.url)?u.url:n(u.baseURL||"",u.url||""),{a:u.data,b:u.params},f),i=Date.now(),l=a.get(t)||{timestamp:i},s=l.value;return s&&i-l.timestamp<=m?(null==d||d(u),s):o(t,u)}return t(u)})}}export{i 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.4/dist/xior.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xior@0.3.6/dist/xior.umd.js"></script>

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

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

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

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

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

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

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

throttleCache?: ICacheLike<RecordedCache>;
onThrottle?: (config: XiorRequestConfig) => void;
}): XiorPlugin;

@@ -569,3 +570,9 @@ ```

const http = xior.create();
http.plugins.use(throttlePlugin());
http.plugins.use(
throttlePlugin({
onThrottle(config) {
console.log(`Throttle requests ${config.method} ${config.url}`);
},
})
);

@@ -608,5 +615,5 @@ http.get('/'); // make real http request

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

@@ -624,6 +631,6 @@ <!-- Usage -->

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

@@ -683,5 +690,5 @@ <!-- Usage -->

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

@@ -699,6 +706,6 @@ <!-- Usage -->

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

@@ -761,5 +768,5 @@ <!-- Usage -->

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

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

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

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

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

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

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

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

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

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

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

@@ -1065,0 +1072,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