@visulima/pail 4.0.0-alpha.4 → 4.0.0-alpha.6
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/CHANGELOG.md +40 -0
- package/LICENSE.md +4 -4
- package/dist/index.browser.js +1488 -2
- package/dist/index.server.js +2656 -12
- package/dist/interactive/index.js +2 -2
- package/dist/packem_shared/AbstractJsonReporter-DWRpTtGw.js +204 -0
- package/dist/packem_shared/{InteractiveManager-CbE7d1kY.js → InteractiveManager-Cd6A14ZK.js} +1 -1
- package/dist/packem_shared/{interactive-stream-hook-DG4BtN12.js → InteractiveStreamHook-ePIURL_U.js} +1 -9
- package/dist/packem_shared/{JsonReporter-VzgyLEYz.js → JsonReporter-BV5lMnJX.js} +1 -1
- package/dist/packem_shared/{PrettyReporter-DySIXBjQ.js → PrettyReporter-BYL3NrdA.js} +49 -4
- package/dist/packem_shared/{format-label-De49vNPd.js → PrettyReporter-BjXCFQlo.js} +268 -3
- package/dist/packem_shared/Spinner-DIdVcfWq.js +2183 -0
- package/dist/packem_shared/abstract-pretty-reporter-jU8WL_6c.js +2602 -0
- package/dist/packem_shared/constants-B1RjD_ps.js +99 -0
- package/dist/packem_shared/getBarChar-BWj1UrH3.js +404 -0
- package/dist/packem_shared/{index-BomQ3E6J.js → index-DnkF86LQ.js} +9 -1
- package/dist/packem_shared/{index-EZ_WSQZS.js → index-frijFf5m.js} +120 -14
- package/dist/processor/message-formatter-processor.js +648 -1
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.js +1 -1
- package/dist/reporter/json/index.js +2 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.js +2 -7
- package/dist/spinner.js +34 -1
- package/package.json +4 -4
- package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +0 -21
- package/dist/packem_shared/PrettyReporter-C2wVB7yu.js +0 -222
- package/dist/packem_shared/abstract-pretty-reporter-Di_sdm2r.js +0 -50
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +0 -9
- package/dist/packem_shared/pail.browser-u2CSR_af.js +0 -1427
package/dist/index.server.js
CHANGED
|
@@ -4,23 +4,1752 @@ const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
|
4
4
|
|
|
5
5
|
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
6
|
|
|
7
|
+
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
+
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
+
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
+
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
+
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
+
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
+
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// Fallback to createRequire
|
|
17
|
+
return __cjs_require(module);
|
|
18
|
+
};
|
|
19
|
+
|
|
7
20
|
const {
|
|
8
21
|
stdout,
|
|
9
22
|
stderr,
|
|
10
23
|
env
|
|
11
24
|
} = __cjs_getProcess;
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
import { t as terminalSize, w as wordWrap, W as WrapMode, g as getLongestLabel, E as EXTENDED_RFC_5424_LOG_LEVELS, a as EMPTY_SYMBOL, L as LOG_TYPES, i as inspect, b as writeStream, A as AbstractPrettyReporter, d as defaultInspectorConfig, c as getLongestBadge, e as getStringWidth, f as formatLabel, r as renderError } from './packem_shared/abstract-pretty-reporter-jU8WL_6c.js';
|
|
26
|
+
const {
|
|
27
|
+
StringDecoder
|
|
28
|
+
} = __cjs_getBuiltinModule("node:string_decoder");
|
|
29
|
+
import { ProgressBar, applyStyleToOptions, MultiProgressBar } from './packem_shared/getBarChar-BWj1UrH3.js';
|
|
30
|
+
export { getBarChar } from './packem_shared/getBarChar-BWj1UrH3.js';
|
|
31
|
+
import { Spinner, MultiSpinner } from './packem_shared/Spinner-DIdVcfWq.js';
|
|
32
|
+
import colorize, { red, greenBright, cyan, green, grey, bgGrey, underline, white } from '@visulima/colorize';
|
|
33
|
+
|
|
34
|
+
class InteractiveManager {
|
|
35
|
+
#stream;
|
|
36
|
+
#isActive = false;
|
|
37
|
+
#isSuspended = false;
|
|
38
|
+
#lastLength = 0;
|
|
39
|
+
#outside = 0;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new InteractiveManager with the given stream hooks.
|
|
42
|
+
* @param stdout Hook for stdout stream
|
|
43
|
+
* @param stderr Hook for stderr stream
|
|
44
|
+
*/
|
|
45
|
+
constructor(stdout, stderr) {
|
|
46
|
+
this.#stream = {
|
|
47
|
+
stderr,
|
|
48
|
+
stdout
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Last printed rows count.
|
|
53
|
+
*
|
|
54
|
+
* Tracks the number of rows that were last written to the terminal.
|
|
55
|
+
* Used internally for managing cursor positioning and output updates.
|
|
56
|
+
*/
|
|
57
|
+
get lastLength() {
|
|
58
|
+
return this.#lastLength;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Rows count outside editable area.
|
|
62
|
+
*
|
|
63
|
+
* Tracks the number of rows that extend beyond the current terminal height.
|
|
64
|
+
* Used for managing scrolling and ensuring all output remains visible.
|
|
65
|
+
*/
|
|
66
|
+
get outside() {
|
|
67
|
+
return this.#outside;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Hook activity status.
|
|
71
|
+
*
|
|
72
|
+
* Indicates whether the interactive hooks are currently active.
|
|
73
|
+
* When true, streams are being intercepted for interactive output.
|
|
74
|
+
*/
|
|
75
|
+
get isHooked() {
|
|
76
|
+
return this.#isActive;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Suspend status for active hooks.
|
|
80
|
+
*
|
|
81
|
+
* Indicates whether interactive mode is temporarily suspended.
|
|
82
|
+
* When suspended, external output can be written without interference.
|
|
83
|
+
*/
|
|
84
|
+
get isSuspended() {
|
|
85
|
+
return this.#isSuspended;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Removes lines from the terminal output.
|
|
89
|
+
*
|
|
90
|
+
* Erases the specified number of lines from the bottom of the output,
|
|
91
|
+
* moving the cursor up and clearing the lines. Useful for removing
|
|
92
|
+
* previous interactive output before displaying new content.
|
|
93
|
+
* @param stream The stream to erase lines from ("stdout" or "stderr")
|
|
94
|
+
* @param count Number of lines to remove (defaults to lastLength)
|
|
95
|
+
* @throws {TypeError} If the specified stream is not available
|
|
96
|
+
*/
|
|
97
|
+
erase(stream, count = this.#lastLength) {
|
|
98
|
+
if (this.#stream[stream] === void 0) {
|
|
99
|
+
throw new TypeError(`Stream "${stream}" is not available`);
|
|
100
|
+
}
|
|
101
|
+
this.#stream[stream].erase(count);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Hook stdout and stderr streams.
|
|
105
|
+
* @returns Success status
|
|
106
|
+
*/
|
|
107
|
+
hook() {
|
|
108
|
+
if (!this.#isActive) {
|
|
109
|
+
Object.values(this.#stream).forEach((hook) => hook.active());
|
|
110
|
+
this.#clear(true);
|
|
111
|
+
}
|
|
112
|
+
return this.#isActive;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Resume suspend hooks.
|
|
116
|
+
* @param stream Stream to resume
|
|
117
|
+
* @param eraseRowCount erase output rows count
|
|
118
|
+
*/
|
|
119
|
+
resume(stream, eraseRowCount) {
|
|
120
|
+
if (this.#isSuspended) {
|
|
121
|
+
this.#isSuspended = false;
|
|
122
|
+
if (eraseRowCount) {
|
|
123
|
+
this.erase(stream, eraseRowCount);
|
|
124
|
+
}
|
|
125
|
+
this.#lastLength = 0;
|
|
126
|
+
Object.values(this.#stream).forEach((hook) => hook.active());
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Suspend active hooks for external output.
|
|
131
|
+
* @param stream Stream to suspend
|
|
132
|
+
* @param erase erase output
|
|
133
|
+
*/
|
|
134
|
+
suspend(stream, erase = true) {
|
|
135
|
+
if (!this.#isSuspended) {
|
|
136
|
+
this.#isSuspended = true;
|
|
137
|
+
if (erase) {
|
|
138
|
+
this.erase(stream);
|
|
139
|
+
}
|
|
140
|
+
Object.values(this.#stream).forEach((hook) => hook.renew());
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Unhooks both stdout and stderr streams and print their story of logs.
|
|
145
|
+
* @param separateHistory If `true`, will add an empty line to the history output for individual recorded lines and console logs
|
|
146
|
+
* @returns Success status
|
|
147
|
+
*/
|
|
148
|
+
unhook(separateHistory = true) {
|
|
149
|
+
if (this.#isActive) {
|
|
150
|
+
Object.values(this.#stream).forEach((hook) => hook.inactive(separateHistory));
|
|
151
|
+
this.#clear();
|
|
152
|
+
}
|
|
153
|
+
return !this.#isActive;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Update output.
|
|
157
|
+
* @param stream Stream to write to
|
|
158
|
+
* @param rows Text lines to write to standard output
|
|
159
|
+
* @param from Index of the line starting from which the contents of the terminal are being overwritten
|
|
160
|
+
*/
|
|
161
|
+
update(stream, rows, from = 0) {
|
|
162
|
+
if (rows.length > 0) {
|
|
163
|
+
if (this.#stream[stream] === void 0) {
|
|
164
|
+
throw new TypeError(`Stream "${stream}" is not available`);
|
|
165
|
+
}
|
|
166
|
+
const hook = this.#stream[stream];
|
|
167
|
+
const { columns: width, rows: height } = terminalSize();
|
|
168
|
+
const position = from > height ? height - 1 : Math.max(0, Math.min(height - 1, from));
|
|
169
|
+
const actualLength = this.lastLength - position;
|
|
170
|
+
const outside = Math.max(actualLength - height, this.outside);
|
|
171
|
+
let output = rows.reduce(
|
|
172
|
+
(accumulator, row) => [
|
|
173
|
+
...accumulator,
|
|
174
|
+
wordWrap(row, {
|
|
175
|
+
trim: false,
|
|
176
|
+
width,
|
|
177
|
+
wrapMode: WrapMode.STRICT_WIDTH
|
|
178
|
+
})
|
|
179
|
+
],
|
|
180
|
+
[]
|
|
181
|
+
);
|
|
182
|
+
if (height <= actualLength) {
|
|
183
|
+
hook.erase(height);
|
|
184
|
+
if (position < outside) {
|
|
185
|
+
output = output.slice(outside - position + 1);
|
|
186
|
+
}
|
|
187
|
+
} else if (actualLength) {
|
|
188
|
+
hook.erase(actualLength);
|
|
189
|
+
}
|
|
190
|
+
hook.write(`${output.join("\n")}
|
|
191
|
+
`);
|
|
192
|
+
this.#lastLength = outside ? outside + output.length + 1 : output.length;
|
|
193
|
+
this.#outside = Math.max(this.lastLength - height, this.outside);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
#clear(status = false) {
|
|
197
|
+
this.#isActive = status;
|
|
198
|
+
this.#lastLength = 0;
|
|
199
|
+
this.#outside = 0;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const ESC = "\x1B[";
|
|
204
|
+
const eraseScreen = `${ESC}2J`;
|
|
205
|
+
const eraseLine = `${ESC}2K`;
|
|
206
|
+
const cursorLeft = `${ESC}G`;
|
|
207
|
+
const cursorUp = (count = 1) => `${ESC + count}A`;
|
|
208
|
+
const clearTerminal = process.platform === "win32" ? `${eraseScreen}${ESC}0f` : (
|
|
209
|
+
// 1. Erases the screen (Only done in case `2` is not supported)
|
|
210
|
+
// 2. Erases the whole screen including scrollback buffer
|
|
211
|
+
// 3. Moves cursor to the top-left position
|
|
212
|
+
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
|
|
213
|
+
`${eraseScreen}${ESC}3J${ESC}H`
|
|
214
|
+
);
|
|
215
|
+
const cursorHide = `${ESC}?25l`;
|
|
216
|
+
const cursorShow = `${ESC}?25h`;
|
|
217
|
+
const eraseLines = (count) => {
|
|
218
|
+
let clear = "";
|
|
219
|
+
for (let index = 0; index < count; index++) {
|
|
220
|
+
clear += eraseLine + (index < count - 1 ? cursorUp() : "");
|
|
221
|
+
}
|
|
222
|
+
if (count) {
|
|
223
|
+
clear += cursorLeft;
|
|
224
|
+
}
|
|
225
|
+
return clear;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
class InteractiveStreamHook {
|
|
229
|
+
/** Constant indicating the stream write operation was successful */
|
|
230
|
+
static DRAIN = true;
|
|
231
|
+
#decoder = new StringDecoder();
|
|
232
|
+
#history = [];
|
|
233
|
+
#method;
|
|
234
|
+
#stream;
|
|
235
|
+
/**
|
|
236
|
+
* Creates a new InteractiveStreamHook for the given stream.
|
|
237
|
+
* @param stream The Node.js WriteStream to hook into (usually stdout or stderr)
|
|
238
|
+
*/
|
|
239
|
+
constructor(stream) {
|
|
240
|
+
this.#method = stream.write;
|
|
241
|
+
this.#stream = stream;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Activates the stream hook.
|
|
245
|
+
*
|
|
246
|
+
* When active, all writes to the stream are captured in history instead of
|
|
247
|
+
* being written immediately. This allows for interactive features like
|
|
248
|
+
* progress bars that can update dynamically.
|
|
249
|
+
*/
|
|
250
|
+
active() {
|
|
251
|
+
this.write(cursorHide);
|
|
252
|
+
this.#stream.write = (data, ...arguments_) => {
|
|
253
|
+
const callback = arguments_.at(-1);
|
|
254
|
+
this.#history.push(
|
|
255
|
+
// prettier-ignore
|
|
256
|
+
this.#decoder.write(
|
|
257
|
+
typeof data === "string" ? Buffer.from(data, typeof arguments_[0] === "string" ? arguments_[0] : void 0) : Buffer.from(data)
|
|
258
|
+
)
|
|
259
|
+
);
|
|
260
|
+
if (typeof callback === "function") {
|
|
261
|
+
callback();
|
|
262
|
+
}
|
|
263
|
+
return InteractiveStreamHook.DRAIN;
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Erases the specified number of lines from the terminal.
|
|
268
|
+
*
|
|
269
|
+
* Uses ANSI escape sequences to remove lines from the current cursor position
|
|
270
|
+
* upwards, which is useful for clearing previous output in interactive applications.
|
|
271
|
+
* @param count Number of lines to erase (including the current line)
|
|
272
|
+
*/
|
|
273
|
+
erase(count) {
|
|
274
|
+
if (count > 0) {
|
|
275
|
+
this.write(eraseLines(count + 1));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Deactivates the stream hook and replays captured output.
|
|
280
|
+
*
|
|
281
|
+
* Restores normal stream operation and outputs all captured history.
|
|
282
|
+
* Optionally adds a newline separator before replaying the history.
|
|
283
|
+
* @param separateHistory Whether to add a newline before replaying history
|
|
284
|
+
*/
|
|
285
|
+
inactive(separateHistory = false) {
|
|
286
|
+
if (this.#history.length > 0) {
|
|
287
|
+
if (separateHistory) {
|
|
288
|
+
this.write("\n");
|
|
289
|
+
}
|
|
290
|
+
this.#history.forEach((element) => {
|
|
291
|
+
this.write(element);
|
|
292
|
+
});
|
|
293
|
+
this.#history = [];
|
|
294
|
+
}
|
|
295
|
+
this.renew();
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Renews the stream hook state.
|
|
299
|
+
*
|
|
300
|
+
* Restores the original stream write method and shows the cursor.
|
|
301
|
+
* This is typically called when temporarily suspending interactive mode.
|
|
302
|
+
*/
|
|
303
|
+
renew() {
|
|
304
|
+
this.#stream.write = this.#method;
|
|
305
|
+
this.write(cursorShow);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Writes a message directly to the underlying stream.
|
|
309
|
+
*
|
|
310
|
+
* Bypasses the hook mechanism and writes directly using the original
|
|
311
|
+
* stream write method. Useful for writing control sequences or
|
|
312
|
+
* messages that should not be captured in history.
|
|
313
|
+
* @param message The message to write to the stream
|
|
314
|
+
*/
|
|
315
|
+
write(message) {
|
|
316
|
+
this.#method.apply(this.#stream, [message]);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function getDefaultExportFromCjs (x) {
|
|
321
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
var safeStableStringify = {exports: {}};
|
|
325
|
+
|
|
326
|
+
var hasRequiredSafeStableStringify;
|
|
327
|
+
|
|
328
|
+
function requireSafeStableStringify () {
|
|
329
|
+
if (hasRequiredSafeStableStringify) return safeStableStringify.exports;
|
|
330
|
+
hasRequiredSafeStableStringify = 1;
|
|
331
|
+
(function (module, exports$1) {
|
|
332
|
+
const { hasOwnProperty } = Object.prototype;
|
|
333
|
+
const stringify = configure();
|
|
334
|
+
stringify.configure = configure;
|
|
335
|
+
stringify.stringify = stringify;
|
|
336
|
+
stringify.default = stringify;
|
|
337
|
+
exports$1.stringify = stringify;
|
|
338
|
+
exports$1.configure = configure;
|
|
339
|
+
module.exports = stringify;
|
|
340
|
+
const strEscapeSequencesRegExp = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;
|
|
341
|
+
function strEscape(str) {
|
|
342
|
+
if (str.length < 5e3 && !strEscapeSequencesRegExp.test(str)) {
|
|
343
|
+
return `"${str}"`;
|
|
344
|
+
}
|
|
345
|
+
return JSON.stringify(str);
|
|
346
|
+
}
|
|
347
|
+
function sort(array, comparator) {
|
|
348
|
+
if (array.length > 200 || comparator) {
|
|
349
|
+
return array.sort(comparator);
|
|
350
|
+
}
|
|
351
|
+
for (let i = 1; i < array.length; i++) {
|
|
352
|
+
const currentValue = array[i];
|
|
353
|
+
let position = i;
|
|
354
|
+
while (position !== 0 && array[position - 1] > currentValue) {
|
|
355
|
+
array[position] = array[position - 1];
|
|
356
|
+
position--;
|
|
357
|
+
}
|
|
358
|
+
array[position] = currentValue;
|
|
359
|
+
}
|
|
360
|
+
return array;
|
|
361
|
+
}
|
|
362
|
+
const typedArrayPrototypeGetSymbolToStringTag = Object.getOwnPropertyDescriptor(
|
|
363
|
+
Object.getPrototypeOf(
|
|
364
|
+
Object.getPrototypeOf(
|
|
365
|
+
new Int8Array()
|
|
366
|
+
)
|
|
367
|
+
),
|
|
368
|
+
Symbol.toStringTag
|
|
369
|
+
).get;
|
|
370
|
+
function isTypedArrayWithEntries(value) {
|
|
371
|
+
return typedArrayPrototypeGetSymbolToStringTag.call(value) !== void 0 && value.length !== 0;
|
|
372
|
+
}
|
|
373
|
+
function stringifyTypedArray(array, separator, maximumBreadth) {
|
|
374
|
+
if (array.length < maximumBreadth) {
|
|
375
|
+
maximumBreadth = array.length;
|
|
376
|
+
}
|
|
377
|
+
const whitespace = separator === "," ? "" : " ";
|
|
378
|
+
let res = `"0":${whitespace}${array[0]}`;
|
|
379
|
+
for (let i = 1; i < maximumBreadth; i++) {
|
|
380
|
+
res += `${separator}"${i}":${whitespace}${array[i]}`;
|
|
381
|
+
}
|
|
382
|
+
return res;
|
|
383
|
+
}
|
|
384
|
+
function getCircularValueOption(options) {
|
|
385
|
+
if (hasOwnProperty.call(options, "circularValue")) {
|
|
386
|
+
const circularValue = options.circularValue;
|
|
387
|
+
if (typeof circularValue === "string") {
|
|
388
|
+
return `"${circularValue}"`;
|
|
389
|
+
}
|
|
390
|
+
if (circularValue == null) {
|
|
391
|
+
return circularValue;
|
|
392
|
+
}
|
|
393
|
+
if (circularValue === Error || circularValue === TypeError) {
|
|
394
|
+
return {
|
|
395
|
+
toString() {
|
|
396
|
+
throw new TypeError("Converting circular structure to JSON");
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined');
|
|
401
|
+
}
|
|
402
|
+
return '"[Circular]"';
|
|
403
|
+
}
|
|
404
|
+
function getDeterministicOption(options) {
|
|
405
|
+
let value;
|
|
406
|
+
if (hasOwnProperty.call(options, "deterministic")) {
|
|
407
|
+
value = options.deterministic;
|
|
408
|
+
if (typeof value !== "boolean" && typeof value !== "function") {
|
|
409
|
+
throw new TypeError('The "deterministic" argument must be of type boolean or comparator function');
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return value === void 0 ? true : value;
|
|
413
|
+
}
|
|
414
|
+
function getBooleanOption(options, key) {
|
|
415
|
+
let value;
|
|
416
|
+
if (hasOwnProperty.call(options, key)) {
|
|
417
|
+
value = options[key];
|
|
418
|
+
if (typeof value !== "boolean") {
|
|
419
|
+
throw new TypeError(`The "${key}" argument must be of type boolean`);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return value === void 0 ? true : value;
|
|
423
|
+
}
|
|
424
|
+
function getPositiveIntegerOption(options, key) {
|
|
425
|
+
let value;
|
|
426
|
+
if (hasOwnProperty.call(options, key)) {
|
|
427
|
+
value = options[key];
|
|
428
|
+
if (typeof value !== "number") {
|
|
429
|
+
throw new TypeError(`The "${key}" argument must be of type number`);
|
|
430
|
+
}
|
|
431
|
+
if (!Number.isInteger(value)) {
|
|
432
|
+
throw new TypeError(`The "${key}" argument must be an integer`);
|
|
433
|
+
}
|
|
434
|
+
if (value < 1) {
|
|
435
|
+
throw new RangeError(`The "${key}" argument must be >= 1`);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return value === void 0 ? Infinity : value;
|
|
439
|
+
}
|
|
440
|
+
function getItemCount(number) {
|
|
441
|
+
if (number === 1) {
|
|
442
|
+
return "1 item";
|
|
443
|
+
}
|
|
444
|
+
return `${number} items`;
|
|
445
|
+
}
|
|
446
|
+
function getUniqueReplacerSet(replacerArray) {
|
|
447
|
+
const replacerSet = /* @__PURE__ */ new Set();
|
|
448
|
+
for (const value of replacerArray) {
|
|
449
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
450
|
+
replacerSet.add(String(value));
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
return replacerSet;
|
|
454
|
+
}
|
|
455
|
+
function getStrictOption(options) {
|
|
456
|
+
if (hasOwnProperty.call(options, "strict")) {
|
|
457
|
+
const value = options.strict;
|
|
458
|
+
if (typeof value !== "boolean") {
|
|
459
|
+
throw new TypeError('The "strict" argument must be of type boolean');
|
|
460
|
+
}
|
|
461
|
+
if (value) {
|
|
462
|
+
return (value2) => {
|
|
463
|
+
let message = `Object can not safely be stringified. Received type ${typeof value2}`;
|
|
464
|
+
if (typeof value2 !== "function") message += ` (${value2.toString()})`;
|
|
465
|
+
throw new Error(message);
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
function configure(options) {
|
|
471
|
+
options = { ...options };
|
|
472
|
+
const fail = getStrictOption(options);
|
|
473
|
+
if (fail) {
|
|
474
|
+
if (options.bigint === void 0) {
|
|
475
|
+
options.bigint = false;
|
|
476
|
+
}
|
|
477
|
+
if (!("circularValue" in options)) {
|
|
478
|
+
options.circularValue = Error;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
const circularValue = getCircularValueOption(options);
|
|
482
|
+
const bigint = getBooleanOption(options, "bigint");
|
|
483
|
+
const deterministic = getDeterministicOption(options);
|
|
484
|
+
const comparator = typeof deterministic === "function" ? deterministic : void 0;
|
|
485
|
+
const maximumDepth = getPositiveIntegerOption(options, "maximumDepth");
|
|
486
|
+
const maximumBreadth = getPositiveIntegerOption(options, "maximumBreadth");
|
|
487
|
+
function stringifyFnReplacer(key, parent, stack, replacer, spacer, indentation) {
|
|
488
|
+
let value = parent[key];
|
|
489
|
+
if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
|
|
490
|
+
value = value.toJSON(key);
|
|
491
|
+
}
|
|
492
|
+
value = replacer.call(parent, key, value);
|
|
493
|
+
switch (typeof value) {
|
|
494
|
+
case "string":
|
|
495
|
+
return strEscape(value);
|
|
496
|
+
case "object": {
|
|
497
|
+
if (value === null) {
|
|
498
|
+
return "null";
|
|
499
|
+
}
|
|
500
|
+
if (stack.indexOf(value) !== -1) {
|
|
501
|
+
return circularValue;
|
|
502
|
+
}
|
|
503
|
+
let res = "";
|
|
504
|
+
let join = ",";
|
|
505
|
+
const originalIndentation = indentation;
|
|
506
|
+
if (Array.isArray(value)) {
|
|
507
|
+
if (value.length === 0) {
|
|
508
|
+
return "[]";
|
|
509
|
+
}
|
|
510
|
+
if (maximumDepth < stack.length + 1) {
|
|
511
|
+
return '"[Array]"';
|
|
512
|
+
}
|
|
513
|
+
stack.push(value);
|
|
514
|
+
if (spacer !== "") {
|
|
515
|
+
indentation += spacer;
|
|
516
|
+
res += `
|
|
517
|
+
${indentation}`;
|
|
518
|
+
join = `,
|
|
519
|
+
${indentation}`;
|
|
520
|
+
}
|
|
521
|
+
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
522
|
+
let i = 0;
|
|
523
|
+
for (; i < maximumValuesToStringify - 1; i++) {
|
|
524
|
+
const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
|
|
525
|
+
res += tmp2 !== void 0 ? tmp2 : "null";
|
|
526
|
+
res += join;
|
|
527
|
+
}
|
|
528
|
+
const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
|
|
529
|
+
res += tmp !== void 0 ? tmp : "null";
|
|
530
|
+
if (value.length - 1 > maximumBreadth) {
|
|
531
|
+
const removedKeys = value.length - maximumBreadth - 1;
|
|
532
|
+
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
|
|
533
|
+
}
|
|
534
|
+
if (spacer !== "") {
|
|
535
|
+
res += `
|
|
536
|
+
${originalIndentation}`;
|
|
537
|
+
}
|
|
538
|
+
stack.pop();
|
|
539
|
+
return `[${res}]`;
|
|
540
|
+
}
|
|
541
|
+
let keys = Object.keys(value);
|
|
542
|
+
const keyLength = keys.length;
|
|
543
|
+
if (keyLength === 0) {
|
|
544
|
+
return "{}";
|
|
545
|
+
}
|
|
546
|
+
if (maximumDepth < stack.length + 1) {
|
|
547
|
+
return '"[Object]"';
|
|
548
|
+
}
|
|
549
|
+
let whitespace = "";
|
|
550
|
+
let separator = "";
|
|
551
|
+
if (spacer !== "") {
|
|
552
|
+
indentation += spacer;
|
|
553
|
+
join = `,
|
|
554
|
+
${indentation}`;
|
|
555
|
+
whitespace = " ";
|
|
556
|
+
}
|
|
557
|
+
const maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
|
|
558
|
+
if (deterministic && !isTypedArrayWithEntries(value)) {
|
|
559
|
+
keys = sort(keys, comparator);
|
|
560
|
+
}
|
|
561
|
+
stack.push(value);
|
|
562
|
+
for (let i = 0; i < maximumPropertiesToStringify; i++) {
|
|
563
|
+
const key2 = keys[i];
|
|
564
|
+
const tmp = stringifyFnReplacer(key2, value, stack, replacer, spacer, indentation);
|
|
565
|
+
if (tmp !== void 0) {
|
|
566
|
+
res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
|
|
567
|
+
separator = join;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
if (keyLength > maximumBreadth) {
|
|
571
|
+
const removedKeys = keyLength - maximumBreadth;
|
|
572
|
+
res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
|
|
573
|
+
separator = join;
|
|
574
|
+
}
|
|
575
|
+
if (spacer !== "" && separator.length > 1) {
|
|
576
|
+
res = `
|
|
577
|
+
${indentation}${res}
|
|
578
|
+
${originalIndentation}`;
|
|
579
|
+
}
|
|
580
|
+
stack.pop();
|
|
581
|
+
return `{${res}}`;
|
|
582
|
+
}
|
|
583
|
+
case "number":
|
|
584
|
+
return isFinite(value) ? String(value) : fail ? fail(value) : "null";
|
|
585
|
+
case "boolean":
|
|
586
|
+
return value === true ? "true" : "false";
|
|
587
|
+
case "undefined":
|
|
588
|
+
return void 0;
|
|
589
|
+
case "bigint":
|
|
590
|
+
if (bigint) {
|
|
591
|
+
return String(value);
|
|
592
|
+
}
|
|
593
|
+
// fallthrough
|
|
594
|
+
default:
|
|
595
|
+
return fail ? fail(value) : void 0;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
function stringifyArrayReplacer(key, value, stack, replacer, spacer, indentation) {
|
|
599
|
+
if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
|
|
600
|
+
value = value.toJSON(key);
|
|
601
|
+
}
|
|
602
|
+
switch (typeof value) {
|
|
603
|
+
case "string":
|
|
604
|
+
return strEscape(value);
|
|
605
|
+
case "object": {
|
|
606
|
+
if (value === null) {
|
|
607
|
+
return "null";
|
|
608
|
+
}
|
|
609
|
+
if (stack.indexOf(value) !== -1) {
|
|
610
|
+
return circularValue;
|
|
611
|
+
}
|
|
612
|
+
const originalIndentation = indentation;
|
|
613
|
+
let res = "";
|
|
614
|
+
let join = ",";
|
|
615
|
+
if (Array.isArray(value)) {
|
|
616
|
+
if (value.length === 0) {
|
|
617
|
+
return "[]";
|
|
618
|
+
}
|
|
619
|
+
if (maximumDepth < stack.length + 1) {
|
|
620
|
+
return '"[Array]"';
|
|
621
|
+
}
|
|
622
|
+
stack.push(value);
|
|
623
|
+
if (spacer !== "") {
|
|
624
|
+
indentation += spacer;
|
|
625
|
+
res += `
|
|
626
|
+
${indentation}`;
|
|
627
|
+
join = `,
|
|
628
|
+
${indentation}`;
|
|
629
|
+
}
|
|
630
|
+
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
631
|
+
let i = 0;
|
|
632
|
+
for (; i < maximumValuesToStringify - 1; i++) {
|
|
633
|
+
const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
|
|
634
|
+
res += tmp2 !== void 0 ? tmp2 : "null";
|
|
635
|
+
res += join;
|
|
636
|
+
}
|
|
637
|
+
const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
|
|
638
|
+
res += tmp !== void 0 ? tmp : "null";
|
|
639
|
+
if (value.length - 1 > maximumBreadth) {
|
|
640
|
+
const removedKeys = value.length - maximumBreadth - 1;
|
|
641
|
+
res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
|
|
642
|
+
}
|
|
643
|
+
if (spacer !== "") {
|
|
644
|
+
res += `
|
|
645
|
+
${originalIndentation}`;
|
|
646
|
+
}
|
|
647
|
+
stack.pop();
|
|
648
|
+
return `[${res}]`;
|
|
649
|
+
}
|
|
650
|
+
stack.push(value);
|
|
651
|
+
let whitespace = "";
|
|
652
|
+
if (spacer !== "") {
|
|
653
|
+
indentation += spacer;
|
|
654
|
+
join = `,
|
|
655
|
+
${indentation}`;
|
|
656
|
+
whitespace = " ";
|
|
657
|
+
}
|
|
658
|
+
let separator = "";
|
|
659
|
+
for (const key2 of replacer) {
|
|
660
|
+
const tmp = stringifyArrayReplacer(key2, value[key2], stack, replacer, spacer, indentation);
|
|
661
|
+
if (tmp !== void 0) {
|
|
662
|
+
res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
|
|
663
|
+
separator = join;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
if (spacer !== "" && separator.length > 1) {
|
|
667
|
+
res = `
|
|
668
|
+
${indentation}${res}
|
|
669
|
+
${originalIndentation}`;
|
|
670
|
+
}
|
|
671
|
+
stack.pop();
|
|
672
|
+
return `{${res}}`;
|
|
673
|
+
}
|
|
674
|
+
case "number":
|
|
675
|
+
return isFinite(value) ? String(value) : fail ? fail(value) : "null";
|
|
676
|
+
case "boolean":
|
|
677
|
+
return value === true ? "true" : "false";
|
|
678
|
+
case "undefined":
|
|
679
|
+
return void 0;
|
|
680
|
+
case "bigint":
|
|
681
|
+
if (bigint) {
|
|
682
|
+
return String(value);
|
|
683
|
+
}
|
|
684
|
+
// fallthrough
|
|
685
|
+
default:
|
|
686
|
+
return fail ? fail(value) : void 0;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function stringifyIndent(key, value, stack, spacer, indentation) {
|
|
690
|
+
switch (typeof value) {
|
|
691
|
+
case "string":
|
|
692
|
+
return strEscape(value);
|
|
693
|
+
case "object": {
|
|
694
|
+
if (value === null) {
|
|
695
|
+
return "null";
|
|
696
|
+
}
|
|
697
|
+
if (typeof value.toJSON === "function") {
|
|
698
|
+
value = value.toJSON(key);
|
|
699
|
+
if (typeof value !== "object") {
|
|
700
|
+
return stringifyIndent(key, value, stack, spacer, indentation);
|
|
701
|
+
}
|
|
702
|
+
if (value === null) {
|
|
703
|
+
return "null";
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
if (stack.indexOf(value) !== -1) {
|
|
707
|
+
return circularValue;
|
|
708
|
+
}
|
|
709
|
+
const originalIndentation = indentation;
|
|
710
|
+
if (Array.isArray(value)) {
|
|
711
|
+
if (value.length === 0) {
|
|
712
|
+
return "[]";
|
|
713
|
+
}
|
|
714
|
+
if (maximumDepth < stack.length + 1) {
|
|
715
|
+
return '"[Array]"';
|
|
716
|
+
}
|
|
717
|
+
stack.push(value);
|
|
718
|
+
indentation += spacer;
|
|
719
|
+
let res2 = `
|
|
720
|
+
${indentation}`;
|
|
721
|
+
const join2 = `,
|
|
722
|
+
${indentation}`;
|
|
723
|
+
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
724
|
+
let i = 0;
|
|
725
|
+
for (; i < maximumValuesToStringify - 1; i++) {
|
|
726
|
+
const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
|
|
727
|
+
res2 += tmp2 !== void 0 ? tmp2 : "null";
|
|
728
|
+
res2 += join2;
|
|
729
|
+
}
|
|
730
|
+
const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
|
|
731
|
+
res2 += tmp !== void 0 ? tmp : "null";
|
|
732
|
+
if (value.length - 1 > maximumBreadth) {
|
|
733
|
+
const removedKeys = value.length - maximumBreadth - 1;
|
|
734
|
+
res2 += `${join2}"... ${getItemCount(removedKeys)} not stringified"`;
|
|
735
|
+
}
|
|
736
|
+
res2 += `
|
|
737
|
+
${originalIndentation}`;
|
|
738
|
+
stack.pop();
|
|
739
|
+
return `[${res2}]`;
|
|
740
|
+
}
|
|
741
|
+
let keys = Object.keys(value);
|
|
742
|
+
const keyLength = keys.length;
|
|
743
|
+
if (keyLength === 0) {
|
|
744
|
+
return "{}";
|
|
745
|
+
}
|
|
746
|
+
if (maximumDepth < stack.length + 1) {
|
|
747
|
+
return '"[Object]"';
|
|
748
|
+
}
|
|
749
|
+
indentation += spacer;
|
|
750
|
+
const join = `,
|
|
751
|
+
${indentation}`;
|
|
752
|
+
let res = "";
|
|
753
|
+
let separator = "";
|
|
754
|
+
let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
|
|
755
|
+
if (isTypedArrayWithEntries(value)) {
|
|
756
|
+
res += stringifyTypedArray(value, join, maximumBreadth);
|
|
757
|
+
keys = keys.slice(value.length);
|
|
758
|
+
maximumPropertiesToStringify -= value.length;
|
|
759
|
+
separator = join;
|
|
760
|
+
}
|
|
761
|
+
if (deterministic) {
|
|
762
|
+
keys = sort(keys, comparator);
|
|
763
|
+
}
|
|
764
|
+
stack.push(value);
|
|
765
|
+
for (let i = 0; i < maximumPropertiesToStringify; i++) {
|
|
766
|
+
const key2 = keys[i];
|
|
767
|
+
const tmp = stringifyIndent(key2, value[key2], stack, spacer, indentation);
|
|
768
|
+
if (tmp !== void 0) {
|
|
769
|
+
res += `${separator}${strEscape(key2)}: ${tmp}`;
|
|
770
|
+
separator = join;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
if (keyLength > maximumBreadth) {
|
|
774
|
+
const removedKeys = keyLength - maximumBreadth;
|
|
775
|
+
res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
|
|
776
|
+
separator = join;
|
|
777
|
+
}
|
|
778
|
+
if (separator !== "") {
|
|
779
|
+
res = `
|
|
780
|
+
${indentation}${res}
|
|
781
|
+
${originalIndentation}`;
|
|
782
|
+
}
|
|
783
|
+
stack.pop();
|
|
784
|
+
return `{${res}}`;
|
|
785
|
+
}
|
|
786
|
+
case "number":
|
|
787
|
+
return isFinite(value) ? String(value) : fail ? fail(value) : "null";
|
|
788
|
+
case "boolean":
|
|
789
|
+
return value === true ? "true" : "false";
|
|
790
|
+
case "undefined":
|
|
791
|
+
return void 0;
|
|
792
|
+
case "bigint":
|
|
793
|
+
if (bigint) {
|
|
794
|
+
return String(value);
|
|
795
|
+
}
|
|
796
|
+
// fallthrough
|
|
797
|
+
default:
|
|
798
|
+
return fail ? fail(value) : void 0;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
function stringifySimple(key, value, stack) {
|
|
802
|
+
switch (typeof value) {
|
|
803
|
+
case "string":
|
|
804
|
+
return strEscape(value);
|
|
805
|
+
case "object": {
|
|
806
|
+
if (value === null) {
|
|
807
|
+
return "null";
|
|
808
|
+
}
|
|
809
|
+
if (typeof value.toJSON === "function") {
|
|
810
|
+
value = value.toJSON(key);
|
|
811
|
+
if (typeof value !== "object") {
|
|
812
|
+
return stringifySimple(key, value, stack);
|
|
813
|
+
}
|
|
814
|
+
if (value === null) {
|
|
815
|
+
return "null";
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
if (stack.indexOf(value) !== -1) {
|
|
819
|
+
return circularValue;
|
|
820
|
+
}
|
|
821
|
+
let res = "";
|
|
822
|
+
const hasLength = value.length !== void 0;
|
|
823
|
+
if (hasLength && Array.isArray(value)) {
|
|
824
|
+
if (value.length === 0) {
|
|
825
|
+
return "[]";
|
|
826
|
+
}
|
|
827
|
+
if (maximumDepth < stack.length + 1) {
|
|
828
|
+
return '"[Array]"';
|
|
829
|
+
}
|
|
830
|
+
stack.push(value);
|
|
831
|
+
const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
|
|
832
|
+
let i = 0;
|
|
833
|
+
for (; i < maximumValuesToStringify - 1; i++) {
|
|
834
|
+
const tmp2 = stringifySimple(String(i), value[i], stack);
|
|
835
|
+
res += tmp2 !== void 0 ? tmp2 : "null";
|
|
836
|
+
res += ",";
|
|
837
|
+
}
|
|
838
|
+
const tmp = stringifySimple(String(i), value[i], stack);
|
|
839
|
+
res += tmp !== void 0 ? tmp : "null";
|
|
840
|
+
if (value.length - 1 > maximumBreadth) {
|
|
841
|
+
const removedKeys = value.length - maximumBreadth - 1;
|
|
842
|
+
res += `,"... ${getItemCount(removedKeys)} not stringified"`;
|
|
843
|
+
}
|
|
844
|
+
stack.pop();
|
|
845
|
+
return `[${res}]`;
|
|
846
|
+
}
|
|
847
|
+
let keys = Object.keys(value);
|
|
848
|
+
const keyLength = keys.length;
|
|
849
|
+
if (keyLength === 0) {
|
|
850
|
+
return "{}";
|
|
851
|
+
}
|
|
852
|
+
if (maximumDepth < stack.length + 1) {
|
|
853
|
+
return '"[Object]"';
|
|
854
|
+
}
|
|
855
|
+
let separator = "";
|
|
856
|
+
let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
|
|
857
|
+
if (hasLength && isTypedArrayWithEntries(value)) {
|
|
858
|
+
res += stringifyTypedArray(value, ",", maximumBreadth);
|
|
859
|
+
keys = keys.slice(value.length);
|
|
860
|
+
maximumPropertiesToStringify -= value.length;
|
|
861
|
+
separator = ",";
|
|
862
|
+
}
|
|
863
|
+
if (deterministic) {
|
|
864
|
+
keys = sort(keys, comparator);
|
|
865
|
+
}
|
|
866
|
+
stack.push(value);
|
|
867
|
+
for (let i = 0; i < maximumPropertiesToStringify; i++) {
|
|
868
|
+
const key2 = keys[i];
|
|
869
|
+
const tmp = stringifySimple(key2, value[key2], stack);
|
|
870
|
+
if (tmp !== void 0) {
|
|
871
|
+
res += `${separator}${strEscape(key2)}:${tmp}`;
|
|
872
|
+
separator = ",";
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
if (keyLength > maximumBreadth) {
|
|
876
|
+
const removedKeys = keyLength - maximumBreadth;
|
|
877
|
+
res += `${separator}"...":"${getItemCount(removedKeys)} not stringified"`;
|
|
878
|
+
}
|
|
879
|
+
stack.pop();
|
|
880
|
+
return `{${res}}`;
|
|
881
|
+
}
|
|
882
|
+
case "number":
|
|
883
|
+
return isFinite(value) ? String(value) : fail ? fail(value) : "null";
|
|
884
|
+
case "boolean":
|
|
885
|
+
return value === true ? "true" : "false";
|
|
886
|
+
case "undefined":
|
|
887
|
+
return void 0;
|
|
888
|
+
case "bigint":
|
|
889
|
+
if (bigint) {
|
|
890
|
+
return String(value);
|
|
891
|
+
}
|
|
892
|
+
// fallthrough
|
|
893
|
+
default:
|
|
894
|
+
return fail ? fail(value) : void 0;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
function stringify2(value, replacer, space) {
|
|
898
|
+
if (arguments.length > 1) {
|
|
899
|
+
let spacer = "";
|
|
900
|
+
if (typeof space === "number") {
|
|
901
|
+
spacer = " ".repeat(Math.min(space, 10));
|
|
902
|
+
} else if (typeof space === "string") {
|
|
903
|
+
spacer = space.slice(0, 10);
|
|
904
|
+
}
|
|
905
|
+
if (replacer != null) {
|
|
906
|
+
if (typeof replacer === "function") {
|
|
907
|
+
return stringifyFnReplacer("", { "": value }, [], replacer, spacer, "");
|
|
908
|
+
}
|
|
909
|
+
if (Array.isArray(replacer)) {
|
|
910
|
+
return stringifyArrayReplacer("", value, [], getUniqueReplacerSet(replacer), spacer, "");
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (spacer.length !== 0) {
|
|
914
|
+
return stringifyIndent("", value, [], spacer, "");
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
return stringifySimple("", value, []);
|
|
918
|
+
}
|
|
919
|
+
return stringify2;
|
|
920
|
+
}
|
|
921
|
+
} (safeStableStringify, safeStableStringify.exports));
|
|
922
|
+
return safeStableStringify.exports;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
var safeStableStringifyExports = requireSafeStableStringify();
|
|
926
|
+
const cjsModule = /*@__PURE__*/getDefaultExportFromCjs(safeStableStringifyExports);
|
|
927
|
+
|
|
928
|
+
const configure = cjsModule.configure;
|
|
929
|
+
|
|
930
|
+
const writeConsoleLogBasedOnLevel = (level) => {
|
|
931
|
+
if (level === "error") {
|
|
932
|
+
return console.__error ?? console.error;
|
|
933
|
+
}
|
|
934
|
+
if (level === "warn") {
|
|
935
|
+
return console.__warn ?? console.warn;
|
|
936
|
+
}
|
|
937
|
+
if (level === "trace") {
|
|
938
|
+
return console.__trace ?? console.trace;
|
|
939
|
+
}
|
|
940
|
+
return console.__log ?? console.log;
|
|
941
|
+
};
|
|
942
|
+
|
|
943
|
+
let RawReporter$1 = class RawReporter {
|
|
944
|
+
// eslint-disable-next-line class-methods-use-this
|
|
945
|
+
log(meta) {
|
|
946
|
+
const { context = [], message, type } = meta;
|
|
947
|
+
const consoleLogFunction = writeConsoleLogBasedOnLevel(type.level);
|
|
948
|
+
consoleLogFunction(message, ...context);
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
const arrayify = (x) => {
|
|
953
|
+
if (x === void 0) {
|
|
954
|
+
return [];
|
|
955
|
+
}
|
|
956
|
+
return Array.isArray(x) ? x : [x];
|
|
957
|
+
};
|
|
958
|
+
|
|
959
|
+
const mergeTypes = (standard, custom) => {
|
|
960
|
+
const types = { ...standard };
|
|
961
|
+
Object.keys(custom).forEach((type) => {
|
|
962
|
+
types[type] = { ...types[type], ...custom[type] };
|
|
963
|
+
});
|
|
964
|
+
return types;
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
const preventLoop = (function_) => {
|
|
968
|
+
let doing = false;
|
|
969
|
+
return function(...args) {
|
|
970
|
+
if (doing) {
|
|
971
|
+
return void 0;
|
|
972
|
+
}
|
|
973
|
+
doing = true;
|
|
974
|
+
try {
|
|
975
|
+
const result = function_.apply(this, args);
|
|
976
|
+
doing = false;
|
|
977
|
+
return result;
|
|
978
|
+
} catch (error) {
|
|
979
|
+
doing = false;
|
|
980
|
+
throw error;
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
};
|
|
984
|
+
class PailBrowserImpl {
|
|
985
|
+
timersMap;
|
|
986
|
+
countMap;
|
|
987
|
+
seqTimers;
|
|
988
|
+
lastLog;
|
|
989
|
+
logLevels;
|
|
990
|
+
disabled;
|
|
991
|
+
paused;
|
|
992
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
993
|
+
messageQueue;
|
|
994
|
+
scopeName;
|
|
995
|
+
types;
|
|
996
|
+
longestLabel;
|
|
997
|
+
processors;
|
|
998
|
+
generalLogLevel;
|
|
999
|
+
reporters;
|
|
1000
|
+
throttle;
|
|
1001
|
+
throttleMin;
|
|
1002
|
+
stringify;
|
|
1003
|
+
groups;
|
|
1004
|
+
startTimerMessage;
|
|
1005
|
+
endTimerMessage;
|
|
1006
|
+
rawReporter;
|
|
1007
|
+
force = {};
|
|
1008
|
+
/**
|
|
1009
|
+
* Creates a new Pail browser logger instance.
|
|
1010
|
+
*
|
|
1011
|
+
* Initializes the logger with the provided configuration options,
|
|
1012
|
+
* setting up reporters, processors, log levels, and other internal state.
|
|
1013
|
+
* @param options Configuration options for the logger
|
|
1014
|
+
*/
|
|
1015
|
+
constructor(options) {
|
|
1016
|
+
this.throttle = options.throttle ?? 1e3;
|
|
1017
|
+
this.throttleMin = options.throttleMin ?? 5;
|
|
1018
|
+
const parentLongestLabel = options.parentLongestLabel;
|
|
1019
|
+
const parentTypes = options.parentTypes;
|
|
1020
|
+
const parentStringify = options.parentStringify;
|
|
1021
|
+
const parentLogLevels = options.parentLogLevels;
|
|
1022
|
+
this.stringify = parentStringify ?? configure({
|
|
1023
|
+
strict: true
|
|
1024
|
+
});
|
|
1025
|
+
this.startTimerMessage = options.messages?.timerStart ?? "Initialized timer...";
|
|
1026
|
+
this.endTimerMessage = options.messages?.timerEnd ?? "Timer run for:";
|
|
1027
|
+
if (parentTypes && parentLongestLabel) {
|
|
1028
|
+
this.types = parentTypes;
|
|
1029
|
+
this.longestLabel = parentLongestLabel;
|
|
1030
|
+
} else {
|
|
1031
|
+
this.types = mergeTypes(LOG_TYPES, options.types ?? {});
|
|
1032
|
+
this.longestLabel = getLongestLabel(this.types);
|
|
1033
|
+
}
|
|
1034
|
+
this.logLevels = parentLogLevels && !options.logLevels ? parentLogLevels : { ...EXTENDED_RFC_5424_LOG_LEVELS, ...options.logLevels };
|
|
1035
|
+
this.generalLogLevel = this.#normalizeLogLevel(options.logLevel);
|
|
1036
|
+
this.reporters = /* @__PURE__ */ new Set();
|
|
1037
|
+
this.processors = /* @__PURE__ */ new Set();
|
|
1038
|
+
this.disabled = options.disabled ?? false;
|
|
1039
|
+
this.paused = false;
|
|
1040
|
+
this.messageQueue = [];
|
|
1041
|
+
this.scopeName = arrayify(options.scope).filter(Boolean);
|
|
1042
|
+
this.timersMap = /* @__PURE__ */ new Map();
|
|
1043
|
+
this.countMap = /* @__PURE__ */ new Map();
|
|
1044
|
+
this.groups = [];
|
|
1045
|
+
this.seqTimers = /* @__PURE__ */ new Set();
|
|
1046
|
+
this.lastLog = {};
|
|
1047
|
+
this.logger = preventLoop(this.logger).bind(this);
|
|
1048
|
+
this.#initializeBoundMethods();
|
|
1049
|
+
if (Array.isArray(options.reporters)) {
|
|
1050
|
+
this.registerReporters(options.reporters);
|
|
1051
|
+
}
|
|
1052
|
+
this.rawReporter = this.extendReporter(options.rawReporter ?? new RawReporter$1());
|
|
1053
|
+
if (Array.isArray(options.processors)) {
|
|
1054
|
+
this.registerProcessors(options.processors);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Initializes bound methods for all logger types.
|
|
1059
|
+
*
|
|
1060
|
+
* Creates bound methods for both regular and force logging methods.
|
|
1061
|
+
* This is separated to allow reuse when types haven't changed.
|
|
1062
|
+
*/
|
|
1063
|
+
#initializeBoundMethods() {
|
|
1064
|
+
for (const type in this.types) {
|
|
1065
|
+
this[type] = this.logger.bind(this, type, false, false);
|
|
1066
|
+
}
|
|
1067
|
+
for (const type in this.types) {
|
|
1068
|
+
this.force[type] = this.logger.bind(this, type, false, true);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
/**
|
|
1072
|
+
* Wraps the global console methods to redirect them through the logger.
|
|
1073
|
+
*
|
|
1074
|
+
* This method replaces console methods (log, info, warn, error, etc.) with
|
|
1075
|
+
* calls to the corresponding logger methods. The original console methods
|
|
1076
|
+
* are backed up and can be restored using restoreConsole().
|
|
1077
|
+
* @example
|
|
1078
|
+
* ```typescript
|
|
1079
|
+
* const logger = createPail();
|
|
1080
|
+
* logger.wrapConsole();
|
|
1081
|
+
*
|
|
1082
|
+
* console.log("This will go through the logger");
|
|
1083
|
+
* console.error("This too!");
|
|
1084
|
+
*
|
|
1085
|
+
* logger.restoreConsole(); // Restore original console methods
|
|
1086
|
+
* ```
|
|
1087
|
+
*/
|
|
1088
|
+
wrapConsole() {
|
|
1089
|
+
for (const type in this.types) {
|
|
1090
|
+
if (!console[`__${type}`]) {
|
|
1091
|
+
console[`__${type}`] = console[type];
|
|
1092
|
+
}
|
|
1093
|
+
console[type] = this[type];
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Restores the original global console methods.
|
|
1098
|
+
*
|
|
1099
|
+
* This method restores the console methods that were backed up by wrapConsole().
|
|
1100
|
+
* After calling this, console methods will work as they did before wrapping.
|
|
1101
|
+
* @example
|
|
1102
|
+
* ```typescript
|
|
1103
|
+
* const logger = createPail();
|
|
1104
|
+
* logger.wrapConsole();
|
|
1105
|
+
*
|
|
1106
|
+
* // Console methods are now wrapped
|
|
1107
|
+
* logger.restoreConsole();
|
|
1108
|
+
* // Console methods are restored to original behavior
|
|
1109
|
+
* ```
|
|
1110
|
+
*/
|
|
1111
|
+
restoreConsole() {
|
|
1112
|
+
for (const type in this.types) {
|
|
1113
|
+
if (console[`__${type}`]) {
|
|
1114
|
+
console[type] = console[`__${type}`];
|
|
1115
|
+
delete console[`__${type}`];
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Wraps uncaught exception and unhandled rejection handlers.
|
|
1121
|
+
*
|
|
1122
|
+
* This method sets up global error handlers that will log uncaught exceptions
|
|
1123
|
+
* and unhandled promise rejections through the logger. This is useful for
|
|
1124
|
+
* capturing and logging application crashes.
|
|
1125
|
+
* @example
|
|
1126
|
+
* ```typescript
|
|
1127
|
+
* const logger = createPail();
|
|
1128
|
+
* logger.wrapException();
|
|
1129
|
+
*
|
|
1130
|
+
* // Now uncaught errors will be logged
|
|
1131
|
+
* throw new Error("This will be logged");
|
|
1132
|
+
* ```
|
|
1133
|
+
*/
|
|
1134
|
+
wrapException() {
|
|
1135
|
+
{
|
|
1136
|
+
process.on("uncaughtException", (error) => {
|
|
1137
|
+
this.error(error);
|
|
1138
|
+
});
|
|
1139
|
+
process.on("unhandledRejection", (error) => {
|
|
1140
|
+
this.error(error);
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Disables all logging output.
|
|
1146
|
+
*
|
|
1147
|
+
* When disabled, all log calls will be silently ignored and no output
|
|
1148
|
+
* will be produced by any reporters. This can be useful for temporarily
|
|
1149
|
+
* suppressing log output in production or during testing.
|
|
1150
|
+
* @example
|
|
1151
|
+
* ```typescript
|
|
1152
|
+
* const logger = createPail();
|
|
1153
|
+
* logger.disable();
|
|
1154
|
+
* logger.info("This won't be logged"); // Silent
|
|
1155
|
+
* logger.enable();
|
|
1156
|
+
* logger.info("This will be logged"); // Output produced
|
|
1157
|
+
* ```
|
|
1158
|
+
*/
|
|
1159
|
+
disable() {
|
|
1160
|
+
this.disabled = true;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Enables logging output.
|
|
1164
|
+
*
|
|
1165
|
+
* Re-enables logging after it has been disabled. All subsequent log calls
|
|
1166
|
+
* will produce output according to the configured reporters.
|
|
1167
|
+
* @example
|
|
1168
|
+
* ```typescript
|
|
1169
|
+
* const logger = createPail();
|
|
1170
|
+
* logger.disable();
|
|
1171
|
+
* logger.info("This won't be logged");
|
|
1172
|
+
* logger.enable(); // Re-enable logging
|
|
1173
|
+
* logger.info("This will be logged");
|
|
1174
|
+
* ```
|
|
1175
|
+
*/
|
|
1176
|
+
enable() {
|
|
1177
|
+
this.disabled = false;
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* Checks if logging is currently enabled.
|
|
1181
|
+
*
|
|
1182
|
+
* Returns true if logging is enabled and false if it has been disabled.
|
|
1183
|
+
* @returns True if logging is enabled, false if disabled
|
|
1184
|
+
* @example
|
|
1185
|
+
* ```typescript
|
|
1186
|
+
* const logger = createPail();
|
|
1187
|
+
* console.log(logger.isEnabled()); // true
|
|
1188
|
+
* logger.disable();
|
|
1189
|
+
* console.log(logger.isEnabled()); // false
|
|
1190
|
+
* ```
|
|
1191
|
+
*/
|
|
1192
|
+
isEnabled() {
|
|
1193
|
+
return !this.disabled;
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* Pauses logging and starts queuing messages.
|
|
1197
|
+
*
|
|
1198
|
+
* When paused, all log calls will be queued instead of being output immediately.
|
|
1199
|
+
* The queued messages will be processed when resume() is called. This is useful
|
|
1200
|
+
* for temporarily buffering log output during critical operations.
|
|
1201
|
+
* @example
|
|
1202
|
+
* ```typescript
|
|
1203
|
+
* const logger = createPail();
|
|
1204
|
+
* logger.pause();
|
|
1205
|
+
* logger.info("This will be queued"); // Queued, not output yet
|
|
1206
|
+
* logger.warn("This too"); // Also queued
|
|
1207
|
+
* logger.resume(); // Now both messages are output
|
|
1208
|
+
* ```
|
|
1209
|
+
*/
|
|
1210
|
+
pause() {
|
|
1211
|
+
this.paused = true;
|
|
1212
|
+
}
|
|
1213
|
+
/**
|
|
1214
|
+
* Resumes logging and flushes all queued messages.
|
|
1215
|
+
*
|
|
1216
|
+
* Processes all messages that were queued during the pause period and
|
|
1217
|
+
* resumes normal logging behavior. Messages are output in the order
|
|
1218
|
+
* they were originally called.
|
|
1219
|
+
* @example
|
|
1220
|
+
* ```typescript
|
|
1221
|
+
* const logger = createPail();
|
|
1222
|
+
* logger.pause();
|
|
1223
|
+
* logger.info("Message 1"); // Queued
|
|
1224
|
+
* logger.info("Message 2"); // Queued
|
|
1225
|
+
* logger.resume(); // Both messages are now output in order
|
|
1226
|
+
* logger.info("Message 3"); // Output immediately
|
|
1227
|
+
* ```
|
|
1228
|
+
*/
|
|
1229
|
+
resume() {
|
|
1230
|
+
this.paused = false;
|
|
1231
|
+
const queue = this.messageQueue.splice(0);
|
|
1232
|
+
for (const { messageObject, raw, type } of queue) {
|
|
1233
|
+
this.logger(type, raw, false, ...messageObject);
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Creates a scoped logger instance.
|
|
1238
|
+
*
|
|
1239
|
+
* Returns a new logger instance that inherits all configuration but adds
|
|
1240
|
+
* the specified scope names to all log messages. This is useful for
|
|
1241
|
+
* categorizing logs by component, module, or feature.
|
|
1242
|
+
* @template N - The new custom logger type names
|
|
1243
|
+
* @param name Scope names to apply to all log messages
|
|
1244
|
+
* @returns A new scoped logger instance
|
|
1245
|
+
* @throws {Error} If no scope name is provided
|
|
1246
|
+
* @example
|
|
1247
|
+
* ```typescript
|
|
1248
|
+
* const logger = createPail();
|
|
1249
|
+
* const scopedLogger = logger.scope("auth", "login");
|
|
1250
|
+
* scopedLogger.info("User logged in"); // Will include scope: ["auth", "login"]
|
|
1251
|
+
* ```
|
|
1252
|
+
*/
|
|
1253
|
+
scope(...name) {
|
|
1254
|
+
if (name.length === 0) {
|
|
1255
|
+
throw new Error("No scope name was defined.");
|
|
1256
|
+
}
|
|
1257
|
+
this.scopeName = name.flat();
|
|
1258
|
+
return this;
|
|
1259
|
+
}
|
|
1260
|
+
/**
|
|
1261
|
+
* Removes the current scope from the logger.
|
|
1262
|
+
*
|
|
1263
|
+
* Clears all scope names that were set by previous scope() calls.
|
|
1264
|
+
* After calling this, log messages will no longer include scope information.
|
|
1265
|
+
* @example
|
|
1266
|
+
* ```typescript
|
|
1267
|
+
* const logger = createPail();
|
|
1268
|
+
* const scopedLogger = logger.scope("auth");
|
|
1269
|
+
* scopedLogger.info("Scoped message"); // Has scope
|
|
1270
|
+
* scopedLogger.unscope();
|
|
1271
|
+
* scopedLogger.info("Unscoped message"); // No scope
|
|
1272
|
+
* ```
|
|
1273
|
+
*/
|
|
1274
|
+
unscope() {
|
|
1275
|
+
this.scopeName = [];
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* Creates a child logger that inherits settings from the parent.
|
|
1279
|
+
*
|
|
1280
|
+
* Returns a new logger instance that inherits all configuration from the parent
|
|
1281
|
+
* (reporters, processors, types, log levels, throttle settings, etc.) while allowing
|
|
1282
|
+
* you to override only what you need. Child loggers are independent instances with
|
|
1283
|
+
* their own state (timers, counters, etc.).
|
|
1284
|
+
* @template N - The new custom logger type names
|
|
1285
|
+
* @template LC - The new log level types
|
|
1286
|
+
* @param options Configuration options to override or extend parent settings
|
|
1287
|
+
* @returns A new child logger instance
|
|
1288
|
+
* @example
|
|
1289
|
+
* ```typescript
|
|
1290
|
+
* const parent = createPail({
|
|
1291
|
+
* logLevel: "info",
|
|
1292
|
+
* types: { http: { label: "HTTP", logLevel: "info" } },
|
|
1293
|
+
* reporters: [new PrettyReporter()],
|
|
1294
|
+
* });
|
|
1295
|
+
*
|
|
1296
|
+
* // Child inherits parent settings but overrides log level
|
|
1297
|
+
* const child = parent.child({ logLevel: "debug" });
|
|
1298
|
+
* child.info("This will be logged"); // Uses debug level from child
|
|
1299
|
+
* child.http("GET /api 200"); // Inherits http type from parent
|
|
1300
|
+
*
|
|
1301
|
+
* // Child can add new types
|
|
1302
|
+
* const childWithNewType = parent.child({
|
|
1303
|
+
* types: { db: { label: "DB", logLevel: "info" } },
|
|
1304
|
+
* });
|
|
1305
|
+
* childWithNewType.db("Query executed"); // New type available
|
|
1306
|
+
* ```
|
|
1307
|
+
*/
|
|
1308
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
1309
|
+
child(options) {
|
|
1310
|
+
const typesChanged = options?.types !== void 0 && options.types !== null;
|
|
1311
|
+
const mergedTypes = typesChanged ? mergeTypes(this.types, options.types) : this.types;
|
|
1312
|
+
const childReporters = options?.reporters ?? [];
|
|
1313
|
+
const allReporters = childReporters.length > 0 ? [...this.reporters, ...childReporters] : [...this.reporters];
|
|
1314
|
+
const childProcessors = options?.processors ?? [];
|
|
1315
|
+
const allProcessors = childProcessors.length > 0 ? [...this.processors, ...childProcessors] : [...this.processors];
|
|
1316
|
+
const mergedLogLevels = options?.logLevels ? { ...this.logLevels, ...options.logLevels } : this.logLevels;
|
|
1317
|
+
let mergedScope;
|
|
1318
|
+
if (options?.scope) {
|
|
1319
|
+
const childScope = arrayify(options.scope).filter(Boolean);
|
|
1320
|
+
mergedScope = this.scopeName.length > 0 ? [...this.scopeName, ...childScope] : childScope;
|
|
1321
|
+
} else {
|
|
1322
|
+
mergedScope = this.scopeName.length > 0 ? this.scopeName : [];
|
|
1323
|
+
}
|
|
1324
|
+
const mergedMessages = options?.messages ? {
|
|
1325
|
+
timerEnd: this.endTimerMessage,
|
|
1326
|
+
timerStart: this.startTimerMessage,
|
|
1327
|
+
...options.messages
|
|
1328
|
+
} : {
|
|
1329
|
+
timerEnd: this.endTimerMessage,
|
|
1330
|
+
timerStart: this.startTimerMessage
|
|
1331
|
+
};
|
|
1332
|
+
const childOptions = {
|
|
1333
|
+
disabled: options?.disabled ?? this.disabled,
|
|
1334
|
+
logLevel: options?.logLevel ?? this.generalLogLevel,
|
|
1335
|
+
logLevels: mergedLogLevels,
|
|
1336
|
+
messages: mergedMessages,
|
|
1337
|
+
processors: allProcessors,
|
|
1338
|
+
rawReporter: options?.rawReporter ?? this.rawReporter,
|
|
1339
|
+
reporters: allReporters,
|
|
1340
|
+
scope: mergedScope,
|
|
1341
|
+
throttle: options?.throttle ?? this.throttle,
|
|
1342
|
+
throttleMin: options?.throttleMin ?? this.throttleMin
|
|
1343
|
+
};
|
|
1344
|
+
if (typesChanged) {
|
|
1345
|
+
childOptions.parentTypes = mergedTypes;
|
|
1346
|
+
childOptions.parentLongestLabel = getLongestLabel(mergedTypes);
|
|
1347
|
+
} else {
|
|
1348
|
+
childOptions.parentTypes = this.types;
|
|
1349
|
+
childOptions.parentLongestLabel = this.longestLabel;
|
|
1350
|
+
}
|
|
1351
|
+
if (!options?.logLevels) {
|
|
1352
|
+
childOptions.parentLogLevels = this.logLevels;
|
|
1353
|
+
}
|
|
1354
|
+
if (!options?.messages) {
|
|
1355
|
+
childOptions.parentMessages = {
|
|
1356
|
+
timerEnd: this.endTimerMessage,
|
|
1357
|
+
timerStart: this.startTimerMessage
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
childOptions.parentStringify = this.stringify;
|
|
1361
|
+
return new PailBrowserImpl(childOptions);
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Starts a timer with the specified label.
|
|
1365
|
+
*
|
|
1366
|
+
* Records the current timestamp and associates it with the given label.
|
|
1367
|
+
* Multiple timers can be active simultaneously with different labels.
|
|
1368
|
+
* @param label The timer label (defaults to "default")
|
|
1369
|
+
* @example
|
|
1370
|
+
* ```typescript
|
|
1371
|
+
* const logger = createPail();
|
|
1372
|
+
* logger.time("operation");
|
|
1373
|
+
* // ... some operation ...
|
|
1374
|
+
* logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
|
|
1375
|
+
* ```
|
|
1376
|
+
*/
|
|
1377
|
+
time(label = "default") {
|
|
1378
|
+
if (this.seqTimers.has(label)) {
|
|
1379
|
+
this.logger("warn", false, false, {
|
|
1380
|
+
message: `Timer '${label}' already exists`,
|
|
1381
|
+
prefix: label
|
|
1382
|
+
});
|
|
1383
|
+
} else {
|
|
1384
|
+
this.seqTimers.add(label);
|
|
1385
|
+
this.timersMap.set(label, Date.now());
|
|
1386
|
+
this.logger("start", false, false, {
|
|
1387
|
+
message: this.startTimerMessage,
|
|
1388
|
+
prefix: label
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Logs the current elapsed time for a timer without stopping it.
|
|
1394
|
+
*
|
|
1395
|
+
* Calculates and logs the time elapsed since the timer was started,
|
|
1396
|
+
* but keeps the timer running. If no label is provided, uses the
|
|
1397
|
+
* most recently started timer.
|
|
1398
|
+
* @param label The timer label (uses last timer if not specified)
|
|
1399
|
+
* @param data Additional data to include in the log message
|
|
1400
|
+
* @example
|
|
1401
|
+
* ```typescript
|
|
1402
|
+
* const logger = createPail();
|
|
1403
|
+
* logger.time("task");
|
|
1404
|
+
* // ... some work ...
|
|
1405
|
+
* logger.timeLog("task"); // Logs current elapsed time
|
|
1406
|
+
* // ... more work ...
|
|
1407
|
+
* logger.timeEnd("task"); // Logs final time and stops timer
|
|
1408
|
+
* ```
|
|
1409
|
+
*/
|
|
1410
|
+
timeLog(label, ...data) {
|
|
1411
|
+
if (!label && this.seqTimers.size > 0) {
|
|
1412
|
+
label = [...this.seqTimers].pop();
|
|
1413
|
+
}
|
|
1414
|
+
if (label && this.timersMap.has(label)) {
|
|
1415
|
+
const span = Date.now() - this.timersMap.get(label);
|
|
1416
|
+
this.logger("info", false, false, {
|
|
1417
|
+
context: data,
|
|
1418
|
+
message: span < 1e3 ? `${span} ms` : `${(span / 1e3).toFixed(2)} s`,
|
|
1419
|
+
prefix: label
|
|
1420
|
+
});
|
|
1421
|
+
} else {
|
|
1422
|
+
this.logger("warn", false, false, {
|
|
1423
|
+
context: data,
|
|
1424
|
+
message: "Timer not found",
|
|
1425
|
+
prefix: label
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Stops a timer and logs the final elapsed time.
|
|
1431
|
+
*
|
|
1432
|
+
* Calculates the total time elapsed since the timer was started,
|
|
1433
|
+
* logs the result, and removes the timer. If no label is provided,
|
|
1434
|
+
* uses the most recently started timer.
|
|
1435
|
+
* @param label The timer label (uses last timer if not specified)
|
|
1436
|
+
* @example
|
|
1437
|
+
* ```typescript
|
|
1438
|
+
* const logger = createPail();
|
|
1439
|
+
* logger.time("operation");
|
|
1440
|
+
* // ... perform operation ...
|
|
1441
|
+
* logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
|
|
1442
|
+
* ```
|
|
1443
|
+
*/
|
|
1444
|
+
timeEnd(label) {
|
|
1445
|
+
if (!label && this.seqTimers.size > 0) {
|
|
1446
|
+
label = [...this.seqTimers].pop();
|
|
1447
|
+
}
|
|
1448
|
+
if (label && this.timersMap.has(label)) {
|
|
1449
|
+
const span = Date.now() - this.timersMap.get(label);
|
|
1450
|
+
this.timersMap.delete(label);
|
|
1451
|
+
this.logger("stop", false, false, {
|
|
1452
|
+
message: `${this.endTimerMessage} ${span < 1e3 ? `${span} ms` : `${(span / 1e3).toFixed(2)} s`}`,
|
|
1453
|
+
prefix: label
|
|
1454
|
+
});
|
|
1455
|
+
} else {
|
|
1456
|
+
this.logger("warn", false, false, {
|
|
1457
|
+
message: "Timer not found",
|
|
1458
|
+
prefix: label
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* Starts a log group with the specified label.
|
|
1464
|
+
*
|
|
1465
|
+
* Groups related log messages together. In browser environments,
|
|
1466
|
+
* this uses the native console.group() functionality. In other
|
|
1467
|
+
* environments, it tracks group nesting internally.
|
|
1468
|
+
* @param label The group label (defaults to "console.group")
|
|
1469
|
+
* @example
|
|
1470
|
+
* ```typescript
|
|
1471
|
+
* const logger = createPail();
|
|
1472
|
+
* logger.group("Database Operations");
|
|
1473
|
+
* logger.info("Connecting to database");
|
|
1474
|
+
* logger.info("Running migration");
|
|
1475
|
+
* logger.groupEnd(); // End the group
|
|
1476
|
+
* ```
|
|
1477
|
+
*/
|
|
1478
|
+
group(label = "console.group") {
|
|
1479
|
+
if (globalThis.window === void 0) {
|
|
1480
|
+
this.groups.push(label);
|
|
1481
|
+
} else {
|
|
1482
|
+
console.group(label);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Ends the current log group.
|
|
1487
|
+
*
|
|
1488
|
+
* Closes the most recently opened log group. In browser environments,
|
|
1489
|
+
* this uses the native console.groupEnd() functionality.
|
|
1490
|
+
* @example
|
|
1491
|
+
* ```typescript
|
|
1492
|
+
* const logger = createPail();
|
|
1493
|
+
* logger.group("Processing");
|
|
1494
|
+
* logger.info("Step 1");
|
|
1495
|
+
* logger.info("Step 2");
|
|
1496
|
+
* logger.groupEnd(); // Closes the "Processing" group
|
|
1497
|
+
* ```
|
|
1498
|
+
*/
|
|
1499
|
+
groupEnd() {
|
|
1500
|
+
if (globalThis.window === void 0) {
|
|
1501
|
+
this.groups.pop();
|
|
1502
|
+
} else {
|
|
1503
|
+
console.groupEnd();
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Increments and logs a counter with the specified label.
|
|
1508
|
+
*
|
|
1509
|
+
* Maintains an internal counter for each label and logs the current count
|
|
1510
|
+
* each time it's called. Useful for tracking how many times certain
|
|
1511
|
+
* code paths are executed.
|
|
1512
|
+
* @param label The counter label (defaults to "default")
|
|
1513
|
+
* @example
|
|
1514
|
+
* ```typescript
|
|
1515
|
+
* const logger = createPail();
|
|
1516
|
+
* logger.count("requests"); // Logs: "requests: 1"
|
|
1517
|
+
* logger.count("requests"); // Logs: "requests: 2"
|
|
1518
|
+
* logger.count("errors"); // Logs: "errors: 1"
|
|
1519
|
+
* ```
|
|
1520
|
+
*/
|
|
1521
|
+
count(label = "default") {
|
|
1522
|
+
const current = this.countMap.get(label) ?? 0;
|
|
1523
|
+
this.countMap.set(label, current + 1);
|
|
1524
|
+
this.logger("log", false, false, {
|
|
1525
|
+
message: `${label}: ${current + 1}`,
|
|
1526
|
+
prefix: label
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1529
|
+
/**
|
|
1530
|
+
* Resets a counter to zero.
|
|
1531
|
+
*
|
|
1532
|
+
* Removes the counter with the specified label, effectively resetting
|
|
1533
|
+
* it to zero. If the counter doesn't exist, logs a warning.
|
|
1534
|
+
* @param label The counter label to reset (defaults to "default")
|
|
1535
|
+
* @example
|
|
1536
|
+
* ```typescript
|
|
1537
|
+
* const logger = createPail();
|
|
1538
|
+
* logger.count("requests"); // Logs: "requests: 1"
|
|
1539
|
+
* logger.countReset("requests"); // Resets counter
|
|
1540
|
+
* logger.count("requests"); // Logs: "requests: 1" (starts over)
|
|
1541
|
+
* ```
|
|
1542
|
+
*/
|
|
1543
|
+
countReset(label = "default") {
|
|
1544
|
+
if (this.countMap.has(label)) {
|
|
1545
|
+
this.countMap.delete(label);
|
|
1546
|
+
} else {
|
|
1547
|
+
this.logger("warn", false, false, {
|
|
1548
|
+
message: `Count for ${label} does not exist`,
|
|
1549
|
+
prefix: label
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Clears the console output.
|
|
1555
|
+
*
|
|
1556
|
+
* Calls the native console.clear() method to clear all output from
|
|
1557
|
+
* the console. This is a convenience method that wraps the native
|
|
1558
|
+
* console.clear() functionality.
|
|
1559
|
+
* @example
|
|
1560
|
+
* ```typescript
|
|
1561
|
+
* const logger = createPail();
|
|
1562
|
+
* logger.info("Some message");
|
|
1563
|
+
* logger.clear(); // Clears the console
|
|
1564
|
+
* ```
|
|
1565
|
+
*/
|
|
1566
|
+
// eslint-disable-next-line class-methods-use-this
|
|
1567
|
+
clear() {
|
|
1568
|
+
console.clear();
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Logs a raw message bypassing normal processing.
|
|
1572
|
+
*
|
|
1573
|
+
* Sends a message directly to the raw reporter without going through
|
|
1574
|
+
* the normal logging pipeline (processors, throttling, etc.). This is
|
|
1575
|
+
* useful for logging that needs to bypass all formatting and processing.
|
|
1576
|
+
* @param message The raw message to log
|
|
1577
|
+
* @param arguments_ Additional arguments to include
|
|
1578
|
+
* @example
|
|
1579
|
+
* ```typescript
|
|
1580
|
+
* const logger = createPail();
|
|
1581
|
+
* logger.raw("Direct message", { data: "value" });
|
|
1582
|
+
* ```
|
|
1583
|
+
*/
|
|
1584
|
+
raw(message, ...arguments_) {
|
|
1585
|
+
if (this.disabled) {
|
|
1586
|
+
return;
|
|
1587
|
+
}
|
|
1588
|
+
this.logger("log", true, false, {
|
|
1589
|
+
context: arguments_,
|
|
1590
|
+
message
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
extendReporter(reporter) {
|
|
1594
|
+
if (typeof reporter.setLoggerTypes === "function") {
|
|
1595
|
+
reporter.setLoggerTypes(this.types);
|
|
1596
|
+
}
|
|
1597
|
+
if (typeof reporter.setStringify === "function") {
|
|
1598
|
+
reporter.setStringify(this.stringify);
|
|
1599
|
+
}
|
|
1600
|
+
return reporter;
|
|
1601
|
+
}
|
|
1602
|
+
registerReporters(reporters) {
|
|
1603
|
+
for (const reporter of reporters) {
|
|
1604
|
+
this.reporters.add(this.extendReporter(reporter));
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
registerProcessors(processors) {
|
|
1608
|
+
for (const processor of processors) {
|
|
1609
|
+
if (typeof processor.setStringify === "function") {
|
|
1610
|
+
processor.setStringify(this.stringify);
|
|
1611
|
+
}
|
|
1612
|
+
this.processors.add(processor);
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
#report(meta, raw) {
|
|
1616
|
+
if (raw) {
|
|
1617
|
+
this.rawReporter.log(Object.freeze(meta));
|
|
1618
|
+
} else {
|
|
1619
|
+
for (const reporter of this.reporters) {
|
|
1620
|
+
reporter.log(Object.freeze(meta));
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
#normalizeLogLevel(level) {
|
|
1625
|
+
return level && this.logLevels[level] ? level : "debug";
|
|
1626
|
+
}
|
|
1627
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
1628
|
+
#buildMeta(typeName, type, ...arguments_) {
|
|
1629
|
+
const meta = {
|
|
1630
|
+
badge: void 0,
|
|
1631
|
+
context: void 0,
|
|
1632
|
+
error: void 0,
|
|
1633
|
+
label: void 0,
|
|
1634
|
+
message: EMPTY_SYMBOL,
|
|
1635
|
+
prefix: void 0,
|
|
1636
|
+
repeated: void 0,
|
|
1637
|
+
scope: void 0,
|
|
1638
|
+
suffix: void 0
|
|
1639
|
+
};
|
|
1640
|
+
meta.type = {
|
|
1641
|
+
level: type.logLevel,
|
|
1642
|
+
name: typeName
|
|
1643
|
+
};
|
|
1644
|
+
meta.groups = this.groups;
|
|
1645
|
+
meta.scope = this.scopeName;
|
|
1646
|
+
meta.date = /* @__PURE__ */ new Date();
|
|
1647
|
+
if (arguments_.length > 0 && arguments_[0] instanceof Error) {
|
|
1648
|
+
meta.error = arguments_[0];
|
|
1649
|
+
if (arguments_.length > 1) {
|
|
1650
|
+
meta.context = arguments_.slice(1);
|
|
1651
|
+
}
|
|
1652
|
+
} else if (arguments_.length > 0 && typeof arguments_[0] === "object" && arguments_[0] !== null && "message" in arguments_[0]) {
|
|
1653
|
+
const { context, message, prefix, suffix } = arguments_[0];
|
|
1654
|
+
if (context) {
|
|
1655
|
+
meta.context = context;
|
|
1656
|
+
}
|
|
1657
|
+
if (prefix) {
|
|
1658
|
+
meta.prefix = prefix;
|
|
1659
|
+
}
|
|
1660
|
+
if (suffix) {
|
|
1661
|
+
meta.suffix = suffix;
|
|
1662
|
+
}
|
|
1663
|
+
meta.message = message;
|
|
1664
|
+
if (arguments_.length > 1) {
|
|
1665
|
+
const additionalContext = arguments_.slice(1);
|
|
1666
|
+
if (meta.context) {
|
|
1667
|
+
meta.context = Array.isArray(meta.context) ? [...meta.context, ...additionalContext] : [meta.context, ...additionalContext];
|
|
1668
|
+
} else {
|
|
1669
|
+
meta.context = additionalContext;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
} else if (arguments_.length > 1) {
|
|
1673
|
+
meta.message = arguments_[0];
|
|
1674
|
+
meta.context = arguments_.slice(1);
|
|
1675
|
+
} else if (arguments_.length === 1) {
|
|
1676
|
+
meta.message = arguments_[0];
|
|
1677
|
+
} else {
|
|
1678
|
+
meta.message = void 0;
|
|
1679
|
+
}
|
|
1680
|
+
if (type.logLevel === "trace") {
|
|
1681
|
+
meta.traceError = new Error("Trace");
|
|
1682
|
+
}
|
|
1683
|
+
if (type.badge) {
|
|
1684
|
+
meta.badge = type.badge;
|
|
1685
|
+
}
|
|
1686
|
+
if (type.label) {
|
|
1687
|
+
meta.label = type.label;
|
|
1688
|
+
}
|
|
1689
|
+
return meta;
|
|
1690
|
+
}
|
|
1691
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
1692
|
+
logger(type, raw, force, ...messageObject) {
|
|
1693
|
+
if (this.disabled) {
|
|
1694
|
+
return;
|
|
1695
|
+
}
|
|
1696
|
+
if (this.paused) {
|
|
1697
|
+
this.messageQueue.push({ messageObject, raw, type });
|
|
1698
|
+
return;
|
|
1699
|
+
}
|
|
1700
|
+
const typeConfig = this.types[type];
|
|
1701
|
+
if (!typeConfig) {
|
|
1702
|
+
return;
|
|
1703
|
+
}
|
|
1704
|
+
const logLevel = this.#normalizeLogLevel(typeConfig.logLevel);
|
|
1705
|
+
if (force || this.logLevels[logLevel] >= this.logLevels[this.generalLogLevel]) {
|
|
1706
|
+
let meta = this.#buildMeta(type, typeConfig, ...messageObject);
|
|
1707
|
+
const resolveLog = (newLog = false) => {
|
|
1708
|
+
const repeated = (this.lastLog.count || 0) - this.throttleMin;
|
|
1709
|
+
if (this.lastLog.object && repeated > 0) {
|
|
1710
|
+
const lastMeta = { ...this.lastLog.object };
|
|
1711
|
+
if (repeated > 1) {
|
|
1712
|
+
lastMeta.repeated = repeated;
|
|
1713
|
+
}
|
|
1714
|
+
this.#report(lastMeta, raw);
|
|
1715
|
+
this.lastLog.count = 1;
|
|
1716
|
+
}
|
|
1717
|
+
if (newLog) {
|
|
1718
|
+
for (const processor of this.processors) {
|
|
1719
|
+
meta = { ...processor.process(meta) };
|
|
1720
|
+
}
|
|
1721
|
+
this.lastLog.object = meta;
|
|
1722
|
+
this.#report(meta, raw);
|
|
1723
|
+
}
|
|
1724
|
+
};
|
|
1725
|
+
clearTimeout(this.lastLog.timeout);
|
|
1726
|
+
const diffTime = this.lastLog.time && meta.date ? new Date(meta.date).getTime() - this.lastLog.time.getTime() : 0;
|
|
1727
|
+
this.lastLog.time = new Date(meta.date);
|
|
1728
|
+
if (diffTime < this.throttle) {
|
|
1729
|
+
try {
|
|
1730
|
+
const isSameLog = this.lastLog.object && JSON.stringify([meta.label, meta.scope, meta.type, meta.message, meta.prefix, meta.suffix, meta.context]) === JSON.stringify([
|
|
1731
|
+
this.lastLog.object.label,
|
|
1732
|
+
this.lastLog.object.scope,
|
|
1733
|
+
this.lastLog.object.type,
|
|
1734
|
+
this.lastLog.object.message,
|
|
1735
|
+
this.lastLog.object.prefix,
|
|
1736
|
+
this.lastLog.object.suffix,
|
|
1737
|
+
this.lastLog.object.context
|
|
1738
|
+
]);
|
|
1739
|
+
if (isSameLog) {
|
|
1740
|
+
this.lastLog.count = (this.lastLog.count || 0) + 1;
|
|
1741
|
+
if (this.lastLog.count > this.throttleMin) {
|
|
1742
|
+
this.lastLog.timeout = setTimeout(resolveLog, this.throttle);
|
|
1743
|
+
return;
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
} catch {
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
resolveLog(true);
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
24
1753
|
|
|
25
1754
|
class RawReporter {
|
|
26
1755
|
#stdout;
|
|
@@ -505,6 +2234,921 @@ class PailServerImpl extends PailBrowserImpl {
|
|
|
505
2234
|
}
|
|
506
2235
|
const PailServer = PailServerImpl;
|
|
507
2236
|
|
|
2237
|
+
const colorKeywords = /* @__PURE__ */ new Map([
|
|
2238
|
+
["aliceblue", "#f0f8ff"],
|
|
2239
|
+
["antiquewhite", "#faebd7"],
|
|
2240
|
+
["aqua", "#00ffff"],
|
|
2241
|
+
["aquamarine", "#7fffd4"],
|
|
2242
|
+
["azure", "#f0ffff"],
|
|
2243
|
+
["beige", "#f5f5dc"],
|
|
2244
|
+
["bisque", "#ffe4c4"],
|
|
2245
|
+
["black", "#000000"],
|
|
2246
|
+
["blanchedalmond", "#ffebcd"],
|
|
2247
|
+
["blue", "#0000ff"],
|
|
2248
|
+
["blueviolet", "#8a2be2"],
|
|
2249
|
+
["brown", "#a52a2a"],
|
|
2250
|
+
["burlywood", "#deb887"],
|
|
2251
|
+
["cadetblue", "#5f9ea0"],
|
|
2252
|
+
["chartreuse", "#7fff00"],
|
|
2253
|
+
["chocolate", "#d2691e"],
|
|
2254
|
+
["coral", "#ff7f50"],
|
|
2255
|
+
["cornflowerblue", "#6495ed"],
|
|
2256
|
+
["cornsilk", "#fff8dc"],
|
|
2257
|
+
["crimson", "#dc143c"],
|
|
2258
|
+
["cyan", "#00ffff"],
|
|
2259
|
+
["darkblue", "#00008b"],
|
|
2260
|
+
["darkcyan", "#008b8b"],
|
|
2261
|
+
["darkgoldenrod", "#b8860b"],
|
|
2262
|
+
["darkgray", "#a9a9a9"],
|
|
2263
|
+
["darkgreen", "#006400"],
|
|
2264
|
+
["darkgrey", "#a9a9a9"],
|
|
2265
|
+
["darkkhaki", "#bdb76b"],
|
|
2266
|
+
["darkmagenta", "#8b008b"],
|
|
2267
|
+
["darkolivegreen", "#556b2f"],
|
|
2268
|
+
["darkorange", "#ff8c00"],
|
|
2269
|
+
["darkorchid", "#9932cc"],
|
|
2270
|
+
["darkred", "#8b0000"],
|
|
2271
|
+
["darksalmon", "#e9967a"],
|
|
2272
|
+
["darkseagreen", "#8fbc8f"],
|
|
2273
|
+
["darkslateblue", "#483d8b"],
|
|
2274
|
+
["darkslategray", "#2f4f4f"],
|
|
2275
|
+
["darkslategrey", "#2f4f4f"],
|
|
2276
|
+
["darkturquoise", "#00ced1"],
|
|
2277
|
+
["darkviolet", "#9400d3"],
|
|
2278
|
+
["deeppink", "#ff1493"],
|
|
2279
|
+
["deepskyblue", "#00bfff"],
|
|
2280
|
+
["dimgray", "#696969"],
|
|
2281
|
+
["dimgrey", "#696969"],
|
|
2282
|
+
["dodgerblue", "#1e90ff"],
|
|
2283
|
+
["firebrick", "#b22222"],
|
|
2284
|
+
["floralwhite", "#fffaf0"],
|
|
2285
|
+
["forestgreen", "#228b22"],
|
|
2286
|
+
["fuchsia", "#ff00ff"],
|
|
2287
|
+
["gainsboro", "#dcdcdc"],
|
|
2288
|
+
["ghostwhite", "#f8f8ff"],
|
|
2289
|
+
["gold", "#ffd700"],
|
|
2290
|
+
["goldenrod", "#daa520"],
|
|
2291
|
+
["gray", "#808080"],
|
|
2292
|
+
["green", "#008000"],
|
|
2293
|
+
["greenyellow", "#adff2f"],
|
|
2294
|
+
["grey", "#808080"],
|
|
2295
|
+
["honeydew", "#f0fff0"],
|
|
2296
|
+
["hotpink", "#ff69b4"],
|
|
2297
|
+
["indianred", "#cd5c5c"],
|
|
2298
|
+
["indigo", "#4b0082"],
|
|
2299
|
+
["ivory", "#fffff0"],
|
|
2300
|
+
["khaki", "#f0e68c"],
|
|
2301
|
+
["lavender", "#e6e6fa"],
|
|
2302
|
+
["lavenderblush", "#fff0f5"],
|
|
2303
|
+
["lawngreen", "#7cfc00"],
|
|
2304
|
+
["lemonchiffon", "#fffacd"],
|
|
2305
|
+
["lightblue", "#add8e6"],
|
|
2306
|
+
["lightcoral", "#f08080"],
|
|
2307
|
+
["lightcyan", "#e0ffff"],
|
|
2308
|
+
["lightgoldenrodyellow", "#fafad2"],
|
|
2309
|
+
["lightgray", "#d3d3d3"],
|
|
2310
|
+
["lightgreen", "#90ee90"],
|
|
2311
|
+
["lightgrey", "#d3d3d3"],
|
|
2312
|
+
["lightpink", "#ffb6c1"],
|
|
2313
|
+
["lightsalmon", "#ffa07a"],
|
|
2314
|
+
["lightseagreen", "#20b2aa"],
|
|
2315
|
+
["lightskyblue", "#87cefa"],
|
|
2316
|
+
["lightslategray", "#778899"],
|
|
2317
|
+
["lightslategrey", "#778899"],
|
|
2318
|
+
["lightsteelblue", "#b0c4de"],
|
|
2319
|
+
["lightyellow", "#ffffe0"],
|
|
2320
|
+
["lime", "#00ff00"],
|
|
2321
|
+
["limegreen", "#32cd32"],
|
|
2322
|
+
["linen", "#faf0e6"],
|
|
2323
|
+
["magenta", "#ff00ff"],
|
|
2324
|
+
["maroon", "#800000"],
|
|
2325
|
+
["mediumaquamarine", "#66cdaa"],
|
|
2326
|
+
["mediumblue", "#0000cd"],
|
|
2327
|
+
["mediumorchid", "#ba55d3"],
|
|
2328
|
+
["mediumpurple", "#9370db"],
|
|
2329
|
+
["mediumseagreen", "#3cb371"],
|
|
2330
|
+
["mediumslateblue", "#7b68ee"],
|
|
2331
|
+
["mediumspringgreen", "#00fa9a"],
|
|
2332
|
+
["mediumturquoise", "#48d1cc"],
|
|
2333
|
+
["mediumvioletred", "#c71585"],
|
|
2334
|
+
["midnightblue", "#191970"],
|
|
2335
|
+
["mintcream", "#f5fffa"],
|
|
2336
|
+
["mistyrose", "#ffe4e1"],
|
|
2337
|
+
["moccasin", "#ffe4b5"],
|
|
2338
|
+
["navajowhite", "#ffdead"],
|
|
2339
|
+
["navy", "#000080"],
|
|
2340
|
+
["oldlace", "#fdf5e6"],
|
|
2341
|
+
["olive", "#808000"],
|
|
2342
|
+
["olivedrab", "#6b8e23"],
|
|
2343
|
+
["orange", "#ffa500"],
|
|
2344
|
+
["orangered", "#ff4500"],
|
|
2345
|
+
["orchid", "#da70d6"],
|
|
2346
|
+
["palegoldenrod", "#eee8aa"],
|
|
2347
|
+
["palegreen", "#98fb98"],
|
|
2348
|
+
["paleturquoise", "#afeeee"],
|
|
2349
|
+
["palevioletred", "#db7093"],
|
|
2350
|
+
["papayawhip", "#ffefd5"],
|
|
2351
|
+
["peachpuff", "#ffdab9"],
|
|
2352
|
+
["peru", "#cd853f"],
|
|
2353
|
+
["pink", "#ffc0cb"],
|
|
2354
|
+
["plum", "#dda0dd"],
|
|
2355
|
+
["powderblue", "#b0e0e6"],
|
|
2356
|
+
["purple", "#800080"],
|
|
2357
|
+
["rebeccapurple", "#663399"],
|
|
2358
|
+
["red", "#ff0000"],
|
|
2359
|
+
["rosybrown", "#bc8f8f"],
|
|
2360
|
+
["royalblue", "#4169e1"],
|
|
2361
|
+
["saddlebrown", "#8b4513"],
|
|
2362
|
+
["salmon", "#fa8072"],
|
|
2363
|
+
["sandybrown", "#f4a460"],
|
|
2364
|
+
["seagreen", "#2e8b57"],
|
|
2365
|
+
["seashell", "#fff5ee"],
|
|
2366
|
+
["sienna", "#a0522d"],
|
|
2367
|
+
["silver", "#c0c0c0"],
|
|
2368
|
+
["skyblue", "#87ceeb"],
|
|
2369
|
+
["slateblue", "#6a5acd"],
|
|
2370
|
+
["slategray", "#708090"],
|
|
2371
|
+
["slategrey", "#708090"],
|
|
2372
|
+
["snow", "#fffafa"],
|
|
2373
|
+
["springgreen", "#00ff7f"],
|
|
2374
|
+
["steelblue", "#4682b4"],
|
|
2375
|
+
["tan", "#d2b48c"],
|
|
2376
|
+
["teal", "#008080"],
|
|
2377
|
+
["thistle", "#d8bfd8"],
|
|
2378
|
+
["tomato", "#ff6347"],
|
|
2379
|
+
["turquoise", "#40e0d0"],
|
|
2380
|
+
["violet", "#ee82ee"],
|
|
2381
|
+
["wheat", "#f5deb3"],
|
|
2382
|
+
["white", "#ffffff"],
|
|
2383
|
+
["whitesmoke", "#f5f5f5"],
|
|
2384
|
+
["yellow", "#ffff00"],
|
|
2385
|
+
["yellowgreen", "#9acd32"]
|
|
2386
|
+
]);
|
|
2387
|
+
const HASH_PATTERN = /^#([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})?$/i;
|
|
2388
|
+
const SMALL_HASH_PATTERN = /^#([\dA-F])([\dA-F])([\dA-F])([\dA-F])?$/i;
|
|
2389
|
+
const RGB_PATTERN = /^rgba?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/;
|
|
2390
|
+
const HSL_PATTERN = /^hsla?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/;
|
|
2391
|
+
const getDefaultCss = () => {
|
|
2392
|
+
return {
|
|
2393
|
+
__proto__: null,
|
|
2394
|
+
backgroundColor: null,
|
|
2395
|
+
color: null,
|
|
2396
|
+
fontStyle: null,
|
|
2397
|
+
fontWeight: null,
|
|
2398
|
+
textDecorationColor: null,
|
|
2399
|
+
textDecorationLine: []
|
|
2400
|
+
};
|
|
2401
|
+
};
|
|
2402
|
+
const SPACE_PATTERN = /\s+/g;
|
|
2403
|
+
const parseCssColor = (colorString) => {
|
|
2404
|
+
if (colorKeywords.has(colorString)) {
|
|
2405
|
+
colorString = colorKeywords.get(colorString);
|
|
2406
|
+
}
|
|
2407
|
+
const hashMatch = HASH_PATTERN.exec(colorString);
|
|
2408
|
+
if (hashMatch) {
|
|
2409
|
+
return [Number.parseInt(hashMatch[1], 16), Number.parseInt(hashMatch[2], 16), Number.parseInt(hashMatch[3], 16)];
|
|
2410
|
+
}
|
|
2411
|
+
const smallHashMatch = SMALL_HASH_PATTERN.exec(colorString);
|
|
2412
|
+
if (smallHashMatch) {
|
|
2413
|
+
return [
|
|
2414
|
+
Number.parseInt(`${smallHashMatch[1]}${smallHashMatch[1]}`, 16),
|
|
2415
|
+
Number.parseInt(`${smallHashMatch[2]}${smallHashMatch[2]}`, 16),
|
|
2416
|
+
Number.parseInt(`${smallHashMatch[3]}${smallHashMatch[3]}`, 16)
|
|
2417
|
+
];
|
|
2418
|
+
}
|
|
2419
|
+
const rgbMatch = RGB_PATTERN.exec(colorString);
|
|
2420
|
+
if (rgbMatch) {
|
|
2421
|
+
return [
|
|
2422
|
+
Math.round(Math.max(0, Math.min(255, Number(rgbMatch[1])))),
|
|
2423
|
+
Math.round(Math.max(0, Math.min(255, Number(rgbMatch[2])))),
|
|
2424
|
+
Math.round(Math.max(0, Math.min(255, Number(rgbMatch[3]))))
|
|
2425
|
+
];
|
|
2426
|
+
}
|
|
2427
|
+
const hslMatch = HSL_PATTERN.exec(colorString);
|
|
2428
|
+
if (hslMatch) {
|
|
2429
|
+
let h = Number(hslMatch[1]) % 360;
|
|
2430
|
+
if (h < 0) {
|
|
2431
|
+
h += 360;
|
|
2432
|
+
}
|
|
2433
|
+
const s = Math.max(0, Math.min(100, Number(hslMatch[2]))) / 100;
|
|
2434
|
+
const l = Math.max(0, Math.min(100, Number(hslMatch[3]))) / 100;
|
|
2435
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
2436
|
+
const x = c * (1 - Math.abs(h / 60 % 2 - 1));
|
|
2437
|
+
const m = l - c / 2;
|
|
2438
|
+
let r_;
|
|
2439
|
+
let g_;
|
|
2440
|
+
let b_;
|
|
2441
|
+
if (h < 60) {
|
|
2442
|
+
({ 0: r_, 1: g_, 2: b_ } = [c, x, 0]);
|
|
2443
|
+
} else if (h < 120) {
|
|
2444
|
+
({ 0: r_, 1: g_, 2: b_ } = [x, c, 0]);
|
|
2445
|
+
} else if (h < 180) {
|
|
2446
|
+
({ 0: r_, 1: g_, 2: b_ } = [0, c, x]);
|
|
2447
|
+
} else if (h < 240) {
|
|
2448
|
+
({ 0: r_, 1: g_, 2: b_ } = [0, x, c]);
|
|
2449
|
+
} else if (h < 300) {
|
|
2450
|
+
({ 0: r_, 1: g_, 2: b_ } = [x, 0, c]);
|
|
2451
|
+
} else {
|
|
2452
|
+
({ 0: r_, 1: g_, 2: b_ } = [c, 0, x]);
|
|
2453
|
+
}
|
|
2454
|
+
return [Math.round((r_ + m) * 255), Math.round((g_ + m) * 255), Math.round((b_ + m) * 255)];
|
|
2455
|
+
}
|
|
2456
|
+
return null;
|
|
2457
|
+
};
|
|
2458
|
+
const colorEquals = (color1, color2) => color1?.[0] === color2?.[0] && color1?.[1] === color2?.[1] && color1?.[2] === color2?.[2];
|
|
2459
|
+
const parseCss = (cssString) => {
|
|
2460
|
+
const css = getDefaultCss();
|
|
2461
|
+
const rawEntries = [];
|
|
2462
|
+
let inValue = false;
|
|
2463
|
+
let currentKey = null;
|
|
2464
|
+
let parenthesesDepth = 0;
|
|
2465
|
+
let currentPart = "";
|
|
2466
|
+
for (const c of cssString) {
|
|
2467
|
+
if (c === "(") {
|
|
2468
|
+
parenthesesDepth++;
|
|
2469
|
+
} else if (parenthesesDepth > 0) {
|
|
2470
|
+
if (c === ")") {
|
|
2471
|
+
parenthesesDepth--;
|
|
2472
|
+
}
|
|
2473
|
+
} else if (inValue) {
|
|
2474
|
+
if (c === ";") {
|
|
2475
|
+
const value = currentPart.trim();
|
|
2476
|
+
if (value !== "") {
|
|
2477
|
+
rawEntries.push([currentKey, value]);
|
|
2478
|
+
}
|
|
2479
|
+
currentKey = null;
|
|
2480
|
+
currentPart = "";
|
|
2481
|
+
inValue = false;
|
|
2482
|
+
continue;
|
|
2483
|
+
}
|
|
2484
|
+
} else if (c === ":") {
|
|
2485
|
+
currentKey = currentPart.trim();
|
|
2486
|
+
currentPart = "";
|
|
2487
|
+
inValue = true;
|
|
2488
|
+
continue;
|
|
2489
|
+
}
|
|
2490
|
+
currentPart += c;
|
|
2491
|
+
}
|
|
2492
|
+
if (inValue && parenthesesDepth === 0) {
|
|
2493
|
+
const value = currentPart.trim();
|
|
2494
|
+
if (value !== "") {
|
|
2495
|
+
rawEntries.push([currentKey, value]);
|
|
2496
|
+
}
|
|
2497
|
+
currentKey = null;
|
|
2498
|
+
currentPart = "";
|
|
2499
|
+
}
|
|
2500
|
+
for (const { 0: key, 1: value } of rawEntries) {
|
|
2501
|
+
switch (key) {
|
|
2502
|
+
case "background-color": {
|
|
2503
|
+
if (value != void 0) {
|
|
2504
|
+
css.backgroundColor = value;
|
|
2505
|
+
}
|
|
2506
|
+
break;
|
|
2507
|
+
}
|
|
2508
|
+
case "color": {
|
|
2509
|
+
if (value != void 0) {
|
|
2510
|
+
css.color = value;
|
|
2511
|
+
}
|
|
2512
|
+
break;
|
|
2513
|
+
}
|
|
2514
|
+
case "font-style": {
|
|
2515
|
+
if (["italic", "oblique", "oblique 14deg"].includes(value)) {
|
|
2516
|
+
css.fontStyle = "italic";
|
|
2517
|
+
}
|
|
2518
|
+
break;
|
|
2519
|
+
}
|
|
2520
|
+
case "font-weight": {
|
|
2521
|
+
if (value === "bold") {
|
|
2522
|
+
css.fontWeight = value;
|
|
2523
|
+
}
|
|
2524
|
+
break;
|
|
2525
|
+
}
|
|
2526
|
+
case "text-decoration": {
|
|
2527
|
+
css.textDecorationColor = null;
|
|
2528
|
+
css.textDecorationLine = [];
|
|
2529
|
+
const arguments_ = value.split(SPACE_PATTERN);
|
|
2530
|
+
for (const argument of arguments_) {
|
|
2531
|
+
const maybeColor = parseCssColor(argument);
|
|
2532
|
+
if (maybeColor != void 0) {
|
|
2533
|
+
css.textDecorationColor = maybeColor;
|
|
2534
|
+
} else if (["line-through", "overline", "underline"].includes(argument)) {
|
|
2535
|
+
css.textDecorationLine.push(argument);
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2538
|
+
break;
|
|
2539
|
+
}
|
|
2540
|
+
case "text-decoration-color": {
|
|
2541
|
+
const color = parseCssColor(value);
|
|
2542
|
+
if (color != void 0) {
|
|
2543
|
+
css.textDecorationColor = color;
|
|
2544
|
+
}
|
|
2545
|
+
break;
|
|
2546
|
+
}
|
|
2547
|
+
case "text-decoration-line": {
|
|
2548
|
+
css.textDecorationLine = [];
|
|
2549
|
+
const lineTypes = value.split(SPACE_PATTERN);
|
|
2550
|
+
for (const lineType of lineTypes) {
|
|
2551
|
+
if (["line-through", "overline", "underline"].includes(lineType)) {
|
|
2552
|
+
css.textDecorationLine.push(lineType);
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
break;
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
return css;
|
|
2560
|
+
};
|
|
2561
|
+
const cssToAnsi = (css, previousCss = null) => {
|
|
2562
|
+
previousCss = previousCss ?? getDefaultCss();
|
|
2563
|
+
let ansi = "";
|
|
2564
|
+
if (!colorEquals(css.backgroundColor, previousCss.backgroundColor)) {
|
|
2565
|
+
if (css.backgroundColor == void 0) {
|
|
2566
|
+
ansi += "\x1B[49m";
|
|
2567
|
+
} else {
|
|
2568
|
+
switch (css.backgroundColor) {
|
|
2569
|
+
case "black": {
|
|
2570
|
+
ansi += "\x1B[40m";
|
|
2571
|
+
break;
|
|
2572
|
+
}
|
|
2573
|
+
case "blue": {
|
|
2574
|
+
ansi += "\x1B[44m";
|
|
2575
|
+
break;
|
|
2576
|
+
}
|
|
2577
|
+
case "cyan": {
|
|
2578
|
+
ansi += "\x1B[46m";
|
|
2579
|
+
break;
|
|
2580
|
+
}
|
|
2581
|
+
case "green": {
|
|
2582
|
+
ansi += "\x1B[42m";
|
|
2583
|
+
break;
|
|
2584
|
+
}
|
|
2585
|
+
case "magenta": {
|
|
2586
|
+
ansi += "\x1B[45m";
|
|
2587
|
+
break;
|
|
2588
|
+
}
|
|
2589
|
+
case "red": {
|
|
2590
|
+
ansi += "\x1B[41m";
|
|
2591
|
+
break;
|
|
2592
|
+
}
|
|
2593
|
+
case "white": {
|
|
2594
|
+
ansi += "\x1B[47m";
|
|
2595
|
+
break;
|
|
2596
|
+
}
|
|
2597
|
+
case "yellow": {
|
|
2598
|
+
ansi += "\x1B[43m";
|
|
2599
|
+
break;
|
|
2600
|
+
}
|
|
2601
|
+
default: {
|
|
2602
|
+
if (Array.isArray(css.backgroundColor)) {
|
|
2603
|
+
const { 0: r, 1: g, 2: b } = css.backgroundColor;
|
|
2604
|
+
ansi += `\x1B[48;2;${r};${g};${b}m`;
|
|
2605
|
+
} else {
|
|
2606
|
+
const parsed = parseCssColor(css.backgroundColor);
|
|
2607
|
+
if (parsed === null) {
|
|
2608
|
+
ansi += "\x1B[49m";
|
|
2609
|
+
} else {
|
|
2610
|
+
const { 0: r, 1: g, 2: b } = parsed;
|
|
2611
|
+
ansi += `\x1B[48;2;${r};${g};${b}m`;
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
if (!colorEquals(css.color, previousCss.color)) {
|
|
2619
|
+
if (css.color == void 0) {
|
|
2620
|
+
ansi += "\x1B[39m";
|
|
2621
|
+
} else {
|
|
2622
|
+
switch (css.color) {
|
|
2623
|
+
case "black": {
|
|
2624
|
+
ansi += "\x1B[30m";
|
|
2625
|
+
break;
|
|
2626
|
+
}
|
|
2627
|
+
case "blue": {
|
|
2628
|
+
ansi += "\x1B[34m";
|
|
2629
|
+
break;
|
|
2630
|
+
}
|
|
2631
|
+
case "cyan": {
|
|
2632
|
+
ansi += "\x1B[36m";
|
|
2633
|
+
break;
|
|
2634
|
+
}
|
|
2635
|
+
case "green": {
|
|
2636
|
+
ansi += "\x1B[32m";
|
|
2637
|
+
break;
|
|
2638
|
+
}
|
|
2639
|
+
case "magenta": {
|
|
2640
|
+
ansi += "\x1B[35m";
|
|
2641
|
+
break;
|
|
2642
|
+
}
|
|
2643
|
+
case "red": {
|
|
2644
|
+
ansi += "\x1B[31m";
|
|
2645
|
+
break;
|
|
2646
|
+
}
|
|
2647
|
+
case "white": {
|
|
2648
|
+
ansi += "\x1B[37m";
|
|
2649
|
+
break;
|
|
2650
|
+
}
|
|
2651
|
+
case "yellow": {
|
|
2652
|
+
ansi += "\x1B[33m";
|
|
2653
|
+
break;
|
|
2654
|
+
}
|
|
2655
|
+
default: {
|
|
2656
|
+
if (Array.isArray(css.color)) {
|
|
2657
|
+
const { 0: r, 1: g, 2: b } = css.color;
|
|
2658
|
+
ansi += `\x1B[38;2;${r};${g};${b}m`;
|
|
2659
|
+
} else {
|
|
2660
|
+
const parsed = parseCssColor(css.color);
|
|
2661
|
+
if (parsed === null) {
|
|
2662
|
+
ansi += "\x1B[39m";
|
|
2663
|
+
} else {
|
|
2664
|
+
const { 0: r, 1: g, 2: b } = parsed;
|
|
2665
|
+
ansi += `\x1B[38;2;${r};${g};${b}m`;
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
if (css.fontWeight !== previousCss.fontWeight) {
|
|
2673
|
+
ansi += css.fontWeight === "bold" ? "\x1B[1m" : "\x1B[22m";
|
|
2674
|
+
}
|
|
2675
|
+
if (css.fontStyle !== previousCss.fontStyle) {
|
|
2676
|
+
ansi += css.fontStyle === "italic" ? "\x1B[3m" : "\x1B[23m";
|
|
2677
|
+
}
|
|
2678
|
+
if (!colorEquals(css.textDecorationColor, previousCss.textDecorationColor)) {
|
|
2679
|
+
if (css.textDecorationColor == void 0) {
|
|
2680
|
+
ansi += "\x1B[59m";
|
|
2681
|
+
} else {
|
|
2682
|
+
const { 0: r, 1: g, 2: b } = css.textDecorationColor;
|
|
2683
|
+
ansi += `\x1B[58;2;${r};${g};${b}m`;
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
if (css.textDecorationLine.includes("line-through") !== previousCss.textDecorationLine.includes("line-through")) {
|
|
2687
|
+
ansi += css.textDecorationLine.includes("line-through") ? "\x1B[9m" : "\x1B[29m";
|
|
2688
|
+
}
|
|
2689
|
+
if (css.textDecorationLine.includes("overline") !== previousCss.textDecorationLine.includes("overline")) {
|
|
2690
|
+
ansi += css.textDecorationLine.includes("overline") ? "\x1B[53m" : "\x1B[55m";
|
|
2691
|
+
}
|
|
2692
|
+
if (css.textDecorationLine.includes("underline") !== previousCss.textDecorationLine.includes("underline")) {
|
|
2693
|
+
ansi += css.textDecorationLine.includes("underline") ? "\x1B[4m" : "\x1B[24m";
|
|
2694
|
+
}
|
|
2695
|
+
return ansi;
|
|
2696
|
+
};
|
|
2697
|
+
const tryStringify = (o) => {
|
|
2698
|
+
try {
|
|
2699
|
+
return JSON.stringify(o);
|
|
2700
|
+
} catch {
|
|
2701
|
+
return '"[Circular]"';
|
|
2702
|
+
}
|
|
2703
|
+
};
|
|
2704
|
+
const CHAR_PERCENT = "%".codePointAt(0);
|
|
2705
|
+
const CHAR_s = "s".codePointAt(0);
|
|
2706
|
+
const CHAR_d = "d".codePointAt(0);
|
|
2707
|
+
const CHAR_f = "f".codePointAt(0);
|
|
2708
|
+
const CHAR_i = "i".codePointAt(0);
|
|
2709
|
+
const CHAR_O = "O".codePointAt(0);
|
|
2710
|
+
const CHAR_o = "o".codePointAt(0);
|
|
2711
|
+
const CHAR_j = "j".codePointAt(0);
|
|
2712
|
+
const CHAR_c = "c".codePointAt(0);
|
|
2713
|
+
const format = (fmt, arguments_ = [], options = {}) => {
|
|
2714
|
+
if (typeof fmt !== "string" && typeof fmt !== "object" || fmt === null) {
|
|
2715
|
+
throw new TypeError(`fmt must be a string or object, got ${fmt === null ? "null" : typeof fmt}`);
|
|
2716
|
+
}
|
|
2717
|
+
const stringify = options.stringify ?? tryStringify;
|
|
2718
|
+
const offset = 1;
|
|
2719
|
+
if (typeof fmt === "object") {
|
|
2720
|
+
const argumentsLength = arguments_.length + offset;
|
|
2721
|
+
if (argumentsLength === 1) {
|
|
2722
|
+
return "{}";
|
|
2723
|
+
}
|
|
2724
|
+
const objects = Array.from({ length: argumentsLength });
|
|
2725
|
+
objects[0] = stringify(fmt);
|
|
2726
|
+
for (let index = 1; index < argumentsLength; index++) {
|
|
2727
|
+
objects[index] = stringify(arguments_[index - offset]);
|
|
2728
|
+
}
|
|
2729
|
+
return objects.join(" ");
|
|
2730
|
+
}
|
|
2731
|
+
if (arguments_.length === 0) {
|
|
2732
|
+
return fmt;
|
|
2733
|
+
}
|
|
2734
|
+
let result = "";
|
|
2735
|
+
let a = 1 - offset;
|
|
2736
|
+
let lastPosition = -1;
|
|
2737
|
+
let usedStyle = false;
|
|
2738
|
+
let previousCss = null;
|
|
2739
|
+
for (let index = 0; index < fmt.length; ) {
|
|
2740
|
+
if (fmt.codePointAt(index) === CHAR_PERCENT && index + 1 < fmt.length) {
|
|
2741
|
+
lastPosition = lastPosition > -1 ? lastPosition : 0;
|
|
2742
|
+
const c = fmt.codePointAt(index + 1);
|
|
2743
|
+
if (c === void 0) {
|
|
2744
|
+
++a;
|
|
2745
|
+
break;
|
|
2746
|
+
}
|
|
2747
|
+
switch (c) {
|
|
2748
|
+
case CHAR_c: {
|
|
2749
|
+
if (globalThis.window === void 0) {
|
|
2750
|
+
const css = parseCss(arguments_[a]);
|
|
2751
|
+
if (lastPosition < index) {
|
|
2752
|
+
result += fmt.slice(lastPosition, index);
|
|
2753
|
+
}
|
|
2754
|
+
result += cssToAnsi(css, previousCss);
|
|
2755
|
+
if (result !== "") {
|
|
2756
|
+
usedStyle = true;
|
|
2757
|
+
previousCss = css;
|
|
2758
|
+
}
|
|
2759
|
+
}
|
|
2760
|
+
lastPosition = index + 2;
|
|
2761
|
+
index++;
|
|
2762
|
+
break;
|
|
2763
|
+
}
|
|
2764
|
+
case CHAR_d:
|
|
2765
|
+
case CHAR_f: {
|
|
2766
|
+
if (a >= arguments_.length || arguments_[a] == void 0) {
|
|
2767
|
+
break;
|
|
2768
|
+
}
|
|
2769
|
+
if (lastPosition < index) {
|
|
2770
|
+
result += fmt.slice(lastPosition, index);
|
|
2771
|
+
}
|
|
2772
|
+
result += Number(arguments_[a]).toString();
|
|
2773
|
+
lastPosition = index + 2;
|
|
2774
|
+
index++;
|
|
2775
|
+
break;
|
|
2776
|
+
}
|
|
2777
|
+
case CHAR_i: {
|
|
2778
|
+
if (a >= arguments_.length || arguments_[a] == void 0) {
|
|
2779
|
+
break;
|
|
2780
|
+
}
|
|
2781
|
+
if (lastPosition < index) {
|
|
2782
|
+
result += fmt.slice(lastPosition, index);
|
|
2783
|
+
}
|
|
2784
|
+
result += Math.floor(Number(arguments_[a])).toString();
|
|
2785
|
+
lastPosition = index + 2;
|
|
2786
|
+
index++;
|
|
2787
|
+
break;
|
|
2788
|
+
}
|
|
2789
|
+
case CHAR_j:
|
|
2790
|
+
case CHAR_O:
|
|
2791
|
+
case CHAR_o: {
|
|
2792
|
+
if (a >= arguments_.length || arguments_[a] === void 0) {
|
|
2793
|
+
break;
|
|
2794
|
+
}
|
|
2795
|
+
if (lastPosition < index) {
|
|
2796
|
+
result += fmt.slice(lastPosition, index);
|
|
2797
|
+
}
|
|
2798
|
+
const temporaryArgument = arguments_[a];
|
|
2799
|
+
const type = typeof temporaryArgument;
|
|
2800
|
+
if (type === "string") {
|
|
2801
|
+
result += `'${temporaryArgument}'`;
|
|
2802
|
+
lastPosition = index + 2;
|
|
2803
|
+
break;
|
|
2804
|
+
}
|
|
2805
|
+
if (type === "function") {
|
|
2806
|
+
result += temporaryArgument.name ? `[Function: ${temporaryArgument.name}]` : "[Function: <anonymous>]";
|
|
2807
|
+
lastPosition = index + 2;
|
|
2808
|
+
break;
|
|
2809
|
+
}
|
|
2810
|
+
result += stringify(temporaryArgument);
|
|
2811
|
+
lastPosition = index + 2;
|
|
2812
|
+
index++;
|
|
2813
|
+
break;
|
|
2814
|
+
}
|
|
2815
|
+
case CHAR_PERCENT: {
|
|
2816
|
+
if (lastPosition < index) {
|
|
2817
|
+
result += fmt.slice(lastPosition, index);
|
|
2818
|
+
}
|
|
2819
|
+
result += "%";
|
|
2820
|
+
lastPosition = index + 2;
|
|
2821
|
+
index++;
|
|
2822
|
+
a--;
|
|
2823
|
+
break;
|
|
2824
|
+
}
|
|
2825
|
+
case CHAR_s: {
|
|
2826
|
+
if (a >= arguments_.length) {
|
|
2827
|
+
break;
|
|
2828
|
+
}
|
|
2829
|
+
if (lastPosition < index) {
|
|
2830
|
+
result += fmt.slice(lastPosition, index);
|
|
2831
|
+
}
|
|
2832
|
+
result += typeof arguments_[a] === "object" ? stringify(arguments_[a]) : String(arguments_[a]);
|
|
2833
|
+
lastPosition = index + 2;
|
|
2834
|
+
index++;
|
|
2835
|
+
break;
|
|
2836
|
+
}
|
|
2837
|
+
default: {
|
|
2838
|
+
if (typeof options.formatters?.[c] === "function") {
|
|
2839
|
+
if (lastPosition < index) {
|
|
2840
|
+
result += fmt.slice(lastPosition, index);
|
|
2841
|
+
}
|
|
2842
|
+
result += options.formatters[c](arguments_[a]);
|
|
2843
|
+
lastPosition = index + 2;
|
|
2844
|
+
index++;
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
++a;
|
|
2849
|
+
}
|
|
2850
|
+
++index;
|
|
2851
|
+
}
|
|
2852
|
+
if (lastPosition === -1) {
|
|
2853
|
+
return fmt;
|
|
2854
|
+
}
|
|
2855
|
+
if (lastPosition < fmt.length) {
|
|
2856
|
+
result += fmt.slice(lastPosition);
|
|
2857
|
+
}
|
|
2858
|
+
if (usedStyle) {
|
|
2859
|
+
result += "\x1B[0m";
|
|
2860
|
+
}
|
|
2861
|
+
return result;
|
|
2862
|
+
};
|
|
2863
|
+
const build = (options = {}) => {
|
|
2864
|
+
const formatters = {};
|
|
2865
|
+
if (typeof options.formatters === "object") {
|
|
2866
|
+
Object.entries(options.formatters).forEach(([key, formatterFunction]) => {
|
|
2867
|
+
if (key.length === 0) {
|
|
2868
|
+
throw new Error(`Formatter %${key} has no characters`);
|
|
2869
|
+
}
|
|
2870
|
+
if (key.length > 1) {
|
|
2871
|
+
throw new Error(`Formatter %${key} has more than one character`);
|
|
2872
|
+
}
|
|
2873
|
+
if (typeof formatterFunction !== "function") {
|
|
2874
|
+
throw new TypeError(`Formatter for %${key} is not a function`);
|
|
2875
|
+
}
|
|
2876
|
+
const c = key.codePointAt(0);
|
|
2877
|
+
if (c === void 0) {
|
|
2878
|
+
throw new Error(`${key}.codePointAt(0) failed to return a value, please report this issue`);
|
|
2879
|
+
}
|
|
2880
|
+
formatters[c] = formatterFunction;
|
|
2881
|
+
});
|
|
2882
|
+
}
|
|
2883
|
+
return (f, arguments_ = [], formatOptions = {}) => format(f, arguments_, { ...formatOptions, formatters });
|
|
2884
|
+
};
|
|
2885
|
+
|
|
2886
|
+
class MessageFormatterProcessor {
|
|
2887
|
+
/** Custom stringify function for object serialization */
|
|
2888
|
+
#stringify;
|
|
2889
|
+
/** Custom formatters for message interpolation */
|
|
2890
|
+
#formatters;
|
|
2891
|
+
/**
|
|
2892
|
+
* Creates a new MessageFormatterProcessor instance.
|
|
2893
|
+
* @param options Configuration options
|
|
2894
|
+
* @param options.formatters Custom formatters for message interpolation
|
|
2895
|
+
*/
|
|
2896
|
+
constructor(options = {}) {
|
|
2897
|
+
this.#formatters = options.formatters;
|
|
2898
|
+
}
|
|
2899
|
+
/**
|
|
2900
|
+
* Sets the stringify function for object serialization.
|
|
2901
|
+
* @param function_ The stringify function to use for serializing objects
|
|
2902
|
+
*/
|
|
2903
|
+
setStringify(function_) {
|
|
2904
|
+
this.#stringify = function_;
|
|
2905
|
+
}
|
|
2906
|
+
/**
|
|
2907
|
+
* Processes log metadata to format messages.
|
|
2908
|
+
*
|
|
2909
|
+
* Applies string interpolation and custom formatters to the message
|
|
2910
|
+
* and contextual data in the log metadata.
|
|
2911
|
+
* @param meta The log metadata to process
|
|
2912
|
+
* @returns The processed metadata with formatted messages
|
|
2913
|
+
*/
|
|
2914
|
+
process(meta) {
|
|
2915
|
+
const formatter = build({
|
|
2916
|
+
formatters: this.#formatters});
|
|
2917
|
+
if (meta.message !== void 0) {
|
|
2918
|
+
meta.message = this.#format(formatter, meta.message, meta.context ?? []);
|
|
2919
|
+
}
|
|
2920
|
+
return meta;
|
|
2921
|
+
}
|
|
2922
|
+
/**
|
|
2923
|
+
* Recursively formats data using the formatter.
|
|
2924
|
+
*
|
|
2925
|
+
* Applies string interpolation and formatting to strings, arrays, and objects.
|
|
2926
|
+
* @param formatter The formatter function to use
|
|
2927
|
+
* @param data The data to format (string, array, or object)
|
|
2928
|
+
* @param arguments_ Additional arguments for formatting
|
|
2929
|
+
* @returns The formatted data
|
|
2930
|
+
* @private
|
|
2931
|
+
*/
|
|
2932
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2933
|
+
#format(formatter, data, arguments_ = []) {
|
|
2934
|
+
if (typeof data === "string") {
|
|
2935
|
+
return formatter(data, arguments_);
|
|
2936
|
+
}
|
|
2937
|
+
if (typeof data === "object" && data !== null) {
|
|
2938
|
+
for (const index in data) {
|
|
2939
|
+
const value = data[index];
|
|
2940
|
+
if (typeof value === "string" || Array.isArray(value) || typeof value === "object") {
|
|
2941
|
+
data[index] = this.#format(formatter, value, arguments_);
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
return data;
|
|
2946
|
+
}
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
const pailFileFilter = (line) => !/[\\/]pail[\\/]dist/.test(line);
|
|
2950
|
+
class PrettyReporter extends AbstractPrettyReporter {
|
|
2951
|
+
#stdout;
|
|
2952
|
+
#stderr;
|
|
2953
|
+
#interactiveManager;
|
|
2954
|
+
#interactive = false;
|
|
2955
|
+
#inspectOptions;
|
|
2956
|
+
#errorOptions;
|
|
2957
|
+
/**
|
|
2958
|
+
* Creates a new Server Pretty Reporter instance.
|
|
2959
|
+
* @param options Configuration options for styling, error rendering, and object inspection
|
|
2960
|
+
*/
|
|
2961
|
+
constructor(options = {}) {
|
|
2962
|
+
const { error: errorOptions, inspect: inspectOptions, ...rest } = options;
|
|
2963
|
+
super({
|
|
2964
|
+
uppercase: {
|
|
2965
|
+
label: true,
|
|
2966
|
+
...rest.uppercase
|
|
2967
|
+
},
|
|
2968
|
+
...rest
|
|
2969
|
+
});
|
|
2970
|
+
this.#inspectOptions = { ...defaultInspectorConfig, ...inspectOptions };
|
|
2971
|
+
this.#errorOptions = {
|
|
2972
|
+
...errorOptions,
|
|
2973
|
+
color: {
|
|
2974
|
+
fileLine: green,
|
|
2975
|
+
hint: cyan,
|
|
2976
|
+
marker: red,
|
|
2977
|
+
message: red,
|
|
2978
|
+
method: greenBright,
|
|
2979
|
+
title: red
|
|
2980
|
+
}
|
|
2981
|
+
};
|
|
2982
|
+
this.#stdout = stdout;
|
|
2983
|
+
this.#stderr = stderr;
|
|
2984
|
+
}
|
|
2985
|
+
/**
|
|
2986
|
+
* Sets the stdout stream for the reporter.
|
|
2987
|
+
* @param stdout_ The writable stream to use for standard output
|
|
2988
|
+
*/
|
|
2989
|
+
setStdout(stdout_) {
|
|
2990
|
+
this.#stdout = stdout_;
|
|
2991
|
+
}
|
|
2992
|
+
/**
|
|
2993
|
+
* Sets the stderr stream for the reporter.
|
|
2994
|
+
* @param stderr_ The writable stream to use for error output
|
|
2995
|
+
*/
|
|
2996
|
+
setStderr(stderr_) {
|
|
2997
|
+
this.#stderr = stderr_;
|
|
2998
|
+
}
|
|
2999
|
+
/**
|
|
3000
|
+
* Sets the interactive manager for handling interactive output.
|
|
3001
|
+
* @param manager The interactive manager instance, or undefined to disable
|
|
3002
|
+
*/
|
|
3003
|
+
setInteractiveManager(manager) {
|
|
3004
|
+
this.#interactiveManager = manager;
|
|
3005
|
+
}
|
|
3006
|
+
/**
|
|
3007
|
+
* Enables or disables interactive mode.
|
|
3008
|
+
* @param interactive Whether to enable interactive terminal features
|
|
3009
|
+
*/
|
|
3010
|
+
setIsInteractive(interactive) {
|
|
3011
|
+
this.#interactive = interactive;
|
|
3012
|
+
}
|
|
3013
|
+
log(meta) {
|
|
3014
|
+
this._log(this._formatMessage(meta), meta.type.level);
|
|
3015
|
+
}
|
|
3016
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity, no-underscore-dangle
|
|
3017
|
+
_formatMessage(data) {
|
|
3018
|
+
const { columns } = terminalSize();
|
|
3019
|
+
let size = columns;
|
|
3020
|
+
if (typeof this.styles.messageLength === "number") {
|
|
3021
|
+
size = this.styles.messageLength;
|
|
3022
|
+
}
|
|
3023
|
+
const { badge, context, date, error, file, groups, label, message, prefix, repeated, scope, suffix, traceError, type } = data;
|
|
3024
|
+
const { color } = this.loggerTypes[type.name];
|
|
3025
|
+
const colorized = color ? colorize[color] : white;
|
|
3026
|
+
const groupSpaces = groups.map(() => " ").join("");
|
|
3027
|
+
const items = [];
|
|
3028
|
+
if (groups.length > 0) {
|
|
3029
|
+
items.push(`${groupSpaces + grey(`[${groups.at(-1)}]`)} `);
|
|
3030
|
+
}
|
|
3031
|
+
if (date) {
|
|
3032
|
+
items.push(`${grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date))} `);
|
|
3033
|
+
}
|
|
3034
|
+
if (badge) {
|
|
3035
|
+
items.push(colorized(badge));
|
|
3036
|
+
} else {
|
|
3037
|
+
const longestBadge = getLongestBadge(this.loggerTypes);
|
|
3038
|
+
if (longestBadge.length > 0) {
|
|
3039
|
+
items.push(`${grey(".".repeat(longestBadge.length))} `);
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
3042
|
+
const longestLabel = getLongestLabel(this.loggerTypes);
|
|
3043
|
+
if (label) {
|
|
3044
|
+
const longestLabelWidth = getStringWidth(longestLabel);
|
|
3045
|
+
const labelWidth = getStringWidth(label);
|
|
3046
|
+
items.push(`${colorized(formatLabel(label, this.styles))} `, grey(".".repeat(Math.max(0, longestLabelWidth - labelWidth))));
|
|
3047
|
+
} else {
|
|
3048
|
+
items.push(grey(".".repeat(longestLabel.length + 2)));
|
|
3049
|
+
}
|
|
3050
|
+
if (repeated) {
|
|
3051
|
+
items.push(`${bgGrey.white(`[${repeated}x]`)} `);
|
|
3052
|
+
}
|
|
3053
|
+
if (Array.isArray(scope) && scope.length > 0) {
|
|
3054
|
+
items.push(` ${grey(`[${scope.join(" > ")}]`)} `);
|
|
3055
|
+
}
|
|
3056
|
+
if (prefix) {
|
|
3057
|
+
items.push(
|
|
3058
|
+
`${grey(`${Array.isArray(scope) && scope.length > 0 ? ". " : " "}[${this.styles.underline.prefix ? underline(prefix) : prefix}]`)} `
|
|
3059
|
+
);
|
|
3060
|
+
}
|
|
3061
|
+
const titleSize = getStringWidth(items.join(" "));
|
|
3062
|
+
if (file) {
|
|
3063
|
+
const fileMessage = file.name + (file.line ? `:${file.line}` : "");
|
|
3064
|
+
const fileMessageSize = getStringWidth(fileMessage);
|
|
3065
|
+
if (fileMessageSize + titleSize + 2 > size) {
|
|
3066
|
+
items.push(grey(` ${fileMessage}`));
|
|
3067
|
+
} else {
|
|
3068
|
+
const dots = Math.max(0, size - titleSize - fileMessageSize - 2);
|
|
3069
|
+
items.push(grey(`${".".repeat(dots)} ${fileMessage}`));
|
|
3070
|
+
}
|
|
3071
|
+
} else {
|
|
3072
|
+
items.push(grey(".".repeat(Math.max(0, size - titleSize - 1))));
|
|
3073
|
+
}
|
|
3074
|
+
if (items.length > 0) {
|
|
3075
|
+
items.push("\n\n");
|
|
3076
|
+
}
|
|
3077
|
+
if (message !== EMPTY_SYMBOL) {
|
|
3078
|
+
const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
|
|
3079
|
+
items.push(
|
|
3080
|
+
groupSpaces + wordWrap(formattedMessage, {
|
|
3081
|
+
trim: false,
|
|
3082
|
+
width: size - 3,
|
|
3083
|
+
wrapMode: WrapMode.STRICT_WIDTH
|
|
3084
|
+
})
|
|
3085
|
+
);
|
|
3086
|
+
}
|
|
3087
|
+
if (context) {
|
|
3088
|
+
let hasError = false;
|
|
3089
|
+
items.push(
|
|
3090
|
+
...context.map((value) => {
|
|
3091
|
+
if (value instanceof Error) {
|
|
3092
|
+
hasError = true;
|
|
3093
|
+
return `
|
|
3094
|
+
|
|
3095
|
+
${renderError(value, {
|
|
3096
|
+
...this.#errorOptions,
|
|
3097
|
+
filterStacktrace: pailFileFilter,
|
|
3098
|
+
prefix: groupSpaces
|
|
3099
|
+
})}`;
|
|
3100
|
+
}
|
|
3101
|
+
if (typeof value === "object") {
|
|
3102
|
+
return ` ${inspect(value, this.#inspectOptions)}`;
|
|
3103
|
+
}
|
|
3104
|
+
const newValue = (hasError ? "\n\n" : " ") + value;
|
|
3105
|
+
hasError = false;
|
|
3106
|
+
return newValue;
|
|
3107
|
+
})
|
|
3108
|
+
);
|
|
3109
|
+
}
|
|
3110
|
+
if (error) {
|
|
3111
|
+
items.push(
|
|
3112
|
+
renderError(error, {
|
|
3113
|
+
...this.#errorOptions,
|
|
3114
|
+
filterStacktrace: pailFileFilter,
|
|
3115
|
+
prefix: groupSpaces
|
|
3116
|
+
})
|
|
3117
|
+
);
|
|
3118
|
+
}
|
|
3119
|
+
if (traceError) {
|
|
3120
|
+
items.push(
|
|
3121
|
+
`
|
|
3122
|
+
|
|
3123
|
+
${renderError(traceError, {
|
|
3124
|
+
...this.#errorOptions,
|
|
3125
|
+
filterStacktrace: pailFileFilter,
|
|
3126
|
+
hideErrorCauseCodeView: true,
|
|
3127
|
+
hideErrorCodeView: true,
|
|
3128
|
+
hideErrorErrorsCodeView: true,
|
|
3129
|
+
hideMessage: true,
|
|
3130
|
+
prefix: groupSpaces
|
|
3131
|
+
})}`
|
|
3132
|
+
);
|
|
3133
|
+
}
|
|
3134
|
+
if (suffix) {
|
|
3135
|
+
items.push("\n", groupSpaces + grey(this.styles.underline.suffix ? underline(suffix) : suffix));
|
|
3136
|
+
}
|
|
3137
|
+
return items.join("");
|
|
3138
|
+
}
|
|
3139
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
3140
|
+
_log(message, logLevel) {
|
|
3141
|
+
const streamType = ["error", "trace", "warn"].includes(logLevel) ? "stderr" : "stdout";
|
|
3142
|
+
const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
|
|
3143
|
+
if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
|
|
3144
|
+
this.#interactiveManager.update(streamType, message.split("\n"), 0);
|
|
3145
|
+
} else {
|
|
3146
|
+
writeStream(`${message}
|
|
3147
|
+
`, stream);
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
|
|
508
3152
|
const getDefaultLogLevel = () => {
|
|
509
3153
|
if (env.NODE_ENV === "debug" || env.DEBUG !== void 0) {
|
|
510
3154
|
return "debug";
|