UNPKG

wretch

Version:

A tiny wrapper built around fetch with an intuitive syntax.

2 lines 756 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.wretchBasicAuthAddon=t())})(this,function(){function e(e){let t=new TextEncoder().encode(e);return btoa(String.fromCharCode(...t))}let t=()=>t=>(n,r)=>{let i;try{i=new URL(n)}catch{i=null}if(i?.username||i?.password){let t=e(`${decodeURIComponent(i.username)}:${decodeURIComponent(i.password)}`);r.headers={...r.headers,Authorization:`Basic ${t}`},i.username=``,i.password=``,n=i.toString()}return t(n,r)};return{beforeRequest(e){return e.middlewares([t()])},wretch:{basicAuth(t,n){let r=e(`${t}:${n}`);return this.auth(`Basic ${r}`)}}}}); //# sourceMappingURL=basicAuth.min.js.map