xior
Version:
A lite http request lib based on fetch with plugins support and similar API to axios.
1 lines • 1.5 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.xiorProgress=e():t.xiorProgress=e()}(this,(function(){return function(){"use strict";var t={};return{155:function(t,e){var o=this&&this.__awaiter||function(t,e,o,n){return new(o||(o=Promise))((function(r,s){function a(t){try{c(n.next(t))}catch(t){s(t)}}function i(t){try{c(n.throw(t))}catch(t){s(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(a,i)}c((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t={}){const{progressDuration:e=5e3}=t;return function(t){return n=>o(this,void 0,void 0,(function*(){const{progressDuration:o=e,onUploadProgress:r,onDownloadProgress:s}=n;let a;if(r||s){const t=1e3;let e=0,n=0;const i=t/(o/300);a=setInterval((()=>{if(n>=99)return void clearInterval(a);e+=Math.random()*i,n=Math.floor(e/t*100);const o={total:t,loaded:e,progress:n};o.progress>=99&&(o.progress=99,o.loaded=.99*t),r&&r(Object.assign(Object.assign({},o),{upload:!0})),s&&s(Object.assign(Object.assign({},o),{download:!0}))}),300)}try{const e=yield t(n);if(a&&(clearInterval(a),a=void 0),r||s){const t={total:1e3,loaded:1e3,progress:100};r&&r(Object.assign(Object.assign({},t),{upload:!0})),s&&s(Object.assign(Object.assign({},t),{download:!0}))}return e}catch(t){throw a&&clearInterval(a),t}}))}}}}[155](0,t),t.default}()}));