get-it
Version:
Generic HTTP request library for node, browsers and workers
2 lines (1 loc) • 10.2 kB
JavaScript
import e from"tty";import t from"util";import n from"through2";var r,s,o,c,i,a={exports:{}},u={exports:{}};function l(){return c?o:(c=1,o=function(e){function t(e){let r,s,o,c=null;function i(...e){if(!i.enabled)return;const n=i,s=Number(/* @__PURE__ */new Date),o=s-(r||s);n.diff=o,n.prev=r,n.curr=s,r=s,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let c=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(r,s)=>{if("%%"===r)return"%";c++;const o=t.formatters[s];if("function"==typeof o){const t=e[c];r=o.call(n,t),e.splice(c,1),c--}return r}),t.formatArgs.call(n,e),(n.log||t.log).apply(n,e)}return i.namespace=e,i.useColors=t.useColors(),i.color=t.selectColor(e),i.extend=n,i.destroy=t.destroy,Object.defineProperty(i,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==c?c:(s!==t.namespaces&&(s=t.namespaces,o=t.enabled(e)),o),set:e=>{c=e}}),"function"==typeof t.init&&t.init(i),i}function n(e,n){const r=t(this.namespace+(typeof n>"u"?":":n)+e);return r.log=this.log,r}function o(e,t){let n=0,r=0,s=-1,o=0;for(;n<e.length;)if(r<t.length&&(t[r]===e[n]||"*"===t[r]))"*"===t[r]?(s=r,o=n,r++):(n++,r++);else{if(-1===s)return!1;r=s+1,o++,n=o}for(;r<t.length&&"*"===t[r];)r++;return r===t.length}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){const e=[...t.names,...t.skips.map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){t.save(e),t.namespaces=e,t.names=[],t.skips=[];const n=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(const e of n)"-"===e[0]?t.skips.push(e.slice(1)):t.names.push(e)},t.enabled=function(e){for(const n of t.skips)if(o(e,n))return!1;for(const n of t.names)if(o(e,n))return!0;return!1},t.humanize=function(){if(s)return r;s=1;var e=1e3,t=60*e,n=60*t,o=24*n,c=7*o;function i(e,t,n,r){var s=t>=1.5*n;return Math.round(e/n)+" "+r+(s?"s":"")}return r=function(r,s){s=s||{};var a,u,l=typeof r;if("string"===l&&r.length>0)return function(r){if(!((r=String(r)).length>100)){var s=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(r);if(s){var i=parseFloat(s[1]);switch((s[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*i;case"weeks":case"week":case"w":return i*c;case"days":case"day":case"d":return i*o;case"hours":case"hour":case"hrs":case"hr":case"h":return i*n;case"minutes":case"minute":case"mins":case"min":case"m":return i*t;case"seconds":case"second":case"secs":case"sec":case"s":return i*e;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return i;default:return}}}}(r);if("number"===l&&isFinite(r))return s.long?(a=r,(u=Math.abs(a))>=o?i(a,u,o,"day"):u>=n?i(a,u,n,"hour"):u>=t?i(a,u,t,"minute"):u>=e?i(a,u,e,"second"):a+" ms"):function(r){var s=Math.abs(r);return s>=o?Math.round(r/o)+"d":s>=n?Math.round(r/n)+"h":s>=t?Math.round(r/t)+"m":s>=e?Math.round(r/e)+"s":r+"ms"}(r);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(r))}}(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(n=>{t[n]=e[n]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return t.colors[Math.abs(n)%t.colors.length]},t.enable(t.load()),t})}var p,f,d,C,g={exports:{}};function h(){return C||(C=1,typeof process>"u"||"renderer"===process.type||!0===process.browser||process.__nwjs?a.exports=(i||(i=1,function(e,t){t.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;const n="color: "+this.color;t.splice(1,0,n,"color: inherit");let r=0,s=0;t[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(r++,"%c"===e&&(s=r))}),t.splice(s,0,n)},t.save=function(e){try{e?t.storage.setItem("debug",e):t.storage.removeItem("debug")}catch{}},t.load=function(){let e;try{e=t.storage.getItem("debug")||t.storage.getItem("DEBUG")}catch{}return!e&&typeof process<"u"&&"env"in process&&(e=process.env.DEBUG),e},t.useColors=function(){if(typeof window<"u"&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},t.storage=function(){try{return localStorage}catch{}}(),t.destroy=/* @__PURE__ */(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),t.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],t.log=console.debug||console.log||(()=>{}),e.exports=l()(t);const{formatters:n}=e.exports;n.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}(u,u.exports)),u.exports):a.exports=(d||(d=1,function(n,r){const s=e,o=t;r.init=function(e){e.inspectOpts={};const t=Object.keys(r.inspectOpts);for(let n=0;n<t.length;n++)e.inspectOpts[t[n]]=r.inspectOpts[t[n]]},r.log=function(...e){return process.stderr.write(o.formatWithOptions(r.inspectOpts,...e)+"\n")},r.formatArgs=function(e){const{namespace:t,useColors:s}=this;if(s){const r=this.color,s="[3"+(r<8?r:"8;5;"+r),o=` ${s};1m${t} [0m`;e[0]=o+e[0].split("\n").join("\n"+o),e.push(s+"m+"+n.exports.humanize(this.diff)+"[0m")}else e[0]=(r.inspectOpts.hideDate?"":/* @__PURE__ */(new Date).toISOString()+" ")+t+" "+e[0]},r.save=function(e){e?process.env.DEBUG=e:delete process.env.DEBUG},r.load=function(){return process.env.DEBUG},r.useColors=function(){return"colors"in r.inspectOpts?!!r.inspectOpts.colors:s.isatty(process.stderr.fd)},r.destroy=o.deprecate(()=>{},"Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."),r.colors=[6,2,3,4,5,1];try{const e=function(){if(f)return p;f=1;const e=function(){const e=/(Chrome|Chromium)\/(?<chromeVersion>\d+)\./.exec(navigator.userAgent);if(e)return Number.parseInt(e.groups.chromeVersion,10)}()>=69&&{level:1,hasBasic:!0,has256:!1,has16m:!1};return p={stdout:e,stderr:e}}();e&&(e.stderr||e).level>=2&&(r.colors=[20,21,26,27,32,33,38,39,40,41,42,43,44,45,56,57,62,63,68,69,74,75,76,77,78,79,80,81,92,93,98,99,112,113,128,129,134,135,148,149,160,161,162,163,164,165,166,167,168,169,170,171,172,173,178,179,184,185,196,197,198,199,200,201,202,203,204,205,206,207,208,209,214,215,220,221])}catch{}r.inspectOpts=Object.keys(process.env).filter(e=>/^debug_/i.test(e)).reduce((e,t)=>{const n=t.substring(6).toLowerCase().replace(/_([a-z])/g,(e,t)=>t.toUpperCase());let r=process.env[t];return r=!!/^(yes|on|true|enabled)$/i.test(r)||!/^(no|off|false|disabled)$/i.test(r)&&("null"===r?null:Number(r)),e[n]=r,e},{}),n.exports=l()(r);const{formatters:c}=n.exports;c.o=function(e){return this.inspectOpts.colors=this.useColors,o.inspect(e,this.inspectOpts).split("\n").map(e=>e.trim()).join(" ")},c.O=function(e){return this.inspectOpts.colors=this.useColors,o.inspect(e,this.inspectOpts)}}(g,g.exports)),g.exports)),a.exports}let m=1;const F=65535;let y=null;const b=function(){m=m+1&F};function w(e){let t=e.length||0,r=0,s=Date.now()+e.time,o=0;const c=function(){y||(y=setInterval(b,250),y.unref&&y.unref());const e=[0];let t=1,n=m-1&F;return{getSpeed:function(r){let s=m-n&F;for(s>20&&(s=20),n=m;s--;)20===t&&(t=0),e[t]=e[0===t?19:t-1],t++;r&&(e[t-1]+=r);const o=e[t-1],c=e.length<20?0:e[20===t?0:t];return e.length<4?o:4*(o-c)/e.length},clear:function(){y&&(clearInterval(y),y=null)}}}(),i=Date.now(),a={percentage:0,transferred:r,length:t,remaining:t,eta:0,runtime:0,speed:0,delta:0},u=function(n){a.delta=o,a.percentage=n?100:t?r/t*100:0,a.speed=c.getSpeed(o),a.eta=Math.round(a.remaining/a.speed),a.runtime=Math.floor((Date.now()-i)/1e3),s=Date.now()+e.time,o=0,l.emit("progress",a)},l=n({},function(e,n,c){const i=e.length;r+=i,o+=i,a.transferred=r,a.remaining=t>=r?t-r:0,Date.now()>=s&&u(!1),c(null,e)},function(e){u(!0),c.clear(),e()}),p=function(e){t=e,a.length=t,a.remaining=t-a.transferred,l.emit("length",t)};return l.on("pipe",function(e){if(!(t>0)){if(e.readable&&!("writable"in e)&&"headers"in e&&"object"==typeof(n=e.headers)&&null!==n&&!Array.isArray(n)){const t="string"==typeof e.headers["content-length"]?parseInt(e.headers["content-length"],10):0;return p(t)}if("length"in e&&"number"==typeof e.length)return p(e.length);e.on("response",function(e){if(e&&e.headers&&"gzip"!==e.headers["content-encoding"]&&e.headers["content-length"])return p(parseInt(e.headers["content-length"]))})}var n}),l.progress=function(){return a.speed=c.getSpeed(0),a.eta=Math.round(a.remaining/a.speed),a},l}class v extends Error{request;code;constructor(e,t){super(e.message),this.request=t,this.code=e.code}}export{v as N,w as p,h as r};//# sourceMappingURL=node-request-error.js.map