UNPKG

wretch

Version:

A tiny wrapper built around fetch with an intuitive syntax.

2 lines 821 B
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.wretchAbortAddon=t())})(this,function(){return()=>({beforeRequest(e,t,n){let r=new AbortController;t.signal||=r.signal;let i={ref:null,clear(){i.ref&&=(clearTimeout(i.ref),null)}};return n.abort={timeout:i,fetchController:r},e},wretch:{signal(e){return{...this,_options:{...this._options,signal:e.signal}}}},resolver:{setTimeout(e,t={}){let n=t.controller??this._sharedState.abort.fetchController,{timeout:r}=this._sharedState.abort;return r.clear(),r.ref=setTimeout(()=>n.abort(),e),this},controller(){return[this._sharedState.abort.fetchController,this]},onAbort(e){return this.error(`AbortError`,e)}}})}); //# sourceMappingURL=abort.min.js.map