Comparing version 0.2.0 to 0.3.0
@@ -23,4 +23,3 @@ "use strict"; | ||
module.exports = function (options) { | ||
const debux = existing ? existing : (existing = new Debux(options)); | ||
return debux; | ||
return existing || (existing = new Debux(options)); | ||
}; | ||
@@ -36,3 +35,3 @@ class Debux { | ||
if (this.logLevel == level.all) | ||
return Debux.consoleLog(this.constructMessage(s, options)); | ||
return Debux.consoleLog(this.constructMessage(s, "log", options)); | ||
} | ||
@@ -42,3 +41,3 @@ error(s, options) { | ||
if (this.logLevel > level.error) | ||
return Debux.consoleLog(this.constructMessage(chalk_1.default.red(s), options)); | ||
return Debux.consoleLog(this.constructMessage(chalk_1.default.red(s), "error", options)); | ||
} | ||
@@ -48,3 +47,3 @@ warn(s, options) { | ||
if (this.logLevel > level.warning) | ||
return Debux.consoleLog(this.constructMessage(chalk_1.default.yellow(s), options)); | ||
return Debux.consoleLog(this.constructMessage(chalk_1.default.yellow(s), "warn", options)); | ||
} | ||
@@ -54,3 +53,3 @@ info(s, options) { | ||
if (this.logLevel > level.info) | ||
return Debux.consoleLog(this.constructMessage(chalk_1.default.blue(s), options)); | ||
return Debux.consoleLog(this.constructMessage(s, "info", options)); | ||
} | ||
@@ -63,4 +62,6 @@ get logs() { | ||
} | ||
constructMessage(s, options) { | ||
let msg = chalk_1.default.cyan(new Date().toUTCString()) + seperator; | ||
constructMessage(s, cmd, options) { | ||
let msg = chalk_1.default.black(chalk_1.default.bgCyan(new Date().toUTCString())) + | ||
seperator + | ||
this.getCMDString(cmd); | ||
if (typeof options?.process == "string") | ||
@@ -79,2 +80,16 @@ msg += chalk_1.default.magenta(options.process) + seperator; | ||
} | ||
getCMDString(cmd) { | ||
switch (cmd) { | ||
case "log": | ||
return ""; | ||
case "info": | ||
return chalk_1.default.black(chalk_1.default.bgBlue("Info")) + seperator; | ||
case "warn": | ||
return chalk_1.default.black(chalk_1.default.bgYellow("Warning")) + seperator; | ||
case "error": | ||
return chalk_1.default.black(chalk_1.default.bgRed("Error")) + seperator; | ||
default: | ||
return ""; | ||
} | ||
} | ||
addCache(log) { | ||
@@ -81,0 +96,0 @@ this.cache.push(new Date().toUTCString() + seperator + log); |
@@ -9,3 +9,3 @@ "use strict"; | ||
const debug = __1.default({ maxCacheSize: 10, logLevel: 4 }); | ||
debug.log(null, { | ||
debug.log("this is a log", { | ||
process: "process", | ||
@@ -12,0 +12,0 @@ class: "className", |
{ | ||
"name": "debux", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Easy-to-use library for debugging your code", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -11,2 +11,4 @@ import chalk from "chalk"; | ||
type cmd = "log" | "error" | "warn" | "info"; | ||
export interface Options { | ||
@@ -34,3 +36,3 @@ process?: string; | ||
module.exports = function(options?: constructOptions): Debux { | ||
return existing ? existing : (existing = new Debux(options)); | ||
return existing || (existing = new Debux(options)); | ||
}; | ||
@@ -49,3 +51,4 @@ | ||
this.addCache(s ?? "null"); | ||
if (this.logLevel == level.all) return Debux.consoleLog(this.constructMessage(s, options)); | ||
if (this.logLevel == level.all) | ||
return Debux.consoleLog(this.constructMessage(s, "log", options)); | ||
} | ||
@@ -56,3 +59,3 @@ | ||
if (this.logLevel > level.error) | ||
return Debux.consoleLog(this.constructMessage(chalk.red(s), options)); | ||
return Debux.consoleLog(this.constructMessage(chalk.red(s), "error", options)); | ||
} | ||
@@ -63,3 +66,3 @@ | ||
if (this.logLevel > level.warning) | ||
return Debux.consoleLog(this.constructMessage(chalk.yellow(s), options)); | ||
return Debux.consoleLog(this.constructMessage(chalk.yellow(s), "warn", options)); | ||
} | ||
@@ -70,3 +73,3 @@ | ||
if (this.logLevel > level.info) | ||
return Debux.consoleLog(this.constructMessage(chalk.blue(s), options)); | ||
return Debux.consoleLog(this.constructMessage(s, "info", options)); | ||
} | ||
@@ -82,4 +85,7 @@ | ||
private constructMessage(s: string | null, options?: Options): string { | ||
let msg: string = chalk.cyan(new Date().toUTCString()) + seperator; | ||
private constructMessage(s: string | null, cmd: cmd, options?: Options): string { | ||
let msg: string = | ||
chalk.black(chalk.bgCyan(new Date().toUTCString())) + | ||
seperator + | ||
this.getCMDString(cmd); | ||
if (typeof options?.process == "string") msg += chalk.magenta(options.process) + seperator; | ||
@@ -93,2 +99,19 @@ if (typeof options?.class == "string") msg += chalk.yellow(options.class) + seperator; | ||
private getCMDString(cmd: cmd): string { | ||
switch (cmd) { | ||
case "log": | ||
return ""; | ||
case "info": | ||
return chalk.black(chalk.bgBlue("Info")) + seperator; | ||
case "warn": | ||
return chalk.black(chalk.bgYellow("Warning")) + seperator; | ||
case "error": | ||
return chalk.black(chalk.bgRed("Error")) + seperator; | ||
default: | ||
return ""; | ||
} | ||
} | ||
private addCache(log: string): void { | ||
@@ -95,0 +118,0 @@ this.cache.push(new Date().toUTCString() + seperator + log); |
@@ -6,3 +6,3 @@ //@ts-ignore | ||
debug.log(null, { | ||
debug.log("this is a log", { | ||
process: "process", | ||
@@ -9,0 +9,0 @@ class: "className", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12005
273