wretch
Version:
A tiny wrapper built around fetch with an intuitive syntax.
2 lines • 551 B
JavaScript
function e(e){let t=new TextEncoder().encode(e);return btoa(String.fromCharCode(...t))}const 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)},n={beforeRequest(e){return e.middlewares([t()])},wretch:{basicAuth(t,n){let r=e(`${t}:${n}`);return this.auth(`Basic ${r}`)}}};module.exports=n;
//# sourceMappingURL=basicAuth.min.cjs.map