Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

logestic

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logestic - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

2

dist/index.js
// @bun
import U0 from"elysia";var a=function(){const $=new Map;for(let[K,W]of Object.entries(U)){for(let[O,z]of Object.entries(W))U[O]={open:`\x1B[${z[0]}m`,close:`\x1B[${z[1]}m`},W[O]=U[O],$.set(z[0],z[1]);Object.defineProperty(U,K,{value:W,enumerable:!1})}return Object.defineProperty(U,"codes",{value:$,enumerable:!1}),U.color.close="\x1B[39m",U.bgColor.close="\x1B[49m",U.color.ansi=A(),U.color.ansi256=F(),U.color.ansi16m=T(),U.bgColor.ansi=A(10),U.bgColor.ansi256=F(10),U.bgColor.ansi16m=T(10),Object.defineProperties(U,{rgbToAnsi256:{value(K,W,O){if(K===W&&W===O){if(K<8)return 16;if(K>248)return 231;return Math.round((K-8)/247*24)+232}return 16+36*Math.round(K/255*5)+6*Math.round(W/255*5)+Math.round(O/255*5)},enumerable:!1},hexToRgb:{value(K){const W=/[a-f\d]{6}|[a-f\d]{3}/i.exec(K.toString(16));if(!W)return[0,0,0];let[O]=W;if(O.length===3)O=[...O].map((H)=>H+H).join("");const z=Number.parseInt(O,16);return[z>>16&255,z>>8&255,z&255]},enumerable:!1},hexToAnsi256:{value:(K)=>U.rgbToAnsi256(...U.hexToRgb(K)),enumerable:!1},ansi256ToAnsi:{value(K){if(K<8)return 30+K;if(K<16)return 90+(K-8);let W,O,z;if(K>=232)W=((K-232)*10+8)/255,O=W,z=W;else{K-=16;const Z=K%36;W=Math.floor(K/36)/5,O=Math.floor(Z/6)/5,z=Z%6/5}const H=Math.max(W,O,z)*2;if(H===0)return 30;let J=30+(Math.round(z)<<2|Math.round(O)<<1|Math.round(W));if(H===2)J+=60;return J},enumerable:!1},rgbToAnsi:{value:(K,W,O)=>U.ansi256ToAnsi(U.rgbToAnsi256(K,W,O)),enumerable:!1},hexToAnsi:{value:(K)=>U.ansi256ToAnsi(U.hexToAnsi256(K)),enumerable:!1}}),U};var A=($=0)=>(K)=>`\x1B[${K+$}m`,F=($=0)=>(K)=>`\x1B[${38+$};5;${K}m`,T=($=0)=>(K,W,O)=>`\x1B[${38+$};2;${K};${W};${O}m`,U={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},j0=Object.keys(U.modifier),i=Object.keys(U.color),n=Object.keys(U.bgColor),B0=[...i,...n],l=a(),G=l;import q from"process";import o from"os";import S from"tty";var B=function($,K=globalThis.Deno?globalThis.Deno.args:q.argv){const W=$.startsWith("-")?"":$.length===1?"-":"--",O=K.indexOf(W+$),z=K.indexOf("--");return O!==-1&&(z===-1||O<z)},r=function(){if("FORCE_COLOR"in X){if(X.FORCE_COLOR==="true")return 1;if(X.FORCE_COLOR==="false")return 0;return X.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(X.FORCE_COLOR,10),3)}},s=function($){if($===0)return!1;return{level:$,hasBasic:!0,has256:$>=2,has16m:$>=3}},t=function($,{streamIsTTY:K,sniffFlags:W=!0}={}){const O=r();if(O!==void 0)I=O;const z=W?I:O;if(z===0)return 0;if(W){if(B("color=16m")||B("color=full")||B("color=truecolor"))return 3;if(B("color=256"))return 2}if("TF_BUILD"in X&&"AGENT_NAME"in X)return 1;if($&&!K&&z===void 0)return 0;const H=z||0;if(X.TERM==="dumb")return H;if(q.platform==="win32"){const J=o.release().split(".");if(Number(J[0])>=10&&Number(J[2])>=10586)return Number(J[2])>=14931?3:2;return 1}if("CI"in X){if("GITHUB_ACTIONS"in X||"GITEA_ACTIONS"in X)return 3;if(["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some((J)=>(J in X))||X.CI_NAME==="codeship")return 1;return H}if("TEAMCITY_VERSION"in X)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(X.TEAMCITY_VERSION)?1:0;if(X.COLORTERM==="truecolor")return 3;if(X.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in X){const J=Number.parseInt((X.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(X.TERM_PROGRAM){case"iTerm.app":return J>=3?3:2;case"Apple_Terminal":return 2}}if(/-256(color)?$/i.test(X.TERM))return 2;if(/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(X.TERM))return 1;if("COLORTERM"in X)return 1;return H};function k($,K={}){const W=t($,{streamIsTTY:$&&$.isTTY,...K});return s(W)}var{env:X}=q,I;if(B("no-color")||B("no-colors")||B("color=false")||B("color=never"))I=0;else if(B("color")||B("colors")||B("color=true")||B("color=always"))I=1;var e={stdout:k({isTTY:S.isatty(1)}),stderr:k({isTTY:S.isatty(2)})},b=e;function _($,K,W){let O=$.indexOf(K);if(O===-1)return $;const z=K.length;let H=0,J="";do J+=$.slice(H,O)+K+W,H=O+z,O=$.indexOf(K,H);while(O!==-1);return J+=$.slice(H),J}function C($,K,W,O){let z=0,H="";do{const J=$[O-1]==="\r";H+=$.slice(z,J?O-1:O)+K+(J?"\r\n":"\n")+W,z=O+1,O=$.indexOf("\n",z)}while(O!==-1);return H+=$.slice(z),H}var M=function($){return K0($)};var{stdout:x,stderr:v}=b,R=Symbol("GENERATOR"),P=Symbol("STYLER"),N=Symbol("IS_EMPTY"),f=["ansi","ansi","ansi256","ansi16m"],w=Object.create(null),$0=($,K={})=>{if(K.level&&!(Number.isInteger(K.level)&&K.level>=0&&K.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");const W=x?x.level:0;$.level=K.level===void 0?W:K.level};var K0=($)=>{const K=(...W)=>W.join(" ");return $0(K,$),Object.setPrototypeOf(K,M.prototype),K};Object.setPrototypeOf(M.prototype,Function.prototype);for(let[$,K]of Object.entries(G))w[$]={get(){const W=L(this,D(K.open,K.close,this[P]),this[N]);return Object.defineProperty(this,$,{value:W}),W}};w.visible={get(){const $=L(this,this[P],!0);return Object.defineProperty(this,"visible",{value:$}),$}};var E=($,K,W,...O)=>{if($==="rgb"){if(K==="ansi16m")return G[W].ansi16m(...O);if(K==="ansi256")return G[W].ansi256(G.rgbToAnsi256(...O));return G[W].ansi(G.rgbToAnsi(...O))}if($==="hex")return E("rgb",K,W,...G.hexToRgb(...O));return G[W][$](...O)},O0=["rgb","hex","ansi256"];for(let $ of O0){w[$]={get(){const{level:W}=this;return function(...O){const z=D(E($,f[W],"color",...O),G.color.close,this[P]);return L(this,z,this[N])}}};const K="bg"+$[0].toUpperCase()+$.slice(1);w[K]={get(){const{level:W}=this;return function(...O){const z=D(E($,f[W],"bgColor",...O),G.bgColor.close,this[P]);return L(this,z,this[N])}}}}var W0=Object.defineProperties(()=>{},{...w,level:{enumerable:!0,get(){return this[R].level},set($){this[R].level=$}}}),D=($,K,W)=>{let O,z;if(W===void 0)O=$,z=K;else O=W.openAll+$,z=K+W.closeAll;return{open:$,close:K,openAll:O,closeAll:z,parent:W}},L=($,K,W)=>{const O=(...z)=>z0(O,z.length===1?""+z[0]:z.join(" "));return Object.setPrototypeOf(O,W0),O[R]=$,O[P]=K,O[N]=W,O},z0=($,K)=>{if($.level<=0||!K)return $[N]?"":K;let W=$[P];if(W===void 0)return K;const{openAll:O,closeAll:z}=W;if(K.includes("\x1B"))while(W!==void 0)K=_(K,W.close,W.open),W=W.parent;const H=K.indexOf("\n");if(H!==-1)K=C(K,z,O,H);return O+K+z};Object.defineProperties(M.prototype,w);var H0=M(),q0=M({level:v?v.level:0});var Q=H0;import{StatusMap as J0} from"elysia";function y($){return $.replace(/\u001b\[\d*m/g,"").trimStart()}var h=($,K,W)=>{const{request:O,path:z,body:H,query:J,set:Z}=$;let j={};for(let d in K)switch(d){case"ip":j.ip=O.headers.get("x-forwarded-for")||"<ip?>";break;case"method":j.method=O.method;break;case"path":j.path=z;break;case"body":j.body=H;break;case"query":j.query=J;break;case"time":j.time=new Date;break;case"contentLength":j.contentLength=Number(O.headers.get("content-length"));break;case"status":if(!Z.status)break;j.status=typeof Z.status==="number"?Z.status:J0[Z.status];break;case"referer":j.referer=O.headers.get("referer")||"<referer?>";break;case"userAgent":j.userAgent=O.headers.get("user-agent")||"<user-agent?>";break;case"duration":const g=process.hrtime.bigint();j.duration=(g-W)/1000n;break}return j},V=($,K)=>{let W=Q.bgBlack;switch($){case"http":W=K[$]&&Q.hex(K[$])||Q.bgBlue;break;case"info":W=K[$]&&Q.hex(K[$])||Q.bgGreen;break;case"warn":W=K[$]&&Q.hex(K[$])||Q.bgYellow;break;case"debug":W=K[$]&&Q.hex(K[$])||Q.bgCyan;break;case"error":W=K[$]&&Q.hex(K[$])||Q.bgRed;break}const O=` ${$.toUpperCase()} `;return W?.(O)??O};var m=($)=>new Y($).use(["time","method","path","status"]).format({onSuccess({time:K,method:W,path:O,status:z}){const H=Q.gray(`${K.toISOString()}`),J=Q.cyan(`${W} ${O}`);let Z=Q.white;if(200<=z&&z<300)Z=Q.green;if(400<=z&&z<500)Z=Q.yellow;if(500<=z)Z=Q.red;return`[${H}] ${J} ${Z(z)}`},onFailure({request:K,error:W,code:O,datetime:z}){const H=Q.gray(`${z.toISOString()}`),J=Q.red(`${K.method} ${K.url} ${W.message} ${O}`);return`[${H}] ${J}`}});var u=($)=>{const K=$.getFullYear(),W=$.getMonth()+1,O=$.getDate(),z=$.getHours(),H=$.getMinutes(),J=$.getSeconds();return`${O}/${W}/${K} ${z}:${H}:${J}`},Q0={showLevel:!0},p=($)=>new Y({...Q0,...$}).use(["time","method","path","duration"]).format({onSuccess({time:K,method:W,path:O,duration:z}){const H=Q.gray(u(K)),J=Q.cyan(`${W} ${O}`);return`${H} ${J} ${z}\u03BCs`},onFailure({request:K,datetime:W}){const O=u(W);return Q.red(`${O} ${K.method} ${K.url}`)}});var c=($)=>{switch($){case"common":return m;case"fancy":return p}};import X0 from"fs";var c0=Q;class Y{requestedAttrs;dest;showLevel;logLevelColour;httpLogging;explicitLogging;constructor($={}){this.requestedAttrs=[],this.showLevel=$.showLevel||!1,this.logLevelColour=$.logLevelColour||{},this.httpLogging=$.httpLogging||!0,this.explicitLogging=$.explicitLogging||!0,this.setDest($.dest||Bun.stdout)}setDest($){if($===Bun.stdin)throw new Error("Cannot log to stdin. Please provide a writable destination.");if($===Bun.stdout||$===Bun.stderr){this.dest=$;return}this.createFileIfNotExists($).then((K)=>this.dest=K).catch((K)=>{throw K})}async createFileIfNotExists($){if(!await $.exists())Bun.write($,"");return $}use($){if(Array.isArray($)){for(let K of $)this._use(K);return this}return this._use($),this}_use($){this.requestedAttrs.push($)}static preset($,K={}){return c($)(K)}build(){return new U0({name:"logestic"}).decorate("logestic",this)}format($){return this.build().state("logestic_timeStart",0n).onRequest(({store:K})=>{K.logestic_timeStart=process.hrtime.bigint()}).onResponse({as:"global"},(K)=>{if(!this.httpLogging)return;const{store:{logestic_timeStart:W}}=K;let O=h(K,this.requestedAttrs,W),z=$.onSuccess(O);if(this.showLevel)z=`${V("http",this.logLevelColour)} ${z}`;this.log(z)}).onError({as:"global"},({request:K,error:W,code:O})=>{let z=new Date,H=$.onFailure({request:K,error:W,code:O,datetime:z});if(this.showLevel)H=`${V("error",this.logLevelColour)} ${H}`;this.log(H)})}async log($){const K=`${$}\n`;if(!this.dest.name||!this.dest.name.length){Bun.write(this.dest,K);return}const W=y(K);X0.appendFile(this.dest.name,W,(O)=>{if(O)throw O})}info($){if(!this.explicitLogging)return;let K=$;if(this.showLevel)K=`${V("info",this.logLevelColour)} ${$}`;this.log(K)}warn($){if(!this.explicitLogging)return;let K=$;if(this.showLevel)K=`${V("warn",this.logLevelColour)} ${$}`;this.log(K)}debug($){if(!this.explicitLogging)return;let K=$;if(this.showLevel)K=`${V("debug",this.logLevelColour)} ${$}`;this.log(K)}error($){if(!this.explicitLogging)return;let K=$;if(this.showLevel)K=`${V("error",this.logLevelColour)} ${$}`;this.log(K)}}export{c0 as chalk,Y as Logestic};
import U0 from"elysia";var a=function(){const $=new Map;for(let[K,W]of Object.entries(U)){for(let[O,z]of Object.entries(W))U[O]={open:`\x1B[${z[0]}m`,close:`\x1B[${z[1]}m`},W[O]=U[O],$.set(z[0],z[1]);Object.defineProperty(U,K,{value:W,enumerable:!1})}return Object.defineProperty(U,"codes",{value:$,enumerable:!1}),U.color.close="\x1B[39m",U.bgColor.close="\x1B[49m",U.color.ansi=F(),U.color.ansi256=T(),U.color.ansi16m=A(),U.bgColor.ansi=F(10),U.bgColor.ansi256=T(10),U.bgColor.ansi16m=A(10),Object.defineProperties(U,{rgbToAnsi256:{value(K,W,O){if(K===W&&W===O){if(K<8)return 16;if(K>248)return 231;return Math.round((K-8)/247*24)+232}return 16+36*Math.round(K/255*5)+6*Math.round(W/255*5)+Math.round(O/255*5)},enumerable:!1},hexToRgb:{value(K){const W=/[a-f\d]{6}|[a-f\d]{3}/i.exec(K.toString(16));if(!W)return[0,0,0];let[O]=W;if(O.length===3)O=[...O].map((H)=>H+H).join("");const z=Number.parseInt(O,16);return[z>>16&255,z>>8&255,z&255]},enumerable:!1},hexToAnsi256:{value:(K)=>U.rgbToAnsi256(...U.hexToRgb(K)),enumerable:!1},ansi256ToAnsi:{value(K){if(K<8)return 30+K;if(K<16)return 90+(K-8);let W,O,z;if(K>=232)W=((K-232)*10+8)/255,O=W,z=W;else{K-=16;const Z=K%36;W=Math.floor(K/36)/5,O=Math.floor(Z/6)/5,z=Z%6/5}const H=Math.max(W,O,z)*2;if(H===0)return 30;let J=30+(Math.round(z)<<2|Math.round(O)<<1|Math.round(W));if(H===2)J+=60;return J},enumerable:!1},rgbToAnsi:{value:(K,W,O)=>U.ansi256ToAnsi(U.rgbToAnsi256(K,W,O)),enumerable:!1},hexToAnsi:{value:(K)=>U.ansi256ToAnsi(U.hexToAnsi256(K)),enumerable:!1}}),U};var F=($=0)=>(K)=>`\x1B[${K+$}m`,T=($=0)=>(K)=>`\x1B[${38+$};5;${K}m`,A=($=0)=>(K,W,O)=>`\x1B[${38+$};2;${K};${W};${O}m`,U={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},j0=Object.keys(U.modifier),i=Object.keys(U.color),n=Object.keys(U.bgColor),B0=[...i,...n],l=a(),G=l;import R from"process";import o from"os";import b from"tty";var B=function($,K=globalThis.Deno?globalThis.Deno.args:R.argv){const W=$.startsWith("-")?"":$.length===1?"-":"--",O=K.indexOf(W+$),z=K.indexOf("--");return O!==-1&&(z===-1||O<z)},r=function(){if("FORCE_COLOR"in X){if(X.FORCE_COLOR==="true")return 1;if(X.FORCE_COLOR==="false")return 0;return X.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(X.FORCE_COLOR,10),3)}},s=function($){if($===0)return!1;return{level:$,hasBasic:!0,has256:$>=2,has16m:$>=3}},t=function($,{streamIsTTY:K,sniffFlags:W=!0}={}){const O=r();if(O!==void 0)I=O;const z=W?I:O;if(z===0)return 0;if(W){if(B("color=16m")||B("color=full")||B("color=truecolor"))return 3;if(B("color=256"))return 2}if("TF_BUILD"in X&&"AGENT_NAME"in X)return 1;if($&&!K&&z===void 0)return 0;const H=z||0;if(X.TERM==="dumb")return H;if(R.platform==="win32"){const J=o.release().split(".");if(Number(J[0])>=10&&Number(J[2])>=10586)return Number(J[2])>=14931?3:2;return 1}if("CI"in X){if("GITHUB_ACTIONS"in X||"GITEA_ACTIONS"in X)return 3;if(["TRAVIS","CIRCLECI","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some((J)=>(J in X))||X.CI_NAME==="codeship")return 1;return H}if("TEAMCITY_VERSION"in X)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(X.TEAMCITY_VERSION)?1:0;if(X.COLORTERM==="truecolor")return 3;if(X.TERM==="xterm-kitty")return 3;if("TERM_PROGRAM"in X){const J=Number.parseInt((X.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(X.TERM_PROGRAM){case"iTerm.app":return J>=3?3:2;case"Apple_Terminal":return 2}}if(/-256(color)?$/i.test(X.TERM))return 2;if(/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(X.TERM))return 1;if("COLORTERM"in X)return 1;return H};function k($,K={}){const W=t($,{streamIsTTY:$&&$.isTTY,...K});return s(W)}var{env:X}=R,I;if(B("no-color")||B("no-colors")||B("color=false")||B("color=never"))I=0;else if(B("color")||B("colors")||B("color=true")||B("color=always"))I=1;var e={stdout:k({isTTY:b.isatty(1)}),stderr:k({isTTY:b.isatty(2)})},S=e;function _($,K,W){let O=$.indexOf(K);if(O===-1)return $;const z=K.length;let H=0,J="";do J+=$.slice(H,O)+K+W,H=O+z,O=$.indexOf(K,H);while(O!==-1);return J+=$.slice(H),J}function C($,K,W,O){let z=0,H="";do{const J=$[O-1]==="\r";H+=$.slice(z,J?O-1:O)+K+(J?"\r\n":"\n")+W,z=O+1,O=$.indexOf("\n",z)}while(O!==-1);return H+=$.slice(z),H}var M=function($){return K0($)};var{stdout:x,stderr:v}=S,q=Symbol("GENERATOR"),P=Symbol("STYLER"),N=Symbol("IS_EMPTY"),h=["ansi","ansi","ansi256","ansi16m"],w=Object.create(null),$0=($,K={})=>{if(K.level&&!(Number.isInteger(K.level)&&K.level>=0&&K.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");const W=x?x.level:0;$.level=K.level===void 0?W:K.level};var K0=($)=>{const K=(...W)=>W.join(" ");return $0(K,$),Object.setPrototypeOf(K,M.prototype),K};Object.setPrototypeOf(M.prototype,Function.prototype);for(let[$,K]of Object.entries(G))w[$]={get(){const W=L(this,D(K.open,K.close,this[P]),this[N]);return Object.defineProperty(this,$,{value:W}),W}};w.visible={get(){const $=L(this,this[P],!0);return Object.defineProperty(this,"visible",{value:$}),$}};var E=($,K,W,...O)=>{if($==="rgb"){if(K==="ansi16m")return G[W].ansi16m(...O);if(K==="ansi256")return G[W].ansi256(G.rgbToAnsi256(...O));return G[W].ansi(G.rgbToAnsi(...O))}if($==="hex")return E("rgb",K,W,...G.hexToRgb(...O));return G[W][$](...O)},O0=["rgb","hex","ansi256"];for(let $ of O0){w[$]={get(){const{level:W}=this;return function(...O){const z=D(E($,h[W],"color",...O),G.color.close,this[P]);return L(this,z,this[N])}}};const K="bg"+$[0].toUpperCase()+$.slice(1);w[K]={get(){const{level:W}=this;return function(...O){const z=D(E($,h[W],"bgColor",...O),G.bgColor.close,this[P]);return L(this,z,this[N])}}}}var W0=Object.defineProperties(()=>{},{...w,level:{enumerable:!0,get(){return this[q].level},set($){this[q].level=$}}}),D=($,K,W)=>{let O,z;if(W===void 0)O=$,z=K;else O=W.openAll+$,z=K+W.closeAll;return{open:$,close:K,openAll:O,closeAll:z,parent:W}},L=($,K,W)=>{const O=(...z)=>z0(O,z.length===1?""+z[0]:z.join(" "));return Object.setPrototypeOf(O,W0),O[q]=$,O[P]=K,O[N]=W,O},z0=($,K)=>{if($.level<=0||!K)return $[N]?"":K;let W=$[P];if(W===void 0)return K;const{openAll:O,closeAll:z}=W;if(K.includes("\x1B"))while(W!==void 0)K=_(K,W.close,W.open),W=W.parent;const H=K.indexOf("\n");if(H!==-1)K=C(K,z,O,H);return O+K+z};Object.defineProperties(M.prototype,w);var H0=M(),R0=M({level:v?v.level:0});var Q=H0;import{StatusMap as J0} from"elysia";function y($){return $.replace(/\u001b\[\d*m/g,"").trimStart()}var f=($,K,W)=>{const{request:O,path:z,body:H,query:J,set:Z}=$;let j={};for(let d in K)switch(d){case"ip":j.ip=O.headers.get("x-forwarded-for")||"<ip?>";break;case"method":j.method=O.method;break;case"path":j.path=z;break;case"body":j.body=H;break;case"query":j.query=J;break;case"time":j.time=new Date;break;case"contentLength":j.contentLength=Number(O.headers.get("content-length"));break;case"status":if(!Z.status)break;j.status=typeof Z.status==="number"?Z.status:J0[Z.status];break;case"referer":j.referer=O.headers.get("referer")||"<referer?>";break;case"userAgent":j.userAgent=O.headers.get("user-agent")||"<user-agent?>";break;case"duration":const g=process.hrtime.bigint();j.duration=(g-W)/1000n;break}return j},V=($,K)=>{let W=Q.bgBlack;switch($){case"http":W=K[$]&&Q.hex(K[$])||Q.bgBlue;break;case"info":W=K[$]&&Q.hex(K[$])||Q.bgGreen;break;case"warn":W=K[$]&&Q.hex(K[$])||Q.bgYellow;break;case"debug":W=K[$]&&Q.hex(K[$])||Q.bgCyan;break;case"error":W=K[$]&&Q.hex(K[$])||Q.bgRed;break}const O=` ${$.toUpperCase()} `;return W?.(O)??O};var m=($)=>new Y($).use(["time","method","path","status"]).format({onSuccess({time:K,method:W,path:O,status:z}){const H=Q.gray(`${K.toISOString()}`),J=Q.cyan(`${W} ${O}`);let Z=Q.white;if(200<=z&&z<300)Z=Q.green;if(400<=z&&z<500)Z=Q.yellow;if(500<=z)Z=Q.red;return`[${H}] ${J} ${Z(z)}`},onFailure({request:K,error:W,code:O,datetime:z}){const H=Q.gray(`${z.toISOString()}`),J=Q.red(`${K.method} ${K.url} ${W.message} ${O}`);return`[${H}] ${J}`}});var u=($)=>{const K=$.getFullYear(),W=$.getMonth()+1,O=$.getDate(),z=$.getHours(),H=$.getMinutes(),J=$.getSeconds();return`${O}/${W}/${K} ${z}:${H}:${J}`},Q0={showLevel:!0},p=($)=>new Y({...Q0,...$}).use(["time","method","path","duration"]).format({onSuccess({time:K,method:W,path:O,duration:z}){const H=Q.gray(u(K)),J=Q.cyan(`${W} ${O}`);return`${H} ${J} ${z}\u03BCs`},onFailure({request:K,datetime:W}){const O=u(W);return Q.red(`${O} ${K.method} ${K.url}`)}});var c=($)=>{switch($){case"common":return m;case"fancy":return p}};import X0 from"fs";var c0=Q;class Y{requestedAttrs;dest;showLevel;logLevelColour;httpLogging;explicitLogging;constructor($={}){this.requestedAttrs=[],this.showLevel=$.showLevel||!1,this.logLevelColour=$.logLevelColour||{},this.httpLogging=$.httpLogging||!0,this.explicitLogging=$.explicitLogging||!0,this.setDest($.dest||Bun.stdout)}setDest($){if($===Bun.stdin)throw new Error("Cannot log to stdin. Please provide a writable destination.");if($===Bun.stdout||$===Bun.stderr){this.dest=$;return}this.createFileIfNotExists($).then((K)=>this.dest=K).catch((K)=>{throw K})}async createFileIfNotExists($){if(!await $.exists())Bun.write($,"");return $}use($){if(Array.isArray($)){for(let K of $)this._use(K);return this}return this._use($),this}_use($){this.requestedAttrs.push($)}static preset($,K={}){return c($)(K)}build(){return new U0({name:"logestic"}).decorate("logestic",this)}format($){return this.build().state("logestic_timeStart",0n).onRequest(({store:K,request:W})=>{if(K.logestic_timeStart=process.hrtime.bigint(),$.onRequest){let O=$.onRequest(W);if(this.showLevel)O=`${V("http",this.logLevelColour)} ${O}`;this.log(O)}}).onResponse({as:"global"},(K)=>{if(!this.httpLogging)return;const{store:{logestic_timeStart:W}}=K;let O=f(K,this.requestedAttrs,W),z=$.onSuccess(O);if(this.showLevel)z=`${V("http",this.logLevelColour)} ${z}`;this.log(z)}).onError({as:"global"},({request:K,error:W,code:O})=>{let z=new Date,H=$.onFailure({request:K,error:W,code:O,datetime:z});if(this.showLevel)H=`${V("error",this.logLevelColour)} ${H}`;this.log(H)})}async log($){const K=`${$}\n`;if(!this.dest.name||!this.dest.name.length){Bun.write(this.dest,K);return}const W=y(K);X0.appendFile(this.dest.name,W,(O)=>{if(O)throw O})}info($){if(!this.explicitLogging)return;let K=$;if(this.showLevel)K=`${V("info",this.logLevelColour)} ${$}`;this.log(K)}warn($){if(!this.explicitLogging)return;let K=$;if(this.showLevel)K=`${V("warn",this.logLevelColour)} ${$}`;this.log(K)}debug($){if(!this.explicitLogging)return;let K=$;if(this.showLevel)K=`${V("debug",this.logLevelColour)} ${$}`;this.log(K)}error($){if(!this.explicitLogging)return;let K=$;if(this.showLevel)K=`${V("error",this.logLevelColour)} ${$}`;this.log(K)}}export{c0 as chalk,Y as Logestic};

@@ -37,2 +37,3 @@ /**

export type Callback<K extends keyof Attribute> = {
onRequest?: (attr: Request) => string;
onSuccess: (attr: Pick<Attribute, K>) => string;

@@ -39,0 +40,0 @@ onFailure: (attr: ErrorAttribute) => string;

{
"name": "logestic",
"version": "1.0.1",
"version": "1.1.0",
"author": "Nishant Aanjaney Jalan <cybercoder.nishant@gmail.com>",

@@ -5,0 +5,0 @@ "description": "An advanced and customisable logging library for ElysiaJS",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc