UNPKG

@gamastudio/colorslog

Version:

A utility for logging colored messages to the console with different system message types.

3 lines (2 loc) 4.54 kB
"use strict";function t(){return(t=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(null,arguments)}var e;Object.defineProperty(exports,"__esModule",{value:!0}),(e=exports.SystemMessageType||(exports.SystemMessageType={})).SYS="SYS",e.ERROR="ERROR",e.WARNING="WARNING",e.INFO="INFO",e.SUCCESS="SUCCESS",e.TIMEOUT="TIMEOUT",exports.colors=new(function(){function e(){this.TIMEOUT="",this.globalConfig={zoneHour:0,dateShow:!0,useBackground:!1},this.colors={bright:"",dim:"",underscore:"",blink:"",reverse:"",hidden:"",black:"",red:"",green:"",yellow:"",blue:"",magenta:"",cyan:"",white:"",gray:"",orange:"",bgOrange:"",bgBlack:"",bgRed:"",bgGreen:"",bgYellow:"",bgBlue:"",bgMagenta:"",bgCyan:"",bgWhite:"",bgGray:"",brightRed:"",brightGreen:"",brightYellow:"",brightBlue:"",brightMagenta:"",brightCyan:"",brightWhite:"",bgBrightRed:"",bgBrightGreen:"",bgBrightYellow:"",bgBrightBlue:"",bgBrightMagenta:"",bgBrightCyan:"",bgBrightWhite:""}}var r=e.prototype;return r.getFormattedDate=function(t){var e=new Date,r=e.getTimezoneOffset()+60*t,n=new Date(e.getTime()+60*r*1e3);return n.getDate().toString().padStart(2,"0")+"-"+(n.getMonth()+1).toString().padStart(2,"0")+"-"+n.getFullYear().toString().slice(-2)+" "+n.getHours().toString().padStart(2,"0")+":"+n.getMinutes().toString().padStart(2,"0")},r.formatArguments=function(t){return t.map((function(t){if("object"==typeof t)try{return JSON.stringify(t,null,2)}catch(e){return String(t)}return String(t)})).join(" ")},r.extractConfig=function(t){var e=t[t.length-1];if(e&&"object"==typeof e&&!Array.isArray(e)&&["zoneHour","dateShow","useBackground"].some((function(t){return t in e})))return e},r.filterArgs=function(t){return this.extractConfig(t)?t.slice(0,-1):t},r.log=function(t,e,r){var n=e;if(this.colors[t]){var s=r||{},i=s.dateShow,o=s.zoneHour;if(void 0===i?this.globalConfig.dateShow:i){var a=this.getFormattedDate((void 0===o?this.globalConfig.zoneHour:o)||0);n=this.colors.orange+"[DATE: "+this.colors.red+a+"] "+this.colors[t]+e+this.TIMEOUT}else n=""+this.colors[t]+e+this.TIMEOUT}console.log(n)},r.sys=function(t,e){var r,n,s;switch(t){case exports.SystemMessageType.SYS:r="cyan",n="bgCyan",s="brightCyan";break;case exports.SystemMessageType.ERROR:r="red",n="bgRed",s="brightRed";break;case exports.SystemMessageType.WARNING:r="yellow",n="bgYellow",s="brightYellow";break;case exports.SystemMessageType.INFO:r="blue",n="bgBlue",s="brightBlue";break;case exports.SystemMessageType.SUCCESS:r="green",n="bgGreen",s="brightGreen";break;case exports.SystemMessageType.TIMEOUT:r="orange",n="bgOrange",s="orange";break;default:r="",n="",s=""}var i,o=e||{},a=o.useBackground,g=void 0===a?this.globalConfig.useBackground:a;i=g?this.colors[n]+"["+t+"]"+this.TIMEOUT:""+this.colors.bright+this.colors[s]+"["+t+"]"+this.TIMEOUT;for(var h=arguments.length,l=new Array(h>2?h-2:0),c=2;c<h;c++)l[c-2]=arguments[c];var f=this.formatArguments(l);this.log(r,i+" "+f,e)},r.system=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=this.extractConfig(e),s=this.filterArgs(e);this.sys.apply(this,["SYS",n].concat(s))},r.info=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=this.extractConfig(e),s=this.filterArgs(e);this.sys.apply(this,["INFO",n].concat(s))},r.warn=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=this.extractConfig(e),s=this.filterArgs(e);this.sys.apply(this,["WARNING",n].concat(s))},r.success=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=this.extractConfig(e),s=this.filterArgs(e);this.sys.apply(this,["SUCCESS",n].concat(s))},r.timeout=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=this.extractConfig(e),s=this.filterArgs(e);this.sys.apply(this,["TIMEOUT",n].concat(s))},r.error=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=this.extractConfig(e),s=this.filterArgs(e);this.sys.apply(this,["ERROR",n].concat(s))},r.clear=function(){console.clear()},r.setConfig=function(e){this.globalConfig=t({},this.globalConfig,e)},e}()); //# sourceMappingURL=colorslog.cjs.production.min.js.map