cloggi 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -22,13 +22,13 @@ declare class ClogBuilder {
22
22
  get hidden(): this;
23
23
  get timed(): this;
24
24
  get ow(): this;
25
- log(text: number | string | object): this;
26
- error(text: number | string | object): this;
27
- success(text: number | string | object): this;
28
- warning(text: number | string | object): this;
25
+ log(...args: any[]): this;
26
+ error(...args: any[]): this;
27
+ success(...args: any[]): this;
28
+ warning(...args: any[]): this;
29
29
  sep(a?: number | string, b?: number | string): this;
30
- progress(message: number | string | object, total: number, current: number): this;
30
+ progress(message: any, total: number, current: number): this;
31
31
  }
32
- type Cloggi = ClogBuilder & ((text: number | string | object) => void);
32
+ type Cloggi = ClogBuilder & ((...args: any[]) => void);
33
33
  export declare const cloggi: Cloggi;
34
34
  export {};
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { styleText as st } from 'node:util';
2
- import prettyjson from 'prettyjson';
2
+ import { color, colorize } from 'json-colorizer';
3
3
  class ClogBuilder {
4
4
  constructor() {
5
5
  this._color = 'white';
@@ -8,14 +8,31 @@ class ClogBuilder {
8
8
  this._overwrite = false;
9
9
  this._lastOverwriteLines = 0;
10
10
  }
11
- _print(text) {
11
+ _print(...args) {
12
12
  var _a, _b;
13
- const str = typeof text === 'object'
14
- ? prettyjson.render(text)
15
- : typeof text === 'number'
16
- ? st(this._color, text.toString(), { validateStream: false })
17
- : text;
18
- const output = `${this._timed ? `[${new Date().toTimeString().slice(0, 8)}]${typeof text === 'object' ? '\n' : ' - '}` : ''}${str}`;
13
+ const hasObject = args.some(arg => typeof arg === 'object' && arg !== null);
14
+ const str = args
15
+ .map(arg => typeof arg === 'object' && arg !== null
16
+ ? colorize(arg, {
17
+ indent: 2,
18
+ colors: {
19
+ StringKey: color.blueBright,
20
+ BooleanLiteral: color.yellow,
21
+ NullLiteral: color.red,
22
+ NumberLiteral: color.white,
23
+ StringLiteral: color.greenBright,
24
+ Brace: color.white,
25
+ Bracket: color.white,
26
+ Colon: color.white,
27
+ Comma: color.white,
28
+ Whitespace: color.white
29
+ }
30
+ })
31
+ : typeof arg === 'number'
32
+ ? st(this._color, arg.toString(), { validateStream: false })
33
+ : arg)
34
+ .join('\n-----\n');
35
+ const output = `${this._timed ? `[${new Date().toTimeString().slice(0, 8)}]${hasObject ? '\n' : ' - '}` : ''}${str}`;
19
36
  const formats = [this._color, ...this._modifiers];
20
37
  const styled = st(formats, output, { validateStream: false });
21
38
  if (this._lastOverwriteLines > 0) {
@@ -104,24 +121,24 @@ class ClogBuilder {
104
121
  this._overwrite = true;
105
122
  return this;
106
123
  }
107
- log(text) {
108
- return this._print(text);
124
+ log(...args) {
125
+ return this._print(...args);
109
126
  }
110
- error(text) {
127
+ error(...args) {
111
128
  this._color = 'red';
112
129
  this._modifiers.push('bold');
113
130
  this._modifiers.push('inverse');
114
- return this._print(text);
131
+ return this._print(...args);
115
132
  }
116
- success(text) {
133
+ success(...args) {
117
134
  this._color = 'blue';
118
135
  this._modifiers.push('bold');
119
136
  this._modifiers.push('inverse');
120
- return this._print(text);
137
+ return this._print(...args);
121
138
  }
122
- warning(text) {
139
+ warning(...args) {
123
140
  this._color = 'yellow';
124
- return this._print(text);
141
+ return this._print(...args);
125
142
  }
126
143
  sep(a, b) {
127
144
  const length = typeof a === 'number' ? a : typeof b === 'number' ? b : 25;
@@ -136,13 +153,13 @@ class ClogBuilder {
136
153
  const progressBarLength = 50;
137
154
  const filledLength = Math.round((current / total) * progressBarLength);
138
155
  const bar = '█'.repeat(filledLength) + '-'.repeat(progressBarLength - filledLength);
139
- const fullMessage = `${message}\n|${bar}| ${percentage}%\n${current} of ${total}`;
156
+ const fullMessage = `${message}\n${current} of ${total} |${bar}| ${percentage}%`;
140
157
  return this._print(fullMessage);
141
158
  }
142
159
  }
143
160
  const wrapInstance = (instance) => {
144
- return new Proxy(function (text) {
145
- instance.log(text);
161
+ return new Proxy(function (...args) {
162
+ instance.log(...args);
146
163
  }, {
147
164
  get(_target, prop) {
148
165
  const val = instance[prop];
@@ -155,3 +172,4 @@ const wrapInstance = (instance) => {
155
172
  });
156
173
  };
157
174
  export const cloggi = wrapInstance(new ClogBuilder());
175
+ cloggi.blue({ a: 1 }, { b: true, c: 'pippo', d: null }, 'pippo');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloggi",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "author": "Claudio Santancini",
5
5
  "description": "cloggish!",
6
6
  "main": "dist/index.js",
@@ -26,6 +26,6 @@
26
26
  ],
27
27
  "types": "dist/index.d.ts",
28
28
  "dependencies": {
29
- "prettyjson": "^1.2.5"
29
+ "json-colorizer": "^3.0.1"
30
30
  }
31
31
  }