@vulppi/toolbelt
Version:
A collection of tools and utilities.
2 lines (1 loc) • 1.94 kB
JavaScript
;(()=>{var p=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(a,e)=>(typeof require<"u"?require:a)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var u=p("buffer"),t=p("zlib");function m(s){if(!s)return null;let a=s.trim(),e=a.match(/^Bearer\s+(.+)$/i);if(e)return{type:"bearer",token:e[1]};let i=a.match(/^Basic\s+(.+)$/i);if(i)try{let f=u.Buffer.from(i[1],"base64").toString("utf-8"),[o,r]=f.split(":");return{type:"basic",username:o,password:r}}catch{return null}return null}var n={gzip:/^(?:x-)?gzip$/i,deflate:/^deflate$/i,identity:/^identity$/i,br:/^br$/i};async function d(s,a=["identity"]){let e=s;for(let i of a)n.identity.test(i)||(n.gzip.test(i)?e=await new Promise((f,o)=>{(0,t.gunzip)(e,(r,c)=>{if(r)return o(r);f(c)})}):n.deflate.test(i)?e=await new Promise((f,o)=>{(0,t.inflate)(e,(r,c)=>{if(r)return o(r);f(c)})}):n.br.test(i)&&(e=await new Promise((f,o)=>{(0,t.brotliDecompress)(e,(r,c)=>{if(r)return o(r);f(c)})})));return e}async function b(s,a=["identity"]){let e=s;for(let i of a.toReversed())n.identity.test(i)||(n.gzip.test(i)?e=await new Promise((f,o)=>{(0,t.gzip)(e,(r,c)=>{if(r)return o(r);f(c)})}):n.deflate.test(i)?e=await new Promise((f,o)=>{(0,t.deflate)(e,(r,c)=>{if(r)return o(r);f(c)})}):n.br.test(i)&&(e=await new Promise((f,o)=>{(0,t.brotliCompress)(e,(r,c)=>{if(r)return o(r);f(c)})})));return e}function y(s,a=["identity"]){let e=s;for(let i of a)n.identity.test(i)||(n.gzip.test(i)?e=e.pipe((0,t.createGunzip)()):n.deflate.test(i)?e=e.pipe((0,t.createInflate)()):n.br.test(i)&&(e=e.pipe((0,t.createBrotliDecompress)())));return e}function g(s,a=["identity"]){let e=s;for(let i of a.toReversed())n.identity.test(i)||(n.gzip.test(i)?e=e.pipe((0,t.createGzip)()):n.deflate.test(i)?e=e.pipe((0,t.createDeflate)()):n.br.test(i)&&(e=e.pipe((0,t.createBrotliCompress)())));return e}})();