Comparing version 1.0.9 to 1.0.11
@@ -24,2 +24,3 @@ /* eslint-disable no-console,no-constructor-return */ | ||
}; | ||
export const clearESC = (str) => str.replace(/\x1b\[[\d;]+m/ig, ''); | ||
const logLevelsMeta = [ | ||
@@ -160,3 +161,12 @@ { name: 'silly', colorNum: magentaN, index: 0 }, | ||
} | ||
if (typeof msg === 'object') { | ||
const { colorNum, consoleFunction = 'log', estimate, estimateReset = false, emptyLinesBefore = 0, } = options; | ||
options.colorNum = colorNum || levelColors[levelName] || greyN; | ||
const color = _c(options); | ||
if (estimate) { | ||
title = `${estimate.getTaken(estimateReset, true)} ${title || ''}`; | ||
} | ||
const lb = Number(emptyLinesBefore) ? '\n'.repeat(Number(emptyLinesBefore)) : ''; | ||
const cTitle = title ? `\x1b[1m${title}: \x1b[21m` : ''; | ||
const isError = msg instanceof Error; | ||
if (!isError && typeof msg === 'object') { | ||
if (options.prettyJSON) { | ||
@@ -169,13 +179,5 @@ msg = JSON.stringify(msg, undefined, 2); | ||
} | ||
if (/^ *SELECT /.test(msg)) { | ||
if (typeof msg === 'string' && /^ *SELECT /.test(msg)) { | ||
msg = `${magenta}\n${msg}\n`; | ||
} | ||
const { colorNum, consoleFunction = 'log', estimate, estimateReset = false, linesBefore = 0, } = options; | ||
options.colorNum = colorNum || levelColors[levelName] || greyN; | ||
const color = _c(options); | ||
if (estimate) { | ||
title = `${estimate.getTaken(estimateReset, true)} ${title || ''}`; | ||
} | ||
const lb = Number(linesBefore) ? '\n'.repeat(Number(linesBefore)) : ''; | ||
const cTitle = title ? `\x1b[1m${title}: \x1b[21m` : ''; | ||
if (consoleFunction === 'dir') { | ||
@@ -186,6 +188,17 @@ console.dir(msg); | ||
else { | ||
const prefix = options.prefix ? `${color}${underlineOff}${options.prefix}` : this.prefix; | ||
const logMessage = `${lb}${prefix}${color}${cTitle}${underlineOff}${color}${msg}${reset}`; | ||
console.log(logMessage); | ||
this._lastLogMessage = logMessage; | ||
let prefix = options.prefix ? `${color}${underlineOff}${options.prefix}` : this.prefix; | ||
prefix = `${lb}${prefix}${color}${cTitle}${underlineOff}${reset}`; // ${color}${msg}${reset} | ||
if (!clearESC(prefix).replace(/\s/g, '')) { | ||
prefix = ''; | ||
} | ||
if (!isError) { | ||
msg = `${color}${msg}${reset}`; | ||
} | ||
if (prefix) { | ||
console.log(prefix, msg); | ||
} | ||
else { | ||
console.log(msg); | ||
} | ||
this._lastLogMessage = msg; | ||
} | ||
@@ -192,0 +205,0 @@ } |
@@ -25,4 +25,5 @@ export interface ILogLevel { | ||
prettyJSON?: boolean; | ||
linesBefore?: number; | ||
emptyLinesBefore?: number; | ||
} | ||
export declare const clearESC: (str: string) => string; | ||
/** | ||
@@ -29,0 +30,0 @@ * The class implements the functions of logging to the console with the ability |
{ | ||
"name": "af-echo-ts", | ||
"version": "1.0.9", | ||
"version": "1.0.11", | ||
"description": "Echo", | ||
"main": "./dist/cjs/index.js", | ||
"main": "./dist/cjs/src/index.js", | ||
"module": "./dist/esm/index.js", | ||
@@ -7,0 +7,0 @@ "types": "./dist/types/index.d.ts", |
@@ -36,3 +36,3 @@ /* eslint-disable no-console,no-constructor-return */ | ||
prettyJSON?: boolean, | ||
linesBefore?: number, | ||
emptyLinesBefore?: number, | ||
} | ||
@@ -62,2 +62,4 @@ | ||
export const clearESC = (str: string) => str.replace(/\x1b\[[\d;]+m/ig, ''); | ||
const logLevelsMeta = [ | ||
@@ -195,3 +197,3 @@ { name: 'silly', colorNum: magentaN, index: 0 }, | ||
let msg: string = ''; | ||
let msg: string | Error | any = ''; | ||
@@ -221,12 +223,3 @@ let title: string = ''; | ||
} | ||
if (typeof msg === 'object') { | ||
if (options.prettyJSON) { | ||
msg = JSON.stringify(msg, undefined, 2); | ||
} else { | ||
msg = JSON.stringify(msg); | ||
} | ||
} | ||
if (/^ *SELECT /.test(msg)) { | ||
msg = `${magenta}\n${msg}\n`; | ||
} | ||
const { | ||
@@ -237,3 +230,3 @@ colorNum, | ||
estimateReset = false, | ||
linesBefore = 0, | ||
emptyLinesBefore = 0, | ||
} = options; | ||
@@ -246,4 +239,17 @@ | ||
} | ||
const lb = Number(linesBefore) ? '\n'.repeat(Number(linesBefore)) : ''; | ||
const lb = Number(emptyLinesBefore) ? '\n'.repeat(Number(emptyLinesBefore)) : ''; | ||
const cTitle = title ? `\x1b[1m${title}: \x1b[21m` : ''; | ||
const isError = msg instanceof Error; | ||
if (!isError && typeof msg === 'object') { | ||
if (options.prettyJSON) { | ||
msg = JSON.stringify(msg, undefined, 2); | ||
} else { | ||
msg = JSON.stringify(msg); | ||
} | ||
} | ||
if (typeof msg === 'string' && /^ *SELECT /.test(msg)) { | ||
msg = `${magenta}\n${msg}\n`; | ||
} | ||
if (consoleFunction === 'dir') { | ||
@@ -253,6 +259,16 @@ console.dir(msg); | ||
} else { | ||
const prefix = options.prefix ? `${color}${underlineOff}${options.prefix}` : this.prefix; | ||
const logMessage = `${lb}${prefix}${color}${cTitle}${underlineOff}${color}${msg}${reset}`; | ||
console.log(logMessage); | ||
this._lastLogMessage = logMessage; | ||
let prefix = options.prefix ? `${color}${underlineOff}${options.prefix}` : this.prefix; | ||
prefix = `${lb}${prefix}${color}${cTitle}${underlineOff}${reset}`; // ${color}${msg}${reset} | ||
if (!clearESC(prefix).replace(/\s/g, '')) { | ||
prefix = ''; | ||
} | ||
if (!isError) { | ||
msg = `${color}${msg}${reset}`; | ||
} | ||
if (prefix) { | ||
console.log(prefix, msg); | ||
} else { | ||
console.log(msg); | ||
} | ||
this._lastLogMessage = msg; | ||
} | ||
@@ -259,0 +275,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
45982
11
811