colorino 0.13.1 → 0.13.2
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/browser.bundle.cjs +45 -49
- package/dist/browser.bundle.mjs +45 -49
- package/dist/browser.cjs +1 -1
- package/dist/browser.mjs +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.mjs +1 -1
- package/dist/shared/{colorino.Dcy2ipG7.cjs → colorino.DMgDgITw.cjs} +45 -49
- package/dist/shared/{colorino.DEvR4n1Y.mjs → colorino.vAejLjBp.mjs} +45 -49
- package/package.json +1 -1
package/dist/browser.bundle.cjs
CHANGED
|
@@ -59,9 +59,6 @@ var ColorLevel = /* @__PURE__ */ ((ColorLevel2) => {
|
|
|
59
59
|
return ColorLevel2;
|
|
60
60
|
})(ColorLevel || {});
|
|
61
61
|
|
|
62
|
-
function isConsoleMethod(level) {
|
|
63
|
-
return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
|
|
64
|
-
}
|
|
65
62
|
const ColorinoBrowserColorized = Symbol("colorino.browserColorized");
|
|
66
63
|
const ColorinoBrowserObject = Symbol("colorino.browserObject");
|
|
67
64
|
|
|
@@ -152,26 +149,38 @@ class TypeValidator {
|
|
|
152
149
|
static isNull(value) {
|
|
153
150
|
return value === null;
|
|
154
151
|
}
|
|
152
|
+
static isUndefined(value) {
|
|
153
|
+
return value === void 0;
|
|
154
|
+
}
|
|
155
|
+
static isNullOrUndefined(value) {
|
|
156
|
+
return value == null;
|
|
157
|
+
}
|
|
155
158
|
static isObject(value) {
|
|
156
159
|
return typeof value === "object" && value !== null;
|
|
157
160
|
}
|
|
158
161
|
static isString(value) {
|
|
159
|
-
return typeof value === "string";
|
|
162
|
+
return typeof value === "string" || value instanceof String;
|
|
163
|
+
}
|
|
164
|
+
static isArray(value) {
|
|
165
|
+
return Array.isArray(value);
|
|
160
166
|
}
|
|
161
167
|
static isError(value) {
|
|
162
168
|
return value instanceof Error;
|
|
163
169
|
}
|
|
164
170
|
static isBrowserColorizedArg(value) {
|
|
165
|
-
return
|
|
171
|
+
return TypeValidator.isObject(value) && ColorinoBrowserColorized in value;
|
|
166
172
|
}
|
|
167
173
|
static isBrowserObjectArg(value) {
|
|
168
|
-
return
|
|
174
|
+
return TypeValidator.isObject(value) && ColorinoBrowserObject in value;
|
|
169
175
|
}
|
|
170
176
|
static isAnsiColoredString(value) {
|
|
171
|
-
return TypeValidator.isString(value) && /\x1b\[[0-9;]*m/.test(value);
|
|
177
|
+
return TypeValidator.isString(value) && /\x1b\[[0-9;]*m/.test(value.toString());
|
|
172
178
|
}
|
|
173
179
|
static isFormattableObject(value) {
|
|
174
|
-
return TypeValidator.isObject(value) && !TypeValidator.isError(value) && !TypeValidator.isBrowserColorizedArg(value);
|
|
180
|
+
return TypeValidator.isObject(value) && !TypeValidator.isError(value) && !TypeValidator.isBrowserColorizedArg(value) && !TypeValidator.isString(value);
|
|
181
|
+
}
|
|
182
|
+
static isConsoleMethod(level) {
|
|
183
|
+
return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
|
|
175
184
|
}
|
|
176
185
|
}
|
|
177
186
|
|
|
@@ -236,9 +245,6 @@ class MyColorino {
|
|
|
236
245
|
}
|
|
237
246
|
return `${ansiPrefix}${text}\x1B[0m`;
|
|
238
247
|
}
|
|
239
|
-
_isAnsiColoredString(value) {
|
|
240
|
-
return typeof value === "string" && /\x1b\[[0-9;]*m/.test(value);
|
|
241
|
-
}
|
|
242
248
|
_applyResolvedTheme(resolvedTheme) {
|
|
243
249
|
const themeOpt = this._options.theme ?? "auto";
|
|
244
250
|
const baseThemeName = determineBaseTheme(themeOpt, resolvedTheme);
|
|
@@ -263,34 +269,35 @@ class MyColorino {
|
|
|
263
269
|
}
|
|
264
270
|
_formatValue(value, maxDepth = this._options.maxDepth ?? 5) {
|
|
265
271
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
272
|
+
const sanitizeArray = (items, currentDepth) => {
|
|
273
|
+
return items.map((item) => sanitize(item, currentDepth));
|
|
274
|
+
};
|
|
275
|
+
const sanitizeObject = (obj, currentDepth) => {
|
|
276
|
+
const result = {};
|
|
277
|
+
for (const key in obj) {
|
|
278
|
+
result[key] = sanitize(obj[key], currentDepth);
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
281
|
+
};
|
|
266
282
|
const sanitize = (val, currentDepth) => {
|
|
267
|
-
if (val
|
|
283
|
+
if (TypeValidator.isNullOrUndefined(val) || !TypeValidator.isObject(val)) {
|
|
284
|
+
return val;
|
|
285
|
+
}
|
|
268
286
|
if (seen.has(val)) return "[Circular]";
|
|
269
287
|
seen.add(val);
|
|
270
288
|
if (currentDepth >= maxDepth) return "[Object]";
|
|
271
|
-
|
|
272
|
-
|
|
289
|
+
const nextDepth = currentDepth + 1;
|
|
290
|
+
if (TypeValidator.isArray(val)) {
|
|
291
|
+
return sanitizeArray(val, nextDepth);
|
|
273
292
|
}
|
|
274
|
-
|
|
275
|
-
for (const key in val) {
|
|
276
|
-
result[key] = sanitize(
|
|
277
|
-
val[key],
|
|
278
|
-
currentDepth + 1
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
return result;
|
|
293
|
+
return sanitizeObject(val, nextDepth);
|
|
282
294
|
};
|
|
283
295
|
return JSON.stringify(sanitize(value, 0), null, 2);
|
|
284
296
|
}
|
|
285
|
-
_normalizeString(value) {
|
|
286
|
-
if (value instanceof String) return value.valueOf();
|
|
287
|
-
return value;
|
|
288
|
-
}
|
|
289
297
|
_processArgs(args) {
|
|
290
298
|
const processedArgs = [];
|
|
291
299
|
let previousWasObject = false;
|
|
292
|
-
for (const
|
|
293
|
-
const arg = this._normalizeString(rawArg);
|
|
300
|
+
for (const arg of args) {
|
|
294
301
|
if (TypeValidator.isBrowserColorizedArg(arg)) {
|
|
295
302
|
processedArgs.push(arg);
|
|
296
303
|
previousWasObject = false;
|
|
@@ -327,8 +334,7 @@ ${arg}`);
|
|
|
327
334
|
const cssArgs = [];
|
|
328
335
|
const otherArgs = [];
|
|
329
336
|
const paletteHex = this._palette[consoleMethod];
|
|
330
|
-
for (const
|
|
331
|
-
const arg = this._normalizeString(rawArg);
|
|
337
|
+
for (const arg of args) {
|
|
332
338
|
if (TypeValidator.isBrowserColorizedArg(arg)) {
|
|
333
339
|
formatParts.push(`%c${arg.text}`);
|
|
334
340
|
cssArgs.push(`color:${arg.hex}`);
|
|
@@ -373,31 +379,21 @@ ${arg}`);
|
|
|
373
379
|
}
|
|
374
380
|
}
|
|
375
381
|
_applyNodeColors(consoleMethod, args) {
|
|
376
|
-
const
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
)
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
if (this._isAnsiColoredString(first)) {
|
|
385
|
-
return coloredArgs;
|
|
386
|
-
}
|
|
387
|
-
const hex = this._palette[consoleMethod];
|
|
388
|
-
const ansiPrefix = this._toAnsiPrefix(hex);
|
|
389
|
-
if (!ansiPrefix) {
|
|
390
|
-
return coloredArgs;
|
|
391
|
-
}
|
|
392
|
-
coloredArgs[firstStringIndex] = `${ansiPrefix}${String(first)}\x1B[0m`;
|
|
393
|
-
return coloredArgs;
|
|
382
|
+
const paletteHex = this._palette[consoleMethod];
|
|
383
|
+
const paletteAnsiPrefix = this._toAnsiPrefix(paletteHex);
|
|
384
|
+
if (!paletteAnsiPrefix) return args;
|
|
385
|
+
return args.map((arg) => {
|
|
386
|
+
if (!TypeValidator.isString(arg) || TypeValidator.isAnsiColoredString(arg))
|
|
387
|
+
return arg;
|
|
388
|
+
return `${paletteAnsiPrefix}${String(arg)}\x1B[0m`;
|
|
389
|
+
});
|
|
394
390
|
}
|
|
395
391
|
_output(consoleMethod, args) {
|
|
396
392
|
if (consoleMethod === "trace") this._printCleanTrace(args);
|
|
397
393
|
else console[consoleMethod](...args);
|
|
398
394
|
}
|
|
399
395
|
_out(level, args) {
|
|
400
|
-
const consoleMethod = isConsoleMethod(level) ? level : "log";
|
|
396
|
+
const consoleMethod = TypeValidator.isConsoleMethod(level) ? level : "log";
|
|
401
397
|
const processedArgs = this._processArgs(args);
|
|
402
398
|
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
403
399
|
this._output(consoleMethod, processedArgs);
|
package/dist/browser.bundle.mjs
CHANGED
|
@@ -57,9 +57,6 @@ var ColorLevel = /* @__PURE__ */ ((ColorLevel2) => {
|
|
|
57
57
|
return ColorLevel2;
|
|
58
58
|
})(ColorLevel || {});
|
|
59
59
|
|
|
60
|
-
function isConsoleMethod(level) {
|
|
61
|
-
return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
|
|
62
|
-
}
|
|
63
60
|
const ColorinoBrowserColorized = Symbol("colorino.browserColorized");
|
|
64
61
|
const ColorinoBrowserObject = Symbol("colorino.browserObject");
|
|
65
62
|
|
|
@@ -150,26 +147,38 @@ class TypeValidator {
|
|
|
150
147
|
static isNull(value) {
|
|
151
148
|
return value === null;
|
|
152
149
|
}
|
|
150
|
+
static isUndefined(value) {
|
|
151
|
+
return value === void 0;
|
|
152
|
+
}
|
|
153
|
+
static isNullOrUndefined(value) {
|
|
154
|
+
return value == null;
|
|
155
|
+
}
|
|
153
156
|
static isObject(value) {
|
|
154
157
|
return typeof value === "object" && value !== null;
|
|
155
158
|
}
|
|
156
159
|
static isString(value) {
|
|
157
|
-
return typeof value === "string";
|
|
160
|
+
return typeof value === "string" || value instanceof String;
|
|
161
|
+
}
|
|
162
|
+
static isArray(value) {
|
|
163
|
+
return Array.isArray(value);
|
|
158
164
|
}
|
|
159
165
|
static isError(value) {
|
|
160
166
|
return value instanceof Error;
|
|
161
167
|
}
|
|
162
168
|
static isBrowserColorizedArg(value) {
|
|
163
|
-
return
|
|
169
|
+
return TypeValidator.isObject(value) && ColorinoBrowserColorized in value;
|
|
164
170
|
}
|
|
165
171
|
static isBrowserObjectArg(value) {
|
|
166
|
-
return
|
|
172
|
+
return TypeValidator.isObject(value) && ColorinoBrowserObject in value;
|
|
167
173
|
}
|
|
168
174
|
static isAnsiColoredString(value) {
|
|
169
|
-
return TypeValidator.isString(value) && /\x1b\[[0-9;]*m/.test(value);
|
|
175
|
+
return TypeValidator.isString(value) && /\x1b\[[0-9;]*m/.test(value.toString());
|
|
170
176
|
}
|
|
171
177
|
static isFormattableObject(value) {
|
|
172
|
-
return TypeValidator.isObject(value) && !TypeValidator.isError(value) && !TypeValidator.isBrowserColorizedArg(value);
|
|
178
|
+
return TypeValidator.isObject(value) && !TypeValidator.isError(value) && !TypeValidator.isBrowserColorizedArg(value) && !TypeValidator.isString(value);
|
|
179
|
+
}
|
|
180
|
+
static isConsoleMethod(level) {
|
|
181
|
+
return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
|
|
173
182
|
}
|
|
174
183
|
}
|
|
175
184
|
|
|
@@ -234,9 +243,6 @@ class MyColorino {
|
|
|
234
243
|
}
|
|
235
244
|
return `${ansiPrefix}${text}\x1B[0m`;
|
|
236
245
|
}
|
|
237
|
-
_isAnsiColoredString(value) {
|
|
238
|
-
return typeof value === "string" && /\x1b\[[0-9;]*m/.test(value);
|
|
239
|
-
}
|
|
240
246
|
_applyResolvedTheme(resolvedTheme) {
|
|
241
247
|
const themeOpt = this._options.theme ?? "auto";
|
|
242
248
|
const baseThemeName = determineBaseTheme(themeOpt, resolvedTheme);
|
|
@@ -261,34 +267,35 @@ class MyColorino {
|
|
|
261
267
|
}
|
|
262
268
|
_formatValue(value, maxDepth = this._options.maxDepth ?? 5) {
|
|
263
269
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
270
|
+
const sanitizeArray = (items, currentDepth) => {
|
|
271
|
+
return items.map((item) => sanitize(item, currentDepth));
|
|
272
|
+
};
|
|
273
|
+
const sanitizeObject = (obj, currentDepth) => {
|
|
274
|
+
const result = {};
|
|
275
|
+
for (const key in obj) {
|
|
276
|
+
result[key] = sanitize(obj[key], currentDepth);
|
|
277
|
+
}
|
|
278
|
+
return result;
|
|
279
|
+
};
|
|
264
280
|
const sanitize = (val, currentDepth) => {
|
|
265
|
-
if (val
|
|
281
|
+
if (TypeValidator.isNullOrUndefined(val) || !TypeValidator.isObject(val)) {
|
|
282
|
+
return val;
|
|
283
|
+
}
|
|
266
284
|
if (seen.has(val)) return "[Circular]";
|
|
267
285
|
seen.add(val);
|
|
268
286
|
if (currentDepth >= maxDepth) return "[Object]";
|
|
269
|
-
|
|
270
|
-
|
|
287
|
+
const nextDepth = currentDepth + 1;
|
|
288
|
+
if (TypeValidator.isArray(val)) {
|
|
289
|
+
return sanitizeArray(val, nextDepth);
|
|
271
290
|
}
|
|
272
|
-
|
|
273
|
-
for (const key in val) {
|
|
274
|
-
result[key] = sanitize(
|
|
275
|
-
val[key],
|
|
276
|
-
currentDepth + 1
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
return result;
|
|
291
|
+
return sanitizeObject(val, nextDepth);
|
|
280
292
|
};
|
|
281
293
|
return JSON.stringify(sanitize(value, 0), null, 2);
|
|
282
294
|
}
|
|
283
|
-
_normalizeString(value) {
|
|
284
|
-
if (value instanceof String) return value.valueOf();
|
|
285
|
-
return value;
|
|
286
|
-
}
|
|
287
295
|
_processArgs(args) {
|
|
288
296
|
const processedArgs = [];
|
|
289
297
|
let previousWasObject = false;
|
|
290
|
-
for (const
|
|
291
|
-
const arg = this._normalizeString(rawArg);
|
|
298
|
+
for (const arg of args) {
|
|
292
299
|
if (TypeValidator.isBrowserColorizedArg(arg)) {
|
|
293
300
|
processedArgs.push(arg);
|
|
294
301
|
previousWasObject = false;
|
|
@@ -325,8 +332,7 @@ ${arg}`);
|
|
|
325
332
|
const cssArgs = [];
|
|
326
333
|
const otherArgs = [];
|
|
327
334
|
const paletteHex = this._palette[consoleMethod];
|
|
328
|
-
for (const
|
|
329
|
-
const arg = this._normalizeString(rawArg);
|
|
335
|
+
for (const arg of args) {
|
|
330
336
|
if (TypeValidator.isBrowserColorizedArg(arg)) {
|
|
331
337
|
formatParts.push(`%c${arg.text}`);
|
|
332
338
|
cssArgs.push(`color:${arg.hex}`);
|
|
@@ -371,31 +377,21 @@ ${arg}`);
|
|
|
371
377
|
}
|
|
372
378
|
}
|
|
373
379
|
_applyNodeColors(consoleMethod, args) {
|
|
374
|
-
const
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
)
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
if (this._isAnsiColoredString(first)) {
|
|
383
|
-
return coloredArgs;
|
|
384
|
-
}
|
|
385
|
-
const hex = this._palette[consoleMethod];
|
|
386
|
-
const ansiPrefix = this._toAnsiPrefix(hex);
|
|
387
|
-
if (!ansiPrefix) {
|
|
388
|
-
return coloredArgs;
|
|
389
|
-
}
|
|
390
|
-
coloredArgs[firstStringIndex] = `${ansiPrefix}${String(first)}\x1B[0m`;
|
|
391
|
-
return coloredArgs;
|
|
380
|
+
const paletteHex = this._palette[consoleMethod];
|
|
381
|
+
const paletteAnsiPrefix = this._toAnsiPrefix(paletteHex);
|
|
382
|
+
if (!paletteAnsiPrefix) return args;
|
|
383
|
+
return args.map((arg) => {
|
|
384
|
+
if (!TypeValidator.isString(arg) || TypeValidator.isAnsiColoredString(arg))
|
|
385
|
+
return arg;
|
|
386
|
+
return `${paletteAnsiPrefix}${String(arg)}\x1B[0m`;
|
|
387
|
+
});
|
|
392
388
|
}
|
|
393
389
|
_output(consoleMethod, args) {
|
|
394
390
|
if (consoleMethod === "trace") this._printCleanTrace(args);
|
|
395
391
|
else console[consoleMethod](...args);
|
|
396
392
|
}
|
|
397
393
|
_out(level, args) {
|
|
398
|
-
const consoleMethod = isConsoleMethod(level) ? level : "log";
|
|
394
|
+
const consoleMethod = TypeValidator.isConsoleMethod(level) ? level : "log";
|
|
399
395
|
const processedArgs = this._processArgs(args);
|
|
400
396
|
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
401
397
|
this._output(consoleMethod, processedArgs);
|
package/dist/browser.cjs
CHANGED
package/dist/browser.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ColorLevel, t as themePalettes, M as MyColorino, I as InputValidator, d as determineBaseTheme } from './shared/colorino.
|
|
1
|
+
import { C as ColorLevel, t as themePalettes, M as MyColorino, I as InputValidator, d as determineBaseTheme } from './shared/colorino.vAejLjBp.mjs';
|
|
2
2
|
|
|
3
3
|
class BrowserColorSupportDetector {
|
|
4
4
|
constructor(_window, _navigator, _overrideTheme) {
|
package/dist/node.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const inputValidator = require('./shared/colorino.
|
|
3
|
+
const inputValidator = require('./shared/colorino.DMgDgITw.cjs');
|
|
4
4
|
const node_child_process = require('node:child_process');
|
|
5
5
|
const node_url = require('node:url');
|
|
6
6
|
const node_path = require('node:path');
|
package/dist/node.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ColorLevel, d as determineBaseTheme, t as themePalettes, M as MyColorino, I as InputValidator } from './shared/colorino.
|
|
1
|
+
import { C as ColorLevel, d as determineBaseTheme, t as themePalettes, M as MyColorino, I as InputValidator } from './shared/colorino.vAejLjBp.mjs';
|
|
2
2
|
import { spawnSync } from 'node:child_process';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
@@ -59,9 +59,6 @@ var ColorLevel = /* @__PURE__ */ ((ColorLevel2) => {
|
|
|
59
59
|
return ColorLevel2;
|
|
60
60
|
})(ColorLevel || {});
|
|
61
61
|
|
|
62
|
-
function isConsoleMethod(level) {
|
|
63
|
-
return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
|
|
64
|
-
}
|
|
65
62
|
const ColorinoBrowserColorized = Symbol("colorino.browserColorized");
|
|
66
63
|
const ColorinoBrowserObject = Symbol("colorino.browserObject");
|
|
67
64
|
|
|
@@ -152,26 +149,38 @@ class TypeValidator {
|
|
|
152
149
|
static isNull(value) {
|
|
153
150
|
return value === null;
|
|
154
151
|
}
|
|
152
|
+
static isUndefined(value) {
|
|
153
|
+
return value === void 0;
|
|
154
|
+
}
|
|
155
|
+
static isNullOrUndefined(value) {
|
|
156
|
+
return value == null;
|
|
157
|
+
}
|
|
155
158
|
static isObject(value) {
|
|
156
159
|
return typeof value === "object" && value !== null;
|
|
157
160
|
}
|
|
158
161
|
static isString(value) {
|
|
159
|
-
return typeof value === "string";
|
|
162
|
+
return typeof value === "string" || value instanceof String;
|
|
163
|
+
}
|
|
164
|
+
static isArray(value) {
|
|
165
|
+
return Array.isArray(value);
|
|
160
166
|
}
|
|
161
167
|
static isError(value) {
|
|
162
168
|
return value instanceof Error;
|
|
163
169
|
}
|
|
164
170
|
static isBrowserColorizedArg(value) {
|
|
165
|
-
return
|
|
171
|
+
return TypeValidator.isObject(value) && ColorinoBrowserColorized in value;
|
|
166
172
|
}
|
|
167
173
|
static isBrowserObjectArg(value) {
|
|
168
|
-
return
|
|
174
|
+
return TypeValidator.isObject(value) && ColorinoBrowserObject in value;
|
|
169
175
|
}
|
|
170
176
|
static isAnsiColoredString(value) {
|
|
171
|
-
return TypeValidator.isString(value) && /\x1b\[[0-9;]*m/.test(value);
|
|
177
|
+
return TypeValidator.isString(value) && /\x1b\[[0-9;]*m/.test(value.toString());
|
|
172
178
|
}
|
|
173
179
|
static isFormattableObject(value) {
|
|
174
|
-
return TypeValidator.isObject(value) && !TypeValidator.isError(value) && !TypeValidator.isBrowserColorizedArg(value);
|
|
180
|
+
return TypeValidator.isObject(value) && !TypeValidator.isError(value) && !TypeValidator.isBrowserColorizedArg(value) && !TypeValidator.isString(value);
|
|
181
|
+
}
|
|
182
|
+
static isConsoleMethod(level) {
|
|
183
|
+
return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
|
|
175
184
|
}
|
|
176
185
|
}
|
|
177
186
|
|
|
@@ -236,9 +245,6 @@ class MyColorino {
|
|
|
236
245
|
}
|
|
237
246
|
return `${ansiPrefix}${text}\x1B[0m`;
|
|
238
247
|
}
|
|
239
|
-
_isAnsiColoredString(value) {
|
|
240
|
-
return typeof value === "string" && /\x1b\[[0-9;]*m/.test(value);
|
|
241
|
-
}
|
|
242
248
|
_applyResolvedTheme(resolvedTheme) {
|
|
243
249
|
const themeOpt = this._options.theme ?? "auto";
|
|
244
250
|
const baseThemeName = determineBaseTheme(themeOpt, resolvedTheme);
|
|
@@ -263,34 +269,35 @@ class MyColorino {
|
|
|
263
269
|
}
|
|
264
270
|
_formatValue(value, maxDepth = this._options.maxDepth ?? 5) {
|
|
265
271
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
272
|
+
const sanitizeArray = (items, currentDepth) => {
|
|
273
|
+
return items.map((item) => sanitize(item, currentDepth));
|
|
274
|
+
};
|
|
275
|
+
const sanitizeObject = (obj, currentDepth) => {
|
|
276
|
+
const result = {};
|
|
277
|
+
for (const key in obj) {
|
|
278
|
+
result[key] = sanitize(obj[key], currentDepth);
|
|
279
|
+
}
|
|
280
|
+
return result;
|
|
281
|
+
};
|
|
266
282
|
const sanitize = (val, currentDepth) => {
|
|
267
|
-
if (val
|
|
283
|
+
if (TypeValidator.isNullOrUndefined(val) || !TypeValidator.isObject(val)) {
|
|
284
|
+
return val;
|
|
285
|
+
}
|
|
268
286
|
if (seen.has(val)) return "[Circular]";
|
|
269
287
|
seen.add(val);
|
|
270
288
|
if (currentDepth >= maxDepth) return "[Object]";
|
|
271
|
-
|
|
272
|
-
|
|
289
|
+
const nextDepth = currentDepth + 1;
|
|
290
|
+
if (TypeValidator.isArray(val)) {
|
|
291
|
+
return sanitizeArray(val, nextDepth);
|
|
273
292
|
}
|
|
274
|
-
|
|
275
|
-
for (const key in val) {
|
|
276
|
-
result[key] = sanitize(
|
|
277
|
-
val[key],
|
|
278
|
-
currentDepth + 1
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
return result;
|
|
293
|
+
return sanitizeObject(val, nextDepth);
|
|
282
294
|
};
|
|
283
295
|
return JSON.stringify(sanitize(value, 0), null, 2);
|
|
284
296
|
}
|
|
285
|
-
_normalizeString(value) {
|
|
286
|
-
if (value instanceof String) return value.valueOf();
|
|
287
|
-
return value;
|
|
288
|
-
}
|
|
289
297
|
_processArgs(args) {
|
|
290
298
|
const processedArgs = [];
|
|
291
299
|
let previousWasObject = false;
|
|
292
|
-
for (const
|
|
293
|
-
const arg = this._normalizeString(rawArg);
|
|
300
|
+
for (const arg of args) {
|
|
294
301
|
if (TypeValidator.isBrowserColorizedArg(arg)) {
|
|
295
302
|
processedArgs.push(arg);
|
|
296
303
|
previousWasObject = false;
|
|
@@ -327,8 +334,7 @@ ${arg}`);
|
|
|
327
334
|
const cssArgs = [];
|
|
328
335
|
const otherArgs = [];
|
|
329
336
|
const paletteHex = this._palette[consoleMethod];
|
|
330
|
-
for (const
|
|
331
|
-
const arg = this._normalizeString(rawArg);
|
|
337
|
+
for (const arg of args) {
|
|
332
338
|
if (TypeValidator.isBrowserColorizedArg(arg)) {
|
|
333
339
|
formatParts.push(`%c${arg.text}`);
|
|
334
340
|
cssArgs.push(`color:${arg.hex}`);
|
|
@@ -373,31 +379,21 @@ ${arg}`);
|
|
|
373
379
|
}
|
|
374
380
|
}
|
|
375
381
|
_applyNodeColors(consoleMethod, args) {
|
|
376
|
-
const
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
)
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
if (this._isAnsiColoredString(first)) {
|
|
385
|
-
return coloredArgs;
|
|
386
|
-
}
|
|
387
|
-
const hex = this._palette[consoleMethod];
|
|
388
|
-
const ansiPrefix = this._toAnsiPrefix(hex);
|
|
389
|
-
if (!ansiPrefix) {
|
|
390
|
-
return coloredArgs;
|
|
391
|
-
}
|
|
392
|
-
coloredArgs[firstStringIndex] = `${ansiPrefix}${String(first)}\x1B[0m`;
|
|
393
|
-
return coloredArgs;
|
|
382
|
+
const paletteHex = this._palette[consoleMethod];
|
|
383
|
+
const paletteAnsiPrefix = this._toAnsiPrefix(paletteHex);
|
|
384
|
+
if (!paletteAnsiPrefix) return args;
|
|
385
|
+
return args.map((arg) => {
|
|
386
|
+
if (!TypeValidator.isString(arg) || TypeValidator.isAnsiColoredString(arg))
|
|
387
|
+
return arg;
|
|
388
|
+
return `${paletteAnsiPrefix}${String(arg)}\x1B[0m`;
|
|
389
|
+
});
|
|
394
390
|
}
|
|
395
391
|
_output(consoleMethod, args) {
|
|
396
392
|
if (consoleMethod === "trace") this._printCleanTrace(args);
|
|
397
393
|
else console[consoleMethod](...args);
|
|
398
394
|
}
|
|
399
395
|
_out(level, args) {
|
|
400
|
-
const consoleMethod = isConsoleMethod(level) ? level : "log";
|
|
396
|
+
const consoleMethod = TypeValidator.isConsoleMethod(level) ? level : "log";
|
|
401
397
|
const processedArgs = this._processArgs(args);
|
|
402
398
|
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
403
399
|
this._output(consoleMethod, processedArgs);
|
|
@@ -57,9 +57,6 @@ var ColorLevel = /* @__PURE__ */ ((ColorLevel2) => {
|
|
|
57
57
|
return ColorLevel2;
|
|
58
58
|
})(ColorLevel || {});
|
|
59
59
|
|
|
60
|
-
function isConsoleMethod(level) {
|
|
61
|
-
return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
|
|
62
|
-
}
|
|
63
60
|
const ColorinoBrowserColorized = Symbol("colorino.browserColorized");
|
|
64
61
|
const ColorinoBrowserObject = Symbol("colorino.browserObject");
|
|
65
62
|
|
|
@@ -150,26 +147,38 @@ class TypeValidator {
|
|
|
150
147
|
static isNull(value) {
|
|
151
148
|
return value === null;
|
|
152
149
|
}
|
|
150
|
+
static isUndefined(value) {
|
|
151
|
+
return value === void 0;
|
|
152
|
+
}
|
|
153
|
+
static isNullOrUndefined(value) {
|
|
154
|
+
return value == null;
|
|
155
|
+
}
|
|
153
156
|
static isObject(value) {
|
|
154
157
|
return typeof value === "object" && value !== null;
|
|
155
158
|
}
|
|
156
159
|
static isString(value) {
|
|
157
|
-
return typeof value === "string";
|
|
160
|
+
return typeof value === "string" || value instanceof String;
|
|
161
|
+
}
|
|
162
|
+
static isArray(value) {
|
|
163
|
+
return Array.isArray(value);
|
|
158
164
|
}
|
|
159
165
|
static isError(value) {
|
|
160
166
|
return value instanceof Error;
|
|
161
167
|
}
|
|
162
168
|
static isBrowserColorizedArg(value) {
|
|
163
|
-
return
|
|
169
|
+
return TypeValidator.isObject(value) && ColorinoBrowserColorized in value;
|
|
164
170
|
}
|
|
165
171
|
static isBrowserObjectArg(value) {
|
|
166
|
-
return
|
|
172
|
+
return TypeValidator.isObject(value) && ColorinoBrowserObject in value;
|
|
167
173
|
}
|
|
168
174
|
static isAnsiColoredString(value) {
|
|
169
|
-
return TypeValidator.isString(value) && /\x1b\[[0-9;]*m/.test(value);
|
|
175
|
+
return TypeValidator.isString(value) && /\x1b\[[0-9;]*m/.test(value.toString());
|
|
170
176
|
}
|
|
171
177
|
static isFormattableObject(value) {
|
|
172
|
-
return TypeValidator.isObject(value) && !TypeValidator.isError(value) && !TypeValidator.isBrowserColorizedArg(value);
|
|
178
|
+
return TypeValidator.isObject(value) && !TypeValidator.isError(value) && !TypeValidator.isBrowserColorizedArg(value) && !TypeValidator.isString(value);
|
|
179
|
+
}
|
|
180
|
+
static isConsoleMethod(level) {
|
|
181
|
+
return ["log", "info", "warn", "error", "trace", "debug"].includes(level);
|
|
173
182
|
}
|
|
174
183
|
}
|
|
175
184
|
|
|
@@ -234,9 +243,6 @@ class MyColorino {
|
|
|
234
243
|
}
|
|
235
244
|
return `${ansiPrefix}${text}\x1B[0m`;
|
|
236
245
|
}
|
|
237
|
-
_isAnsiColoredString(value) {
|
|
238
|
-
return typeof value === "string" && /\x1b\[[0-9;]*m/.test(value);
|
|
239
|
-
}
|
|
240
246
|
_applyResolvedTheme(resolvedTheme) {
|
|
241
247
|
const themeOpt = this._options.theme ?? "auto";
|
|
242
248
|
const baseThemeName = determineBaseTheme(themeOpt, resolvedTheme);
|
|
@@ -261,34 +267,35 @@ class MyColorino {
|
|
|
261
267
|
}
|
|
262
268
|
_formatValue(value, maxDepth = this._options.maxDepth ?? 5) {
|
|
263
269
|
const seen = /* @__PURE__ */ new WeakSet();
|
|
270
|
+
const sanitizeArray = (items, currentDepth) => {
|
|
271
|
+
return items.map((item) => sanitize(item, currentDepth));
|
|
272
|
+
};
|
|
273
|
+
const sanitizeObject = (obj, currentDepth) => {
|
|
274
|
+
const result = {};
|
|
275
|
+
for (const key in obj) {
|
|
276
|
+
result[key] = sanitize(obj[key], currentDepth);
|
|
277
|
+
}
|
|
278
|
+
return result;
|
|
279
|
+
};
|
|
264
280
|
const sanitize = (val, currentDepth) => {
|
|
265
|
-
if (val
|
|
281
|
+
if (TypeValidator.isNullOrUndefined(val) || !TypeValidator.isObject(val)) {
|
|
282
|
+
return val;
|
|
283
|
+
}
|
|
266
284
|
if (seen.has(val)) return "[Circular]";
|
|
267
285
|
seen.add(val);
|
|
268
286
|
if (currentDepth >= maxDepth) return "[Object]";
|
|
269
|
-
|
|
270
|
-
|
|
287
|
+
const nextDepth = currentDepth + 1;
|
|
288
|
+
if (TypeValidator.isArray(val)) {
|
|
289
|
+
return sanitizeArray(val, nextDepth);
|
|
271
290
|
}
|
|
272
|
-
|
|
273
|
-
for (const key in val) {
|
|
274
|
-
result[key] = sanitize(
|
|
275
|
-
val[key],
|
|
276
|
-
currentDepth + 1
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
return result;
|
|
291
|
+
return sanitizeObject(val, nextDepth);
|
|
280
292
|
};
|
|
281
293
|
return JSON.stringify(sanitize(value, 0), null, 2);
|
|
282
294
|
}
|
|
283
|
-
_normalizeString(value) {
|
|
284
|
-
if (value instanceof String) return value.valueOf();
|
|
285
|
-
return value;
|
|
286
|
-
}
|
|
287
295
|
_processArgs(args) {
|
|
288
296
|
const processedArgs = [];
|
|
289
297
|
let previousWasObject = false;
|
|
290
|
-
for (const
|
|
291
|
-
const arg = this._normalizeString(rawArg);
|
|
298
|
+
for (const arg of args) {
|
|
292
299
|
if (TypeValidator.isBrowserColorizedArg(arg)) {
|
|
293
300
|
processedArgs.push(arg);
|
|
294
301
|
previousWasObject = false;
|
|
@@ -325,8 +332,7 @@ ${arg}`);
|
|
|
325
332
|
const cssArgs = [];
|
|
326
333
|
const otherArgs = [];
|
|
327
334
|
const paletteHex = this._palette[consoleMethod];
|
|
328
|
-
for (const
|
|
329
|
-
const arg = this._normalizeString(rawArg);
|
|
335
|
+
for (const arg of args) {
|
|
330
336
|
if (TypeValidator.isBrowserColorizedArg(arg)) {
|
|
331
337
|
formatParts.push(`%c${arg.text}`);
|
|
332
338
|
cssArgs.push(`color:${arg.hex}`);
|
|
@@ -371,31 +377,21 @@ ${arg}`);
|
|
|
371
377
|
}
|
|
372
378
|
}
|
|
373
379
|
_applyNodeColors(consoleMethod, args) {
|
|
374
|
-
const
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
)
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
if (this._isAnsiColoredString(first)) {
|
|
383
|
-
return coloredArgs;
|
|
384
|
-
}
|
|
385
|
-
const hex = this._palette[consoleMethod];
|
|
386
|
-
const ansiPrefix = this._toAnsiPrefix(hex);
|
|
387
|
-
if (!ansiPrefix) {
|
|
388
|
-
return coloredArgs;
|
|
389
|
-
}
|
|
390
|
-
coloredArgs[firstStringIndex] = `${ansiPrefix}${String(first)}\x1B[0m`;
|
|
391
|
-
return coloredArgs;
|
|
380
|
+
const paletteHex = this._palette[consoleMethod];
|
|
381
|
+
const paletteAnsiPrefix = this._toAnsiPrefix(paletteHex);
|
|
382
|
+
if (!paletteAnsiPrefix) return args;
|
|
383
|
+
return args.map((arg) => {
|
|
384
|
+
if (!TypeValidator.isString(arg) || TypeValidator.isAnsiColoredString(arg))
|
|
385
|
+
return arg;
|
|
386
|
+
return `${paletteAnsiPrefix}${String(arg)}\x1B[0m`;
|
|
387
|
+
});
|
|
392
388
|
}
|
|
393
389
|
_output(consoleMethod, args) {
|
|
394
390
|
if (consoleMethod === "trace") this._printCleanTrace(args);
|
|
395
391
|
else console[consoleMethod](...args);
|
|
396
392
|
}
|
|
397
393
|
_out(level, args) {
|
|
398
|
-
const consoleMethod = isConsoleMethod(level) ? level : "log";
|
|
394
|
+
const consoleMethod = TypeValidator.isConsoleMethod(level) ? level : "log";
|
|
399
395
|
const processedArgs = this._processArgs(args);
|
|
400
396
|
if (this._colorLevel === ColorLevel.NO_COLOR || this._colorLevel === "UnknownEnv") {
|
|
401
397
|
this._output(consoleMethod, processedArgs);
|