🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

concol

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

concol - npm Package Compare versions

Comparing version
2.0.0
to
2.1.0
+12
-16
concol.js

@@ -6,7 +6,7 @@ /** Color console logging class */

static #appNameLen = 0;
static #namePad = 34;
static #valuePad = 10;
static #numFormat = new Intl.NumberFormat('en-GB', { maximumFractionDigits: 0 });
static #timeFormat = new Intl.DateTimeFormat('en-GB', { hour: '2-digit', minute: '2-digit', second: '2-digit', fractionalSecondDigits: 3 });
static appSize = 14;
static nameSize = 30;
static valueSize = 8;
static numFormat = new Intl.NumberFormat('en-GB', { maximumFractionDigits: 0 });
static timeFormat = new Intl.DateTimeFormat('en-GB', { hour: '2-digit', minute: '2-digit', second: '2-digit', fractionalSecondDigits: 3 });

@@ -28,5 +28,2 @@ #app = 'ConCol';

const aL = this.#app.length;
if (aL > ConCol.#appNameLen) ConCol.#appNameLen = aL;
// app base color

@@ -40,3 +37,2 @@ this.#color = color || this.#color;

/**

@@ -96,3 +92,3 @@ * Outputs log message

msg = this.#parseLog(msg, this.#color, typeMsg, typeColor);
const pre = this.#appPrefix();
const pre = this.#appPrefix(typeColor);

@@ -111,7 +107,7 @@ msg.forEach(m => {

*/
#appPrefix() {
#appPrefix(typeColor) {
return (
styleText( 'grey', ConCol.#timeFormat.format(new Date()) ) +
styleText( ['dim', this.#color], ` [${ this.#app.padEnd( ConCol.#appNameLen, ' ') }] `)
styleText( typeColor || ['dim', this.#color], ConCol.timeFormat.format(new Date()) ) +
styleText( this.#color, ` ${ this.#app.slice(0, ConCol.appSize).padEnd( ConCol.appSize, ' ') }┃ `)
);

@@ -157,8 +153,8 @@ }

else {
val = ConCol.#numFormat.format( parseFloat(val) );
val = ConCol.numFormat.format( parseFloat(val) ).padStart(ConCol.valueSize, ' ');
}
ret = [
styleText(color, name.padStart(ConCol.#namePad - typeMsg.length, ' ') + ':') +
styleText('white', val.padStart(ConCol.#valuePad, ' ') + unit)
styleText(color, name.padStart(ConCol.nameSize - typeMsg.length, ' ') + ': ') +
styleText('white', val + unit)
];

@@ -165,0 +161,0 @@ }

{
"name": "concol",
"version": "2.0.0",
"version": "2.1.0",
"description": "Node.js color console logger",

@@ -5,0 +5,0 @@ "type": "module",

+57
-14

@@ -5,3 +5,3 @@ # ConCol

Time is shown in 24-hour HH:MM:SS.MMM format. Numbers are formatted to 0-dp US/UK format.
By default, time is shown in 24-hour HH:MM:SS.mmm and numbers are shown in #,### format.

@@ -23,3 +23,3 @@

const log2 = new ConCol('App Two', 'green');
const log3 = new ConCol('App Three', 'white', 3);
const log3 = new ConCol('App Three 0123456789', 'white', 3);

@@ -33,7 +33,7 @@ // basic logging

/* output
13:58:10.171 [App One ] output single string
13:58:10.172 [App One ] output string
13:58:10.172 [App One ] with carriage returns
13:58:10.172 [App One ] WARN: show warning
13:58:10.172 [App One ] ERROR: show error
12:30:07.030 App One ┃ output a single string
10:54:34.645 App One ┃ output string
10:54:34.645 App One ┃ with carriage returns
10:54:34.646 App One ┃ WARN: show warning
10:54:34.646 App One ┃ ERROR: show error
*/

@@ -46,7 +46,7 @@

/* output
13:58:10.223 [App Two ] this requires: 0 modules
13:58:10.223 [App Two ] fibonacci sequence
13:58:10.223 [App Two ] first: 1
13:58:10.223 [App Two ] second: 1
13:58:10.223 [App Two ] third: 2
10:54:34.697 App Two ┃ ConCol requires: 0 modules
10:54:34.697 App Two ┃ output the fibonacci sequence
10:54:34.697 App Two ┃ first: 1
10:54:34.697 App Two ┃ second: 1
10:54:34.697 App Two ┃ third: 2
*/

@@ -60,4 +60,4 @@

/* output
13:58:10.275 [App Three] level0
13:58:10.275 [App Three] level3
10:54:34.748 App Three 0123┃ level0
10:54:34.748 App Three 0123┃ level3
*/

@@ -108,1 +108,44 @@ ```

Outputs `console.error()` messages prefixed with "ERROR:". Parameters are identical to [`log()`](#logmsg-level).
## Advanced configuration
The following static properties configure log layout:
* `ConCol.appSize = <num>` - the width of the appName column (default 14)
* `ConCol.nameSize = <num>` - the width of a name column (30)
* `ConCol.valueSize = <num>` - the width of a value column (10)
* `ConCol.numFormat = <Intl.NumberFormat>` - numeric value object (`#,###` rounded to 0dp)
* `ConCol.timeFormat = <Intl.DateTimeFormat>` - date/time object (`HH:MM:SS.mmm`)
```js
// example
ConCol.appSize = 7;
ConCol.nameSize = 15;
ConCol.valueSize = 10;
// show values in #,###.## format
ConCol.numFormat = new Intl.NumberFormat(
'en-US',
{ minimumFractionDigits: 2, maximumFractionDigits: 2 }
);
// show dates in DD/MM HH:MM:SS format
ConCol.timeFormat = new Intl.DateTimeFormat(
'af-AF',
{
month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', second: '2-digit'
}
);
const cc = new ConCol('App One', 'yellow');
cc.log([ 'number two', 12345.678 ]);
cc.log([ 'number one', 123 ]);
/* output
05-06 13:18:20 App One┃ number two: 12,345.68
05-06 13:18:20 App One┃ number one: 123.00
*/
```