UNPKG

@drainpixie/pika

Version:

a cute and shiny logger

6 lines 3.77 kB
var d=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var b=(o,e)=>{for(var r in e)d(o,r,{get:e[r],enumerable:!0})},k=(o,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of N(e))!T.call(o,n)&&n!==r&&d(o,n,{get:()=>e[n],enumerable:!(t=O(e,n))||t.enumerable});return o};var C=o=>k(d({},"__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:"\u2713",INFO:"i",CROSS:"\xD7",WARNING:"!",ELLIPSIS:"\u2026",POINTER_SMALL:"\u203A"},s={RED:"\x1B[31m",BOLD:"\x1B[1m",GREY:"\x1B[0;37m",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},p=(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:p("success",l.INFO,i.TICK,s.GREEN),warn:p("warn",l.WARN,i.WARNING,s.YELLOW),error:p("error",l.ERROR,i.CROSS,s.RED,process.stderr),fatal:p("fatal",l.FATAL,i.CROSS,s.RED,process.stderr),trace:p("trace",l.TRACE,i.ELLIPSIS,s.BLUE),debug:p("debug",l.DEBUG,i.INFO,s.CYAN),info:p("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,f)=>f;let t=new Error().stack;if(!t?.length)return"anonymous";let n=t[0].getFileName(),g=t.slice(1).find(a=>a.getFileName()!==n);if(!g)return"anonymous";let u=g.getFileName();return u?(0,E.parse)(u.startsWith("file://")?(0,m.fileURLToPath)(u):u).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(` `);return`${this.#t(r,s.UNDERLINE)} ${this.#t(t.join(` `),s.GREY)}`}#h(e){return Object.entries(e).map(([r,t])=>`${r} = ${JSON.stringify(t)}`).join(", ")}#y(e,...r){let t=[...this.#u()],{label:n,colour:g,badge:u}=e;if(t.push(this.#t(`${u} `,g)),t.push(`${this.#t(n,g,s.UNDERLINE)}${" ".repeat(Math.max(0,this.#a-n.length))}`),r.length===0)return t.join(" ");let[a,...f]=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([a,...f].map(R=>String(R)).join(" ")),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