UNPKG

xior

Version:

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

2 lines (1 loc) 742 B
import{a as n,b as a,d}from"../chunk-BOVQDIMN.mjs";function c(g={}){let{progressDuration:p=5*1e3}=g;return function(f){return u=>d(this,null,function*(){let{progressDuration:P=p,onUploadProgress:e,onDownloadProgress:o}=u,r;if(e||o){let t=0,l=0,v=1e3/(P/300);r=setInterval(()=>{if(l>=99){clearInterval(r);return}t+=Math.random()*v,l=Math.floor(t/1e3*100);let s={total:1e3,loaded:t,progress:l};s.progress>=99&&(s.progress=99,s.loaded=.99*1e3),e&&e(a(n({},s),{upload:!0})),o&&o(a(n({},s),{download:!0}))},300)}try{let i=yield f(u);if(r&&(clearInterval(r),r=void 0),e||o){let t={total:1e3,loaded:1e3,progress:100};e&&e(a(n({},t),{upload:!0})),o&&o(a(n({},t),{download:!0}))}return i}catch(i){throw r&&clearInterval(r),i}})}}export{c as default};