xior
Version:
A lite http request lib based on fetch with plugins support and similar API to axios.
2 lines (1 loc) • 933 B
JavaScript
import{A as y,b as f,i as n,n as X,v as C,z as T}from"../chunk-C6PKHUO4.mjs";import{d as a}from"../chunk-BOVQDIMN.mjs";import{lru as L}from"tiny-lru";function g(h={}){let{enableThrottle:P,threshold:q=1e3,throttleCache:v=L(h.throttleItems||100),onThrottle:w}=h,o=v;return function(u){let I=(e,i)=>{let r=a(this,null,function*(){try{let t=yield u(i);return o.set(e,{timestamp:Date.now(),value:Promise.resolve(t)}),t}catch(t){throw"delete"in o?o.delete(e):o.del(e),t}});return o.set(e,{timestamp:Date.now(),value:r}),r};return e=>a(this,null,function*(){let{paramsSerializer:i,threshold:r=q,enableThrottle:t=P,onThrottle:l=w}=e,O=e.method===X||e.isGet,m=typeof t,c=m===f,s=n;if(c&&(s=t(e)),s===n&&(s=c||m===`${n}`?O:!!t),s){let d=C(e.url&&T(e.url)?e.url:y(e.baseURL,e.url),{a:e.data,b:e.params},i),p=Date.now(),b=o.get(d)||{timestamp:p},R=b.value;return R&&p-b.timestamp<=r?(l==null||l(e),R):I(d,e)}return u(e)})}}export{g as default};