UNPKG

grab-url

Version:

📥 Generate Request to API from Browser

3 lines (2 loc) 4.04 kB
function e(e="",t={}){let{color:r,style:n="color:rgb(54, 165, 220); font-size: 10pt;",hideInProduction:o,startSpinner:l=!1,stopSpinner:i=!1}=t;const a=f();void 0===o&&(o="undefined"!=typeof window&&window?.location.hostname.includes("localhost")),"object"==typeof e&&(e=g(e)+"\n\n"+JSON.stringify(e,null,2)),Array.isArray(r)&&1==r.length&&(r=r[0]),r&&void 0!==typeof process&&(e.includes("%c")&&Array.isArray(r)?e=e.replace(/%c/g,(e,t)=>a[r[t]]||""):r&&"string"==typeof r&&(e=(a[r]||"")+e+a.reset));var b=0;return l?(global||globalThis).interval=setInterval(()=>{process.stdout.write((Array.isArray(r)?a[r[0]]:a[r]||"")+"\r"+"⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏".split("")[b=++b%10]+" "+e+a.reset)},50):i?(clearInterval((global||globalThis).interval),process.stdout.write("\r"+(e||" ")+" ".repeat(e.length+20)+"\n")):"string"==typeof n?(1==n.split(" ").length||r?n=`color: ${r||n}; font-size: 11pt;`:n.match(/^#[0-9a-fA-F]{6}$/)&&(n=`color: ${n}; font-size: 11pt;`),o?console.debug((n?"%c":"")+(e||""),n):console.log((n?"%c":"")+(e||""),n)):"object"==typeof n&&console.log(e,...n),!0}var t=/* @__PURE__ */(e=>(e.RESET="reset",e.BLACK="black",e.RED="red",e.GREEN="green",e.YELLOW="yellow",e.BLUE="blue",e.MAGENTA="magenta",e.CYAN="cyan",e.WHITE="white",e.GRAY="gray",e.BRIGHT_RED="brightRed",e.BRIGHT_GREEN="brightGreen",e.BRIGHT_YELLOW="brightYellow",e.BRIGHT_BLUE="brightBlue",e.BRIGHT_MAGENTA="brightMagenta",e.BRIGHT_CYAN="brightCyan",e.BRIGHT_WHITE="brightWhite",e.BG_RED="bgRed",e.BG_GREEN="bgGreen",e.BG_YELLOW="bgYellow",e.BG_BLUE="bgBlue",e.BG_MAGENTA="bgMagenta",e.BG_CYAN="bgCyan",e.BG_WHITE="bgWhite",e.BG_GRAY="bgGray",e.BG_BLACK="bgBlack",e.BG_BRIGHT_RED="bgBrightRed",e.BG_BRIGHT_GREEN="bgBrightGreen",e.BG_BRIGHT_YELLOW="bgBrightYellow",e.BG_BRIGHT_BLUE="bgBrightBlue",e.BG_BRIGHT_MAGENTA="bgBrightMagenta",e.BG_BRIGHT_CYAN="bgBrightCyan",e.BG_BRIGHT_WHITE="bgBrightWhite",e))(t||{});const r={reset:[0,"000000"],black:[30,"000000"],red:[31,"ff0000"],green:[32,"00ff00"],yellow:[33,"ffff00"],blue:[34,"0000ff"],magenta:[35,"ff00ff"],cyan:[36,"00ffff"],white:[37,"ffffff"],gray:[90,"808080"],brightRed:[91,"ff5555"],brightGreen:[92,"55ff55"],brightYellow:[93,"ffff55"],brightBlue:[94,"5555ff"],brightMagenta:[95,"ff55ff"],brightCyan:[96,"55ffff"],brightWhite:[97,"ffffff"],bgBlack:[40,"000000"],bgRed:[41,"ff0000"],bgGreen:[42,"00ff00"],bgYellow:[43,"ffff00"],bgBlue:[44,"0000ff"],bgMagenta:[45,"ff00ff"],bgCyan:[46,"00ffff"],bgWhite:[47,"ffffff"],bgGray:[100,"808080"],bgBrightRed:[101,"ff8888"],bgBrightGreen:[102,"88ff88"],bgBrightYellow:[103,"ffff88"],bgBrightBlue:[104,"8888ff"],bgBrightMagenta:[105,"ff88ff"],bgBrightCyan:[106,"88ffff"],bgBrightWhite:[107,"ffffff"]};function f(e="ansi"){const t={};for(const[f,[n,o]]of Object.entries(r))t[f]="html"===e?"#"+o:"["+n+"m";return t}function n(e){const t=f();return"string"==typeof e?t.yellow:"number"==typeof e?t.cyan:"boolean"==typeof e?t.magenta:"function"==typeof e?t.red:null===e?t.gray:Array.isArray(e)?t.blue:"object"==typeof e?t.green:t.white}function o(e){return"string"==typeof e?'""':"number"==typeof e?"number":"boolean"==typeof e?"bool":"function"==typeof e?"function":null===e?"null":Array.isArray(e)?e.length?"["+o(e[0])+"]":"[]":"object"==typeof e?"{...}":typeof e}function g(e,t=0,r="ansi"){const l=f(r),i=" ".repeat(t);var a="";if("object"!=typeof e||null===e){return n(e)+o(e)+l.reset}if(Array.isArray(e)){if(a=l.blue+"["+l.reset,e.length&&(a+="\n"),!e.every(t=>typeof t==typeof e[0]))return e.forEach((r,f)=>{a+=i+" "+g(r,t+1),f<e.length-1&&(a+=","),a+="\n"}),a+=i+l.blue+"]"+l.reset;a+=i+" "+g(e[0],t+1),a+=",",a+="\n"}a=l.green+"{"+l.reset;const b=Object.keys(e);return b.length&&(a+="\n"),b.forEach((r,f)=>{const s=e[r],y=n(s);a+=i+" ","object"!=typeof s||null===s||Array.isArray(s)?Array.isArray(s)?a+=y+r+l.reset+": "+g(s,t+1):a+=y+r+": "+o(s)+l.reset:a+=y+r+l.reset+": "+g(s,t+1),f<b.length-1&&(a+=","),a+="\n"}),a+=i+l.green+"}"+l.reset}export{t as ColorName,f as getColors,e as log,g as printJSONStructure}; //# sourceMappingURL=log.es.js.map