UNPKG

wretch

Version:

A tiny wrapper built around fetch with an intuitive syntax.

3 lines (2 loc) 716 B
var global,factory;global=this,factory=function(){return()=>{const e={ref:null},r=r=>(t,o)=>{let n=0,f=0;return r(t,o).then((r=>{try{const t=r.headers.get("content-length");f=t?+t:null;const o=new TransformStream({transform(r,t){n+=r.length,f<n&&(f=n),e.ref&&e.ref(n,f),t.enqueue(r)}});return new Response(r.body.pipeThrough(o),r)}catch(e){return r}}))};return{beforeRequest:e=>e._middlewares.push(r),resolver:{progress(r){return e.ref=r,this}}}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):(global="undefined"!=typeof globalThis?globalThis:global||self).wretchProgressAddon=factory(); //# sourceMappingURL=progress.min.js.map