@drainpixie/pika
Version:
a cute and shiny logger
6 lines • 3.81 kB
JavaScript
var f=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var b=(o,e)=>{for(var r in e)f(o,r,{get:e[r],enumerable:!0})},k=(o,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of O(e))!T.call(o,n)&&n!==r&&f(o,n,{get:()=>e[n],enumerable:!(t=N(e,n))||t.enumerable});return o};var C=o=>k(f({},"__esModule",{value:!0}),o);var x={};b(x,{Colour:()=>s,Figure:()=>i,Level:()=>l,Pika:()=>y,colour:()=>h,pika:()=>S,shouldUseColors:()=>L});module.exports=C(x);var E=require("path");var i={TICK:"\u2714",INFO:"\u2139",CROSS:"\u2716",WARNING:"\u26A0",ELLIPSIS:"\u2026",POINTER_SMALL:"\u203A"},s={RED:"\x1B[31m",BOLD:"\x1B[1m",GREY:"\x1B[90m",BLUE:"\x1B[34m",CYAN:"\x1B[36m",RESET:"\x1B[0m",GREEN:"\x1B[32m",YELLOW:"\x1B[33m",MAGENTA:"\x1B[35m",UNDERLINE:"\x1B[4m"},l={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,FATAL:5},u=(o,e,r,t,n=process.stdout)=>Object.freeze({label:o,level:e,badge:r,colour:t,stream:n}),h=(o,...e)=>`${e.join("")}${o}${s.RESET}`;function L(){return process.env.NO_COLOR||process.env.NODE_DISABLE_COLORS?!1:process.env.FORCE_COLOR?!0:process.stdout.isTTY??!1}var c={success:u("success",l.INFO,i.TICK,s.GREEN),warn:u("warn",l.WARN,i.WARNING,s.YELLOW),error:u("error",l.ERROR,i.CROSS,s.RED,process.stderr),fatal:u("fatal",l.FATAL,i.CROSS,s.RED,process.stderr),trace:u("trace",l.TRACE,i.ELLIPSIS,s.BLUE),debug:u("debug",l.DEBUG,i.INFO,s.CYAN),info:u("info",l.INFO,i.INFO,s.BLUE)};var m=require("url"),y=class o{#o;#s;#a;#n;#r;constructor(e={}){this.#o=e.scope??this.#i(),this.#s=e.level??l.INFO,this.#a=this.#l(),this.#r=Object.freeze([...e.secrets??[]]),this.#n=e.useColors??L()}scope(e){return new o({...this.options,scope:e})}level(e){return new o({...this.options,level:e})}secrets(...e){return new o({...this.options,secrets:[...this.#r,...e]})}get options(){return{scope:this.#o,level:this.#s,secrets:this.#r,useColors:this.#n}}#i(){let e=Error.prepareStackTrace;try{Error.prepareStackTrace=(a,d)=>d;let t=new Error().stack;if(!t?.length)return"anonymous";let n=t[0].getFileName(),p=t.slice(1).find(a=>a.getFileName()!==n);if(!p)return"anonymous";let g=p.getFileName();return g?(0,E.parse)(g.startsWith("file://")?(0,m.fileURLToPath)(g):g).name:"anonymous"}catch{return"anonymous"}finally{Error.prepareStackTrace=e}}#l(){return Math.max(...Object.values(c).map(e=>e.label?.length??0).filter(e=>e>0),0)}#c(e){return this.#r.length===0?e:this.#r.reduce((r,t)=>r.replaceAll(t,"[REDACTED]"),e)}#p(){return`[${this.#o}]`}#u(){let e=[this.#p()];return e.length>0?(e.push(i.POINTER_SMALL),e.map(r=>h(r,s.GREY))):e}#t(e,...r){return this.#n?h(e,...r):e}#g(e){if(!e.stack)return e.message;let[r,...t]=e.stack.split(`
`),n=this.#t(r,s.UNDERLINE),p=this.#t(t.join(`
`),s.GREY);return`${n}
${p}`}#h(e){return Object.entries(e).map(([r,t])=>`${r} = ${JSON.stringify(t)}`).join(", ")}#y(e,...r){let t=[...this.#u()],{label:n,colour:p,badge:g}=e;if(t.push(this.#t(`${g} `,p)),t.push(`${this.#t(n,p,s.UNDERLINE)}${" ".repeat(Math.max(0,this.#a-n.length))}`),r.length===0)return t.join(" ");let[a,...d]=r;return a instanceof Error?t.push(this.#g(a)):typeof a=="object"&&a!==null&&!(a instanceof Date)&&!(a instanceof RegExp)?t.push(this.#h(a)):t.push(this.#t([a,...d].map(R=>String(R)).join(" "),s.GREY)),t.join(" ")}#e(e,...r){e.level<this.#s||e.stream.write(`${this.#c(this.#y(e,...r))}
`)}clone(e={}){return new o({...this.options,...e})}success=(...e)=>this.#e(c.success,...e);error=(...e)=>this.#e(c.error,...e);fatal=(...e)=>this.#e(c.fatal,...e);trace=(...e)=>this.#e(c.trace,...e);debug=(...e)=>this.#e(c.debug,...e);warn=(...e)=>this.#e(c.warn,...e);info=(...e)=>this.#e(c.info,...e)},S=(o={})=>new y(o);0&&(module.exports={Colour,Figure,Level,Pika,colour,pika,shouldUseColors});
//# sourceMappingURL=index.cjs.map