cloggi 1.0.12 → 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 +6 -6
- package/dist/index.js +37 -19
- package/package.json +2 -2
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(
|
|
26
|
-
error(
|
|
27
|
-
success(
|
|
28
|
-
warning(
|
|
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:
|
|
30
|
+
progress(message: any, total: number, current: number): this;
|
|
31
31
|
}
|
|
32
|
-
type Cloggi = ClogBuilder & ((
|
|
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
|
|
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(
|
|
11
|
+
_print(...args) {
|
|
12
12
|
var _a, _b;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
:
|
|
18
|
-
|
|
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(
|
|
108
|
-
return this._print(
|
|
124
|
+
log(...args) {
|
|
125
|
+
return this._print(...args);
|
|
109
126
|
}
|
|
110
|
-
error(
|
|
127
|
+
error(...args) {
|
|
111
128
|
this._color = 'red';
|
|
112
129
|
this._modifiers.push('bold');
|
|
113
130
|
this._modifiers.push('inverse');
|
|
114
|
-
return this._print(
|
|
131
|
+
return this._print(...args);
|
|
115
132
|
}
|
|
116
|
-
success(
|
|
133
|
+
success(...args) {
|
|
117
134
|
this._color = 'blue';
|
|
118
135
|
this._modifiers.push('bold');
|
|
119
136
|
this._modifiers.push('inverse');
|
|
120
|
-
return this._print(
|
|
137
|
+
return this._print(...args);
|
|
121
138
|
}
|
|
122
|
-
warning(
|
|
139
|
+
warning(...args) {
|
|
123
140
|
this._color = 'yellow';
|
|
124
|
-
return this._print(
|
|
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
|
|
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 (
|
|
145
|
-
instance.log(
|
|
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.
|
|
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
|
-
"
|
|
29
|
+
"json-colorizer": "^3.0.1"
|
|
30
30
|
}
|
|
31
31
|
}
|