@andrew_l/pino-pretty 0.3.22 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,61 +1,47 @@
1
- import { Transform } from 'node:stream';
2
- import abstractTransport from 'pino-abstract-transport';
3
- import pump from 'pump';
4
- import { noop, isObject, isFunction, typeOf, isPrimitive, withCache, crc32, deepDefaults, arrayable, capitalize, isString, omit, def, has } from '@andrew_l/toolkit';
5
- import path from 'node:path';
6
- import { inspect, formatWithOptions } from 'node:util';
7
- import _SonicBoom from 'sonic-boom';
8
- import { isMainThread } from 'node:worker_threads';
9
- import * as tty from 'node:tty';
10
- import { StringWidth } from '@cto.af/string-width';
11
-
1
+ import { Transform } from "node:stream";
2
+ import abstractTransport from "pino-abstract-transport";
3
+ import pump from "pump";
4
+ import { arrayable, capitalize, crc32, deepDefaults, def, has, isFunction, isObject, isPrimitive, isString, noop, omit, typeOf, withCache } from "@andrew_l/toolkit";
5
+ import path from "node:path";
6
+ import { formatWithOptions, inspect } from "node:util";
7
+ import _SonicBoom from "sonic-boom";
8
+ import { isMainThread } from "node:worker_threads";
9
+ import * as tty from "node:tty";
10
+ import { StringWidth } from "@cto.af/string-width";
12
11
  function buildSafeSonicBoom(opts) {
13
- const stream = new _SonicBoom(opts);
14
- stream.on("error", filterBrokenPipe);
15
- if (!process.env.NODE_V8_COVERAGE && !opts.sync && isMainThread) {
16
- setupOnExit(stream);
17
- }
18
- return stream;
19
- function filterBrokenPipe(err) {
20
- if (err.code === "EPIPE") {
21
- stream.write = noop;
22
- stream.end = noop;
23
- stream.flushSync = noop;
24
- stream.destroy = noop;
25
- return;
26
- }
27
- stream.removeListener("error", filterBrokenPipe);
28
- }
12
+ const stream = new _SonicBoom(opts);
13
+ stream.on("error", filterBrokenPipe);
14
+ if (!process.env.NODE_V8_COVERAGE && !opts.sync && isMainThread) setupOnExit(stream);
15
+ return stream;
16
+ function filterBrokenPipe(err) {
17
+ if (err.code === "EPIPE") {
18
+ stream.write = noop;
19
+ stream.end = noop;
20
+ stream.flushSync = noop;
21
+ stream.destroy = noop;
22
+ return;
23
+ }
24
+ stream.removeListener("error", filterBrokenPipe);
25
+ }
29
26
  }
30
27
  function setupOnExit(stream) {
31
- if (global.WeakRef && global.WeakMap && global.FinalizationRegistry) {
32
- import('on-exit-leak-free').then((onExit) => {
33
- onExit.register(stream, autoEnd);
34
- stream.on("close", function() {
35
- onExit.unregister(stream);
36
- });
37
- });
38
- }
28
+ if (global.WeakRef && global.WeakMap && global.FinalizationRegistry) import("on-exit-leak-free").then((onExit) => {
29
+ onExit.register(stream, autoEnd);
30
+ stream.on("close", function() {
31
+ onExit.unregister(stream);
32
+ });
33
+ });
39
34
  }
40
35
  function autoEnd(stream, eventName) {
41
- if (stream.destroyed) {
42
- return;
43
- }
44
- if (eventName === "beforeExit") {
45
- stream.flush();
46
- stream.on("drain", function() {
47
- stream.end();
48
- });
49
- } else {
50
- stream.flushSync();
51
- }
52
- }
53
-
54
- const {
55
- env = {},
56
- argv = [],
57
- platform = ""
58
- } = typeof process === "undefined" ? {} : process;
36
+ if (stream.destroyed) return;
37
+ if (eventName === "beforeExit") {
38
+ stream.flush();
39
+ stream.on("drain", function() {
40
+ stream.end();
41
+ });
42
+ } else stream.flushSync();
43
+ }
44
+ const { env = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
59
45
  const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
60
46
  const isForced = "FORCE_COLOR" in env || argv.includes("--color");
61
47
  const isWindows = platform === "win32";
@@ -64,652 +50,579 @@ const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !
64
50
  const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
65
51
  const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
66
52
  function replaceClose(index, string, close, replace, head = string.slice(0, Math.max(0, index)) + replace, tail = string.slice(Math.max(0, index + close.length)), next = tail.indexOf(close)) {
67
- return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
53
+ return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
68
54
  }
69
55
  function clearBleed(index, string, open, close, replace) {
70
- return index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
56
+ return index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
71
57
  }
72
58
  function filterEmpty(open, close, replace = open, at = open.length + 1) {
73
- return (string) => string || !(string === "" || string === void 0) ? clearBleed(
74
- ("" + string).indexOf(close, at),
75
- string,
76
- open,
77
- close,
78
- replace
79
- ) : "";
59
+ return (string) => string || !(string === "" || string === void 0) ? clearBleed(("" + string).indexOf(close, at), string, open, close, replace) : "";
80
60
  }
81
61
  function init(open, close, replace) {
82
- return filterEmpty(`\x1B[${open}m`, `\x1B[${close}m`, replace);
62
+ return filterEmpty(`\u001B[${open}m`, `\u001B[${close}m`, replace);
83
63
  }
84
64
  function init256Color(code, isBg = false) {
85
- const prefix = isBg ? "48;5;" : "38;5;";
86
- const closeCode = isBg ? 49 : 39;
87
- return filterEmpty(`\x1B[${prefix}${code}m`, `\x1B[${closeCode}m`);
65
+ const prefix = isBg ? "48;5;" : "38;5;";
66
+ const closeCode = isBg ? 49 : 39;
67
+ return filterEmpty(`\u001B[${prefix}${code}m`, `\u001B[${closeCode}m`);
88
68
  }
89
69
  const colorDefs = {
90
- reset: init(0, 0),
91
- bold: init(1, 22, "\x1B[22m\x1B[1m"),
92
- dim: init(2, 22, "\x1B[22m\x1B[2m"),
93
- italic: init(3, 23),
94
- underline: init(4, 24),
95
- inverse: init(7, 27),
96
- hidden: init(8, 28),
97
- strikethrough: init(9, 29),
98
- black: init(30, 39),
99
- red: init(31, 39),
100
- green: init(32, 39),
101
- yellow: init(33, 39),
102
- blue: init(34, 39),
103
- magenta: init(35, 39),
104
- cyan: init(36, 39),
105
- white: init(37, 39),
106
- gray: init(90, 39),
107
- bgBlack: init(40, 49),
108
- bgRed: init(41, 49),
109
- bgGreen: init(42, 49),
110
- bgYellow: init(43, 49),
111
- bgBlue: init(44, 49),
112
- bgMagenta: init(45, 49),
113
- bgCyan: init(46, 49),
114
- bgWhite: init(47, 49),
115
- blackBright: init(90, 39),
116
- redBright: init(91, 39),
117
- greenBright: init(92, 39),
118
- yellowBright: init(93, 39),
119
- blueBright: init(94, 39),
120
- magentaBright: init(95, 39),
121
- cyanBright: init(96, 39),
122
- whiteBright: init(97, 39),
123
- bgBlackBright: init(100, 49),
124
- bgRedBright: init(101, 49),
125
- bgGreenBright: init(102, 49),
126
- bgYellowBright: init(103, 49),
127
- bgBlueBright: init(104, 49),
128
- bgMagentaBright: init(105, 49),
129
- bgCyanBright: init(106, 49),
130
- bgWhiteBright: init(107, 49),
131
- // Extended 256-color palette - Popular colors
132
- orange: init256Color(208),
133
- purple: init256Color(129),
134
- pink: init256Color(207),
135
- lime: init256Color(154),
136
- teal: init256Color(37),
137
- indigo: init256Color(54),
138
- brown: init256Color(130),
139
- olive: init256Color(142),
140
- navy: init256Color(17),
141
- maroon: init256Color(52),
142
- silver: init256Color(248),
143
- gold: init256Color(220),
144
- bgOrange: init256Color(208, true),
145
- bgPurple: init256Color(129, true),
146
- bgPink: init256Color(207, true),
147
- bgLime: init256Color(154, true),
148
- bgTeal: init256Color(37, true),
149
- bgIndigo: init256Color(54, true),
150
- bgBrown: init256Color(130, true),
151
- bgOlive: init256Color(142, true),
152
- bgNavy: init256Color(17, true),
153
- bgMaroon: init256Color(52, true),
154
- bgSilver: init256Color(248, true),
155
- bgGold: init256Color(220, true)
70
+ reset: init(0, 0),
71
+ bold: init(1, 22, "\x1B[22m\x1B[1m"),
72
+ dim: init(2, 22, "\x1B[22m\x1B[2m"),
73
+ italic: init(3, 23),
74
+ underline: init(4, 24),
75
+ inverse: init(7, 27),
76
+ hidden: init(8, 28),
77
+ strikethrough: init(9, 29),
78
+ black: init(30, 39),
79
+ red: init(31, 39),
80
+ green: init(32, 39),
81
+ yellow: init(33, 39),
82
+ blue: init(34, 39),
83
+ magenta: init(35, 39),
84
+ cyan: init(36, 39),
85
+ white: init(37, 39),
86
+ gray: init(90, 39),
87
+ bgBlack: init(40, 49),
88
+ bgRed: init(41, 49),
89
+ bgGreen: init(42, 49),
90
+ bgYellow: init(43, 49),
91
+ bgBlue: init(44, 49),
92
+ bgMagenta: init(45, 49),
93
+ bgCyan: init(46, 49),
94
+ bgWhite: init(47, 49),
95
+ blackBright: init(90, 39),
96
+ redBright: init(91, 39),
97
+ greenBright: init(92, 39),
98
+ yellowBright: init(93, 39),
99
+ blueBright: init(94, 39),
100
+ magentaBright: init(95, 39),
101
+ cyanBright: init(96, 39),
102
+ whiteBright: init(97, 39),
103
+ bgBlackBright: init(100, 49),
104
+ bgRedBright: init(101, 49),
105
+ bgGreenBright: init(102, 49),
106
+ bgYellowBright: init(103, 49),
107
+ bgBlueBright: init(104, 49),
108
+ bgMagentaBright: init(105, 49),
109
+ bgCyanBright: init(106, 49),
110
+ bgWhiteBright: init(107, 49),
111
+ orange: init256Color(208),
112
+ purple: init256Color(129),
113
+ pink: init256Color(207),
114
+ lime: init256Color(154),
115
+ teal: init256Color(37),
116
+ indigo: init256Color(54),
117
+ brown: init256Color(130),
118
+ olive: init256Color(142),
119
+ navy: init256Color(17),
120
+ maroon: init256Color(52),
121
+ silver: init256Color(248),
122
+ gold: init256Color(220),
123
+ bgOrange: init256Color(208, true),
124
+ bgPurple: init256Color(129, true),
125
+ bgPink: init256Color(207, true),
126
+ bgLime: init256Color(154, true),
127
+ bgTeal: init256Color(37, true),
128
+ bgIndigo: init256Color(54, true),
129
+ bgBrown: init256Color(130, true),
130
+ bgOlive: init256Color(142, true),
131
+ bgNavy: init256Color(17, true),
132
+ bgMaroon: init256Color(52, true),
133
+ bgSilver: init256Color(248, true),
134
+ bgGold: init256Color(220, true)
156
135
  };
157
136
  const RAND_COLOR_LIST = Object.keys(colorDefs).filter((v) => {
158
- if (v.startsWith("bg")) return false;
159
- if ([
160
- "reset",
161
- "bold",
162
- "dim",
163
- "italic",
164
- "underline",
165
- "inverse",
166
- "hidden",
167
- "strikethrough",
168
- "black",
169
- "white",
170
- "gray"
171
- ].includes(v))
172
- return false;
173
- return true;
137
+ if (v.startsWith("bg")) return false;
138
+ if ([
139
+ "reset",
140
+ "bold",
141
+ "dim",
142
+ "italic",
143
+ "underline",
144
+ "inverse",
145
+ "hidden",
146
+ "strikethrough",
147
+ "black",
148
+ "white",
149
+ "gray"
150
+ ].includes(v)) return false;
151
+ return true;
174
152
  });
175
153
  function createColors(useColor = isColorSupported) {
176
- return useColor ? colorDefs : Object.fromEntries(Object.keys(colorDefs).map((key) => [key, String]));
154
+ return useColor ? colorDefs : Object.fromEntries(Object.keys(colorDefs).map((key) => [key, String]));
177
155
  }
178
156
  const colors = createColors();
179
157
  function getColor(color, fallback = "reset") {
180
- return colors[color] || colors[fallback];
158
+ return colors[color] || colors[fallback];
181
159
  }
182
-
183
- var QUOTES = { double: '"', single: "'" };
184
- var QUOTE_REGEX = { double: /(["\\])/g, single: /(['\\])/g };
185
- var ESCAPE_CHARS = { 8: "b", 9: "t", 10: "n", 12: "f", 13: "r" };
160
+ var QUOTES = {
161
+ double: "\"",
162
+ single: "'"
163
+ };
164
+ var QUOTE_REGEX = {
165
+ double: /(["\\])/g,
166
+ single: /(['\\])/g
167
+ };
168
+ var ESCAPE_CHARS = {
169
+ 8: "b",
170
+ 9: "t",
171
+ 10: "n",
172
+ 12: "f",
173
+ 13: "r"
174
+ };
186
175
  var SEP_REGEX = /\d(?=(?:\d{3})+(?!\d))/g;
187
176
  function addNumericSeparator(num, str) {
188
- if (num === Infinity || num === -Infinity || Number.isNaN(num) || typeof num === "number" && Math.abs(num) < 1e3 || str.includes("e")) {
189
- return str;
190
- }
191
- if (typeof num === "number" && !Number.isInteger(num)) {
192
- var intPart = Math.trunc(num);
193
- var intStr = String(intPart);
194
- var decPart = str.slice(intStr.length + 1);
195
- return intStr.replace(SEP_REGEX, "$&_") + "." + decPart.replace(/(\d{3})/g, "$&_").replace(/_$/, "");
196
- }
197
- return str.replace(SEP_REGEX, "$&_");
177
+ if (num === Infinity || num === -Infinity || Number.isNaN(num) || typeof num === "number" && Math.abs(num) < 1e3 || str.includes("e")) return str;
178
+ if (typeof num === "number" && !Number.isInteger(num)) {
179
+ var intStr = String(Math.trunc(num));
180
+ var decPart = str.slice(intStr.length + 1);
181
+ return intStr.replace(SEP_REGEX, "$&_") + "." + decPart.replace(/(\d{3})/g, "$&_").replace(/_$/, "");
182
+ }
183
+ return str.replace(SEP_REGEX, "$&_");
198
184
  }
199
185
  function escapeString(str, opts) {
200
- var quoteRegex = QUOTE_REGEX[opts.quoteStyle];
201
- return str.replace(quoteRegex, "\\$1").replace(/[\x00-\x1f]/g, (char) => {
202
- var code = char.charCodeAt(0);
203
- var escapeChar = ESCAPE_CHARS[code];
204
- return escapeChar ? `\\${escapeChar}` : `\\x${code.toString(16).padStart(2, "0").toUpperCase()}`;
205
- });
186
+ var quoteRegex = QUOTE_REGEX[opts.quoteStyle];
187
+ return str.replace(quoteRegex, "\\$1").replace(/[\x00-\x1f]/g, (char) => {
188
+ var code = char.charCodeAt(0);
189
+ var escapeChar = ESCAPE_CHARS[code];
190
+ return escapeChar ? `\\${escapeChar}` : `\\x${code.toString(16).padStart(2, "0").toUpperCase()}`;
191
+ });
206
192
  }
207
193
  function inspectString$1(str, opts) {
208
- if (str.length > opts.maxStringLength) {
209
- var remaining = str.length - opts.maxStringLength;
210
- var trailer = `... ${remaining} more character${remaining > 1 ? "s" : ""}`;
211
- str = str.slice(0, opts.maxStringLength);
212
- return inspectString$1(str, opts) + trailer;
213
- }
214
- var escaped = escapeString(str, opts);
215
- var quote = QUOTES[opts.quoteStyle];
216
- var result = `${quote}${escaped}${quote}`;
217
- return opts.customStringify.string?.(result) ?? result;
194
+ if (str.length > opts.maxStringLength) {
195
+ var remaining = str.length - opts.maxStringLength;
196
+ var trailer = `... ${remaining} more character${remaining > 1 ? "s" : ""}`;
197
+ str = str.slice(0, opts.maxStringLength);
198
+ return inspectString$1(str, opts) + trailer;
199
+ }
200
+ var escaped = escapeString(str, opts);
201
+ var quote = QUOTES[opts.quoteStyle];
202
+ var result = `${quote}${escaped}${quote}`;
203
+ return opts.customStringify.string?.(result) ?? result;
218
204
  }
219
205
  function inspectNumber(num, opts) {
220
- if (typeof num === "bigint") {
221
- var str = `${num}n`;
222
- var result = opts.numericSeparator ? addNumericSeparator(num, str) : str;
223
- return opts.customStringify.number?.(result) ?? result;
224
- }
225
- var str = Object.is(num, -0) ? "-0" : String(num);
226
- var result = opts.numericSeparator ? addNumericSeparator(num, str) : str;
227
- return opts.customStringify.number?.(result) ?? result;
206
+ if (typeof num === "bigint") {
207
+ var str = `${num}n`;
208
+ var result = opts.numericSeparator ? addNumericSeparator(num, str) : str;
209
+ return opts.customStringify.number?.(result) ?? result;
210
+ }
211
+ var str = Object.is(num, -0) ? "-0" : String(num);
212
+ var result = opts.numericSeparator ? addNumericSeparator(num, str) : str;
213
+ return opts.customStringify.number?.(result) ?? result;
228
214
  }
229
215
  function getIndentStrings(opts, depth) {
230
- if (depth === 0) return { base: " ".repeat(opts.indent), prev: "" };
231
- return {
232
- base: " ".repeat(opts.indent),
233
- prev: " ".repeat(opts.indent * depth)
234
- };
216
+ if (depth === 0) return {
217
+ base: " ".repeat(opts.indent),
218
+ prev: ""
219
+ };
220
+ return {
221
+ base: " ".repeat(opts.indent),
222
+ prev: " ".repeat(opts.indent * depth)
223
+ };
235
224
  }
236
225
  function isSingleLine(values) {
237
- return values.every((value) => !value.includes("\n"));
226
+ return values.every((value) => !value.includes("\n"));
238
227
  }
239
228
  function formatMultiline(values, indent) {
240
- if (values.length === 0) return "";
241
- var lineJoiner = `
242
- ${indent.prev}${indent.base}`;
243
- return `${lineJoiner}${values.join(`,${lineJoiner}`)}
244
- ${indent.prev}`;
229
+ if (values.length === 0) return "";
230
+ var lineJoiner = `\n${indent.prev}${indent.base}`;
231
+ return `${lineJoiner}${values.join(`,${lineJoiner}`)}\n${indent.prev}`;
245
232
  }
246
233
  function getObjectEntries(obj, inspectFn) {
247
- var isArray = Array.isArray(obj);
248
- var entries = [];
249
- if (isArray) {
250
- for (var i = 0; i < obj.length; i++) {
251
- entries[i] = Object.hasOwn(obj, i) ? inspectFn(obj[i], obj) : "";
252
- }
253
- }
254
- for (var key in obj) {
255
- if (!Object.hasOwn(obj, key)) continue;
256
- if (isArray && /^\d+$/.test(key) && Number(key) < obj.length) continue;
257
- var needsQuotes = /[^\w$]/.test(key);
258
- var keyStr = needsQuotes ? inspectFn(key, obj) : key;
259
- entries.push(`${keyStr}: ${inspectFn(obj[key], obj)}`);
260
- }
261
- return entries;
234
+ var isArray = Array.isArray(obj);
235
+ var entries = [];
236
+ if (isArray) for (var i = 0; i < obj.length; i++) entries[i] = Object.hasOwn(obj, i) ? inspectFn(obj[i], obj) : "";
237
+ for (var key in obj) {
238
+ if (!Object.hasOwn(obj, key)) continue;
239
+ if (isArray && /^\d+$/.test(key) && Number(key) < obj.length) continue;
240
+ var keyStr = /[^\w$]/.test(key) ? inspectFn(key, obj) : key;
241
+ entries.push(`${keyStr}: ${inspectFn(obj[key], obj)}`);
242
+ }
243
+ return entries;
262
244
  }
263
245
  function inspectValue$1(obj, opts, depth, seen) {
264
- if (obj === void 0)
265
- return opts.customStringify.undefined?.(obj) ?? "undefined";
266
- if (obj === null) return opts.customStringify.null?.(obj) ?? "null";
267
- if (typeof obj === "boolean")
268
- return opts.customStringify.boolean?.(obj) ?? String(obj);
269
- if (typeof obj === "string") return inspectString$1(obj, opts);
270
- if (typeof obj === "number") {
271
- return inspectNumber(obj, opts);
272
- } else if (typeof obj === "bigint") {
273
- return inspectNumber(obj, opts);
274
- }
275
- if (depth >= opts.depth && opts.depth > 0 && typeof obj === "object") {
276
- return Array.isArray(obj) ? "[Array]" : "[Object]";
277
- }
278
- if (seen.has(obj)) return "[Circular]";
279
- seen.add(obj);
280
- var indent = getIndentStrings(opts, depth);
281
- var inspectChild = (value) => inspectValue$1(value, opts, depth + 1, seen);
282
- if (Array.isArray(obj)) {
283
- if (obj.length === 0) return "[]";
284
- var entries = getObjectEntries(obj, inspectChild);
285
- if (indent.base && !isSingleLine(entries)) {
286
- return `[${formatMultiline(entries, indent)}]`;
287
- }
288
- return `[ ${entries.join(", ")} ]`;
289
- }
290
- if (isObject(obj)) {
291
- if (isFunction(obj[inspect.custom])) {
292
- var lineJoiner = `
293
- ${indent.prev}`;
294
- return inspect(obj, { depth: opts.depth - depth }).split("\n").join(lineJoiner);
295
- }
296
- var entries = getObjectEntries(obj, inspectChild);
297
- if (entries.length === 0) return "{}";
298
- if (indent.base) {
299
- return `{${formatMultiline(entries, indent)}}`;
300
- }
301
- return `{ ${entries.join(", ")} }`;
302
- }
303
- seen.delete(obj);
304
- return String(obj);
246
+ if (obj === void 0) return opts.customStringify.undefined?.(obj) ?? "undefined";
247
+ if (obj === null) return opts.customStringify.null?.(obj) ?? "null";
248
+ if (typeof obj === "boolean") return opts.customStringify.boolean?.(obj) ?? String(obj);
249
+ if (typeof obj === "string") return inspectString$1(obj, opts);
250
+ if (typeof obj === "number") return inspectNumber(obj, opts);
251
+ else if (typeof obj === "bigint") return inspectNumber(obj, opts);
252
+ if (depth >= opts.depth && opts.depth > 0 && typeof obj === "object") return Array.isArray(obj) ? "[Array]" : "[Object]";
253
+ if (seen.has(obj)) return "[Circular]";
254
+ seen.add(obj);
255
+ var indent = getIndentStrings(opts, depth);
256
+ var inspectChild = (value) => inspectValue$1(value, opts, depth + 1, seen);
257
+ if (Array.isArray(obj)) {
258
+ if (obj.length === 0) return "[]";
259
+ var entries = getObjectEntries(obj, inspectChild);
260
+ if (indent.base && !isSingleLine(entries)) return `[${formatMultiline(entries, indent)}]`;
261
+ return `[ ${entries.join(", ")} ]`;
262
+ }
263
+ if (isObject(obj)) {
264
+ if (isFunction(obj[inspect.custom])) {
265
+ var lineJoiner = `\n${indent.prev}`;
266
+ return inspect(obj, { depth: opts.depth - depth }).split("\n").join(lineJoiner);
267
+ }
268
+ var entries = getObjectEntries(obj, inspectChild);
269
+ if (entries.length === 0) return "{}";
270
+ if (indent.base) return `{${formatMultiline(entries, indent)}}`;
271
+ return `{ ${entries.join(", ")} }`;
272
+ }
273
+ seen.delete(obj);
274
+ return String(obj);
305
275
  }
306
276
  function inspectRegular(obj, options) {
307
- return inspectValue$1(obj, options, 0, /* @__PURE__ */ new WeakSet());
277
+ return inspectValue$1(obj, options, 0, /* @__PURE__ */ new WeakSet());
308
278
  }
309
-
310
279
  var INSPECT_MAP = {
311
- boolean: (obj, opts) => opts.customStringify.boolean?.(obj) ?? String(obj),
312
- string: inspectString,
313
- number: inspectNumber,
314
- bigint: inspectNumber,
315
- undefined: (obj, opts) => opts.customStringify.undefined?.(obj) ?? "undefined",
316
- null: () => "null",
317
- array: formatArray,
318
- object: formatObject
280
+ boolean: (obj, opts) => opts.customStringify.boolean?.(obj) ?? String(obj),
281
+ string: inspectString,
282
+ number: inspectNumber,
283
+ bigint: inspectNumber,
284
+ undefined: (obj, opts) => opts.customStringify.undefined?.(obj) ?? "undefined",
285
+ null: () => "null",
286
+ array: formatArray,
287
+ object: formatObject
319
288
  };
320
289
  function inspectCompact(obj, options) {
321
- return inspectValue(obj, options, 0, /* @__PURE__ */ new WeakSet());
290
+ return inspectValue(obj, options, 0, /* @__PURE__ */ new WeakSet());
322
291
  }
323
292
  function inspectValue(obj, opts, depth = 0, seen) {
324
- var spaces = depth > 0 ? " ".repeat(opts.indent * depth) : "";
325
- var type = typeOf(obj);
326
- var inspectFn = INSPECT_MAP[type] || String;
327
- if (obj && isFunction(obj[inspect.custom])) {
328
- var lineJoiner = `
329
- ${spaces}`;
330
- return spaces + inspect(obj, { depth: opts.depth - depth }).split("\n").join(lineJoiner);
331
- }
332
- return inspectFn(obj, opts, depth, spaces, seen);
293
+ var spaces = depth > 0 ? " ".repeat(opts.indent * depth) : "";
294
+ var inspectFn = INSPECT_MAP[typeOf(obj)] || String;
295
+ if (obj && isFunction(obj[inspect.custom])) {
296
+ var lineJoiner = `\n${spaces}`;
297
+ return spaces + inspect(obj, { depth: opts.depth - depth }).split("\n").join(lineJoiner);
298
+ }
299
+ return inspectFn(obj, opts, depth, spaces, seen);
333
300
  }
334
301
  function inspectString(str, opts) {
335
- if (str.length > opts.maxStringLength) {
336
- var remaining = str.length - opts.maxStringLength;
337
- str = str.slice(0, opts.maxStringLength);
338
- return formatString(str, remaining, opts);
339
- }
340
- return formatString(str, 0, opts);
302
+ if (str.length > opts.maxStringLength) {
303
+ var remaining = str.length - opts.maxStringLength;
304
+ str = str.slice(0, opts.maxStringLength);
305
+ return formatString(str, remaining, opts);
306
+ }
307
+ return formatString(str, 0, opts);
341
308
  }
342
309
  function formatString(str, remaining, opts) {
343
- var escaped = escapeString(str, opts);
344
- var quote = QUOTES[opts.quoteStyle];
345
- var result;
346
- var trailer = remaining > 0 ? opts.customStringify.stringRemaining(`... ${remaining} more characters`) : "";
347
- if (escaped.length > opts.columns && escaped.includes("\\n")) {
348
- escaped = escaped.replaceAll("\\n", "\n");
349
- result = "\n```\n" + (trailer ? `${escaped}
350
- ${trailer}` : escaped) + "\n```";
351
- } else {
352
- result = `${quote}${escaped}${trailer ?? ""}${quote}`;
353
- }
354
- return opts.customStringify.string?.(result) ?? result;
310
+ var escaped = escapeString(str, opts);
311
+ var quote = QUOTES[opts.quoteStyle];
312
+ var result;
313
+ var trailer = remaining > 0 ? opts.customStringify.stringRemaining(`... ${remaining} more characters`) : "";
314
+ if (escaped.length > opts.columns && escaped.includes("\\n")) {
315
+ escaped = escaped.replaceAll("\\n", "\n");
316
+ result = "\n```\n" + (trailer ? `${escaped}\n${trailer}` : escaped) + "\n```";
317
+ } else result = `${quote}${escaped}${trailer ?? ""}${quote}`;
318
+ return opts.customStringify.string?.(result) ?? result;
355
319
  }
356
320
  function formatArray(arr, opts, depth, spaces, seen) {
357
- if (opts.depth > 0 && depth >= opts.depth) {
358
- return "[Array]";
359
- }
360
- if (seen.has(arr)) {
361
- return "[Circular]";
362
- }
363
- seen.add(arr);
364
- var len = arr.length;
365
- if (isCompactFormat(arr, depth, spaces.length, opts)) {
366
- var compact = [];
367
- for (var i = 0; i < len; i++) {
368
- compact.push(inspectValue(arr[i], opts, 0, seen));
369
- }
370
- return `[${compact.join(", ")}]`;
371
- }
372
- var multiline = [];
373
- for (var i = 0; i < len; i++) {
374
- var strValue = inspectValue(arr[i], opts, depth + 1, seen);
375
- multiline.push(
376
- `${spaces}- ${strValue.trimStart ? strValue.trimStart() : strValue}`
377
- );
378
- }
379
- return multiline.join("\n");
321
+ if (opts.depth > 0 && depth >= opts.depth) return "[Array]";
322
+ if (seen.has(arr)) return "[Circular]";
323
+ seen.add(arr);
324
+ var len = arr.length;
325
+ if (isCompactFormat(arr, depth, spaces.length, opts)) {
326
+ var compact = [];
327
+ for (var i = 0; i < len; i++) compact.push(inspectValue(arr[i], opts, 0, seen));
328
+ return `[${compact.join(", ")}]`;
329
+ }
330
+ var multiline = [];
331
+ for (var i = 0; i < len; i++) {
332
+ var strValue = inspectValue(arr[i], opts, depth + 1, seen);
333
+ multiline.push(`${spaces}- ${strValue.trimStart ? strValue.trimStart() : strValue}`);
334
+ }
335
+ return multiline.join("\n");
380
336
  }
381
337
  function isCompactFormat(value, depth, spaces, opts) {
382
- var availableLength = opts.columns - spaces - depth * opts.indent;
383
- var totalLength = 0;
384
- if (availableLength <= 0) return false;
385
- for (var item of value.flat()) {
386
- totalLength += String(item).length + 2;
387
- if (totalLength > availableLength || !isPrimitive(item)) return false;
388
- }
389
- return true;
338
+ var availableLength = opts.columns - spaces - depth * opts.indent;
339
+ var totalLength = 0;
340
+ if (availableLength <= 0) return false;
341
+ for (var item of value.flat()) {
342
+ totalLength += String(item).length + 2;
343
+ if (totalLength > availableLength || !isPrimitive(item)) return false;
344
+ }
345
+ return true;
390
346
  }
391
347
  function formatObject(obj, opts, depth, spaces, seen) {
392
- if (opts.depth > 0 && depth >= opts.depth) {
393
- return "[Array]";
394
- }
395
- if (seen.has(obj)) {
396
- return "[Circular]";
397
- }
398
- seen.add(obj);
399
- var entries = Object.entries(obj);
400
- var len = entries.length;
401
- if (len === 0) return "{}";
402
- if (isCompactFormat(entries, depth, spaces.length, opts)) {
403
- var compact = [];
404
- var key, value;
405
- for (var i = 0; i < len; i++) {
406
- key = entries[i][0];
407
- value = entries[i][1];
408
- compact.push(`${key}: ${inspectValue(value, opts, 0, seen)}`);
409
- }
410
- return `{ ${compact.join(", ")} }`;
411
- }
412
- var multiline = [];
413
- var key, value, strValue, compactMode;
414
- for (var i = 0; i < len; i++) {
415
- key = entries[i][0];
416
- value = entries[i][1];
417
- strValue = inspectValue(value, opts, depth + 1, seen);
418
- compactMode = strValue[0] === "{" || strValue[0] === "[";
419
- if (compactMode) {
420
- multiline.push(`${spaces}${key}: ${strValue}`);
421
- } else if (value && typeof value === "object") {
422
- if (Array.isArray(value) && value.length > 0 && strValue[0] !== "[") {
423
- multiline.push(`${spaces}${key}:
424
- ${strValue}`);
425
- } else if (!Array.isArray(value)) {
426
- multiline.push(`${spaces}${key}:
427
- ${strValue}`);
428
- } else {
429
- multiline.push(`${spaces}${key}: ${strValue}`);
430
- }
431
- } else {
432
- multiline.push(`${spaces}${key}: ${strValue}`);
433
- }
434
- }
435
- return multiline.join("\n");
348
+ if (opts.depth > 0 && depth >= opts.depth) return "[Array]";
349
+ if (seen.has(obj)) return "[Circular]";
350
+ seen.add(obj);
351
+ var entries = Object.entries(obj);
352
+ var len = entries.length;
353
+ if (len === 0) return "{}";
354
+ if (isCompactFormat(entries, depth, spaces.length, opts)) {
355
+ var compact = [];
356
+ var key, value;
357
+ for (var i = 0; i < len; i++) {
358
+ key = entries[i][0];
359
+ value = entries[i][1];
360
+ compact.push(`${key}: ${inspectValue(value, opts, 0, seen)}`);
361
+ }
362
+ return `{ ${compact.join(", ")} }`;
363
+ }
364
+ var multiline = [];
365
+ var key, value, strValue, compactMode;
366
+ for (var i = 0; i < len; i++) {
367
+ key = entries[i][0];
368
+ value = entries[i][1];
369
+ strValue = inspectValue(value, opts, depth + 1, seen);
370
+ compactMode = strValue[0] === "{" || strValue[0] === "[";
371
+ if (compactMode) multiline.push(`${spaces}${key}: ${strValue}`);
372
+ else if (value && typeof value === "object") if (Array.isArray(value) && value.length > 0 && strValue[0] !== "[") multiline.push(`${spaces}${key}:\n${strValue}`);
373
+ else if (!Array.isArray(value)) multiline.push(`${spaces}${key}:\n${strValue}`);
374
+ else multiline.push(`${spaces}${key}: ${strValue}`);
375
+ else multiline.push(`${spaces}${key}: ${strValue}`);
376
+ }
377
+ return multiline.join("\n");
436
378
  }
437
-
438
379
  function parseOptions(value) {
439
- const defOptions = {
440
- columns: 80,
441
- indent: 2,
442
- depth: 5,
443
- messageKey: "msg",
444
- quoteStyle: "single",
445
- badgeMinLevel: 40,
446
- maxStringLength: 400,
447
- numericSeparator: false,
448
- ignore: "hostname,pid",
449
- colorize: true,
450
- inspect: "compact",
451
- types: {
452
- number: { color: "green" },
453
- boolean: { color: "redBright" },
454
- string: { color: "yellow" },
455
- object: { color: "gray" },
456
- error: { color: "gray" },
457
- errorStack: { color: "cyan" },
458
- time: { color: "gray" },
459
- name: { color: "rand" }
460
- },
461
- levels: {
462
- 10: { badge: "TRACE", color: "gray", icon: "\u2192" },
463
- 20: { badge: "DEBUG", color: "blue", icon: "\u2699" },
464
- 30: { badge: "INFO", color: "cyan", icon: "\u2139" },
465
- 40: { badge: "WARN", color: "yellow", icon: "\u26A0" },
466
- 50: { badge: "ERROR", color: "red", icon: "\u2716" },
467
- 60: { badge: "FATAL", color: "red", icon: "\u2716" }
468
- }
469
- };
470
- const opts = deepDefaults({}, value, defOptions);
471
- const sw = new StringWidth({
472
- extraWidths: new Map(
473
- Object.values(opts.levels).map((v) => [v.icon.charCodeAt(0), 1])
474
- )
475
- });
476
- const result = {
477
- ...opts,
478
- sw,
479
- colorFallback: createColorizeFn(opts.colorize, "gray"),
480
- inspectFn: opts.inspect === "regular" ? inspectRegular : opts.inspect === "compact" ? inspectCompact : isFunction(opts.inspect) ? opts.inspect : inspectRegular,
481
- inspectOptions: {
482
- depth: opts.depth,
483
- quoteStyle: opts.quoteStyle,
484
- indent: opts.indent,
485
- maxStringLength: opts.maxStringLength,
486
- numericSeparator: opts.numericSeparator,
487
- customStringify: {},
488
- columns: opts.columns
489
- },
490
- levels: Object.fromEntries(
491
- Object.entries(opts.levels).map(([key, value2]) => [
492
- key,
493
- {
494
- ...value2,
495
- color: createColorizeFn(opts.colorize, value2.color),
496
- colorBadge: createColorizeBadgeFn(opts.colorize, value2.color)
497
- }
498
- ])
499
- ),
500
- types: Object.fromEntries(
501
- Object.entries(opts.types).map(([key, value2]) => [
502
- key,
503
- {
504
- ...value2,
505
- color: createColorizeFn(opts.colorize, value2.color)
506
- }
507
- ])
508
- ),
509
- ignoreAdditional: /* @__PURE__ */ new Set([
510
- "level",
511
- "time",
512
- "pid",
513
- "hostname",
514
- opts.messageKey,
515
- opts.nestedKey ?? "",
516
- "name"
517
- ]),
518
- ignore: new Set(
519
- opts.ignore.split(",").map((v) => v.trim()).filter(Boolean)
520
- )
521
- };
522
- result.inspectOptions.customStringify = {
523
- number: result.types.number.color,
524
- boolean: result.types.boolean.color,
525
- string: result.types.string.color,
526
- stringRemaining: result.colorFallback
527
- };
528
- return result;
380
+ const opts = deepDefaults({}, value, {
381
+ columns: 80,
382
+ indent: 2,
383
+ depth: 5,
384
+ messageKey: "msg",
385
+ quoteStyle: "single",
386
+ badgeMinLevel: 40,
387
+ maxStringLength: 400,
388
+ numericSeparator: false,
389
+ ignore: "hostname,pid",
390
+ colorize: true,
391
+ inspect: "compact",
392
+ types: {
393
+ number: { color: "green" },
394
+ boolean: { color: "redBright" },
395
+ string: { color: "yellow" },
396
+ object: { color: "gray" },
397
+ error: { color: "gray" },
398
+ errorStack: { color: "cyan" },
399
+ time: { color: "gray" },
400
+ name: { color: "rand" }
401
+ },
402
+ levels: {
403
+ 10: {
404
+ badge: "TRACE",
405
+ color: "gray",
406
+ icon: ""
407
+ },
408
+ 20: {
409
+ badge: "DEBUG",
410
+ color: "blue",
411
+ icon: "⚙"
412
+ },
413
+ 30: {
414
+ badge: "INFO",
415
+ color: "cyan",
416
+ icon: "ℹ"
417
+ },
418
+ 40: {
419
+ badge: "WARN",
420
+ color: "yellow",
421
+ icon: ""
422
+ },
423
+ 50: {
424
+ badge: "ERROR",
425
+ color: "red",
426
+ icon: "✖"
427
+ },
428
+ 60: {
429
+ badge: "FATAL",
430
+ color: "red",
431
+ icon: "✖"
432
+ }
433
+ }
434
+ });
435
+ const sw = new StringWidth({ extraWidths: new Map(Object.values(opts.levels).map((v) => [v.icon.charCodeAt(0), 1])) });
436
+ const result = {
437
+ ...opts,
438
+ sw,
439
+ colorFallback: createColorizeFn(opts.colorize, "gray"),
440
+ inspectFn: opts.inspect === "regular" ? inspectRegular : opts.inspect === "compact" ? inspectCompact : isFunction(opts.inspect) ? opts.inspect : inspectRegular,
441
+ inspectOptions: {
442
+ depth: opts.depth,
443
+ quoteStyle: opts.quoteStyle,
444
+ indent: opts.indent,
445
+ maxStringLength: opts.maxStringLength,
446
+ numericSeparator: opts.numericSeparator,
447
+ customStringify: {},
448
+ columns: opts.columns
449
+ },
450
+ levels: Object.fromEntries(Object.entries(opts.levels).map(([key, value]) => [key, {
451
+ ...value,
452
+ color: createColorizeFn(opts.colorize, value.color),
453
+ colorBadge: createColorizeBadgeFn(opts.colorize, value.color)
454
+ }])),
455
+ types: Object.fromEntries(Object.entries(opts.types).map(([key, value]) => [key, {
456
+ ...value,
457
+ color: createColorizeFn(opts.colorize, value.color)
458
+ }])),
459
+ ignoreAdditional: /* @__PURE__ */ new Set([
460
+ "level",
461
+ "time",
462
+ "pid",
463
+ "hostname",
464
+ opts.messageKey,
465
+ opts.nestedKey ?? "",
466
+ "name"
467
+ ]),
468
+ ignore: new Set(opts.ignore.split(",").map((v) => v.trim()).filter(Boolean))
469
+ };
470
+ result.inspectOptions.customStringify = {
471
+ number: result.types.number.color,
472
+ boolean: result.types.boolean.color,
473
+ string: result.types.string.color,
474
+ stringRemaining: result.colorFallback
475
+ };
476
+ return result;
529
477
  }
530
478
  const randColor = withCache((str) => {
531
- var hash = crc32(str) >>> 0;
532
- var index = hash % RAND_COLOR_LIST.length;
533
- return RAND_COLOR_LIST[index];
479
+ return RAND_COLOR_LIST[(crc32(str) >>> 0) % RAND_COLOR_LIST.length];
534
480
  });
535
481
  function createColorizeFn(colorize, value) {
536
- if (!colorize) {
537
- return String;
538
- }
539
- if (value === "rand") {
540
- return (v) => getColor(randColor(v))(v);
541
- }
542
- var colors = arrayable(value);
543
- if (!colors.length) return String;
544
- return (v) => {
545
- var result = v;
546
- for (var color of colors) {
547
- result = getColor(color)(result);
548
- }
549
- return result;
550
- };
482
+ if (!colorize) return String;
483
+ if (value === "rand") return (v) => getColor(randColor(v))(v);
484
+ var colors = arrayable(value);
485
+ if (!colors.length) return String;
486
+ return (v) => {
487
+ var result = v;
488
+ for (var color of colors) result = getColor(color)(result);
489
+ return result;
490
+ };
551
491
  }
552
492
  function createColorizeBadgeFn(colorize, value) {
553
- if (!colorize) {
554
- return String;
555
- }
556
- if (value === "rand") {
557
- return (v) => getColor(randColor(v))(v);
558
- }
559
- var colors = arrayable(value).map((v) => {
560
- if (v.startsWith("bg")) {
561
- v = v.slice(2);
562
- }
563
- return `bg${capitalize(v)}`;
564
- });
565
- if (!colors.length) return String;
566
- colors.push("black");
567
- return (v) => {
568
- var result = v;
569
- for (var color of colors) {
570
- result = getColor(color)(result);
571
- }
572
- return result;
573
- };
493
+ if (!colorize) return String;
494
+ if (value === "rand") return (v) => getColor(randColor(v))(v);
495
+ var colors = arrayable(value).map((v) => {
496
+ if (v.startsWith("bg")) v = v.slice(2);
497
+ return `bg${capitalize(v)}`;
498
+ });
499
+ if (!colors.length) return String;
500
+ colors.push("black");
501
+ return (v) => {
502
+ var result = v;
503
+ for (var color of colors) result = getColor(color)(result);
504
+ return result;
505
+ };
574
506
  }
575
-
576
507
  function isSerializedError(value) {
577
- return has(value, ["type", "message", "stack"]);
508
+ return has(value, [
509
+ "type",
510
+ "message",
511
+ "stack"
512
+ ]);
578
513
  }
579
514
  function parseStack(stack, message) {
580
- const cwd = process.cwd() + path.sep;
581
- const lines = stack.split("\n").splice(message.split("\n").length).map((l) => l.trim().replace("file://", "").replace(cwd, ""));
582
- return lines;
515
+ const cwd = process.cwd() + path.sep;
516
+ return stack.split("\n").splice(message.split("\n").length).map((l) => l.trim().replace("file://", "").replace(cwd, ""));
583
517
  }
584
518
  function characterFormat(str) {
585
- return str.replace(/`([^`]+)`/gm, (_, m) => getColor("cyan")(m)).replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${getColor("underline")(m)} `);
519
+ return str.replace(/`([^`]+)`/gm, (_, m) => getColor("cyan")(m)).replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${getColor("underline")(m)} `);
586
520
  }
587
521
  function formatStack(stack, message, errorLevel, opts) {
588
- const indent = " ".repeat(opts.indent * errorLevel);
589
- const colorizeStack = opts.types.errorStack?.color || opts.colorFallback;
590
- return `
591
- ${indent}` + parseStack(stack, message).map(
592
- (line) => " " + line.replace(/\((.+)\)/, (_, m) => `(${colorizeStack(m)})`)
593
- ).join(`
594
- ${indent}`);
522
+ const indent = " ".repeat(opts.indent * errorLevel);
523
+ const colorizeStack = opts.types.errorStack?.color || opts.colorFallback;
524
+ return `\n${indent}` + parseStack(stack, message).map((line) => " " + line.replace(/\((.+)\)/, (_, m) => `(${colorizeStack(m)})`)).join(`\n${indent}`);
595
525
  }
596
526
  function formatDate(date, opts) {
597
- return opts.ignore.has("time") ? "" : date.toLocaleTimeString();
527
+ return opts.ignore.has("time") ? "" : date.toLocaleTimeString();
598
528
  }
599
529
  function formatType(logObj, badge, opts) {
600
- const levelBadge = opts.levels[logObj.level].badge || `LEVEL:${logObj.level}`;
601
- if (badge) {
602
- const colorize = opts.levels[logObj.level]?.colorBadge || opts.colorFallback;
603
- return colorize(` ${levelBadge} `);
604
- }
605
- const type = opts.levels[logObj.level].icon || levelBadge;
606
- const typeColor = opts.levels[logObj.level].color || opts.colorFallback;
607
- return type ? typeColor(type) : "";
530
+ const levelBadge = opts.levels[logObj.level].badge || `LEVEL:${logObj.level}`;
531
+ if (badge) return (opts.levels[logObj.level]?.colorBadge || opts.colorFallback)(` ${levelBadge} `);
532
+ const type = opts.levels[logObj.level].icon || levelBadge;
533
+ const typeColor = opts.levels[logObj.level].color || opts.colorFallback;
534
+ return type ? typeColor(type) : "";
608
535
  }
609
536
  function filterAndJoin(arr) {
610
- return arr.filter(Boolean).join(" ");
537
+ return arr.filter(Boolean).join(" ");
611
538
  }
612
539
  function formatError(err, errorLevel, opts) {
613
- const message = (err.type ? `${err.type}: ` : "") + (err.message ?? formatWithOptions({ depth: opts.depth, colors: opts.colorize }, err));
614
- const colorizeError = opts.types.error?.color || opts.colorFallback;
615
- const stack = err.stack ? formatStack(err.stack, message, errorLevel, opts) : "";
616
- const causedPrefix = errorLevel > 0 ? `${" ".repeat(opts.indent * errorLevel)}[cause]: ` : "";
617
- const causedError = err.cause ? "\n\n" + formatError(err.cause, errorLevel + 1, opts) : "";
618
- return colorizeError(causedPrefix + message + stack + causedError);
540
+ const message = (err.type ? `${err.type}: ` : "") + (err.message ?? formatWithOptions({
541
+ depth: opts.depth,
542
+ colors: opts.colorize
543
+ }, err));
544
+ const colorizeError = opts.types.error?.color || opts.colorFallback;
545
+ const stack = err.stack ? formatStack(err.stack, message, errorLevel, opts) : "";
546
+ const causedPrefix = errorLevel > 0 ? `${" ".repeat(opts.indent * errorLevel)}[cause]: ` : "";
547
+ const causedError = err.cause ? "\n\n" + formatError(err.cause, errorLevel + 1, opts) : "";
548
+ return colorizeError(causedPrefix + message + stack + causedError);
619
549
  }
620
550
  function formatAdditional(obj, opts) {
621
- const additional = {};
622
- let empty = true;
623
- if (isSerializedError(obj)) {
624
- return formatError(obj, 0, opts);
625
- } else {
626
- for (const key in obj) {
627
- empty = false;
628
- if (isSerializedError(obj[key])) {
629
- def(obj[key], inspect.custom, () => formatError(obj[key], 0, opts));
630
- }
631
- additional[key] = obj[key];
632
- }
633
- }
634
- if (empty) {
635
- return "";
636
- }
637
- const colorizeObject = opts.types.object?.color || opts.colorFallback;
638
- return colorizeObject(opts.inspectFn(additional, opts.inspectOptions));
551
+ const additional = {};
552
+ let empty = true;
553
+ if (isSerializedError(obj)) return formatError(obj, 0, opts);
554
+ else for (const key in obj) {
555
+ empty = false;
556
+ if (isSerializedError(obj[key])) def(obj[key], inspect.custom, () => formatError(obj[key], 0, opts));
557
+ additional[key] = obj[key];
558
+ }
559
+ if (empty) return "";
560
+ return (opts.types.object?.color || opts.colorFallback)(opts.inspectFn(additional, opts.inspectOptions));
639
561
  }
640
562
  function pretty(logObj) {
641
- const opts = this;
642
- const message = isString(logObj[opts.messageKey]) ? logObj[opts.messageKey] : "";
643
- const additional = opts.nestedKey ? formatAdditional(logObj[opts.nestedKey], opts) : formatAdditional(omit(logObj, opts.ignoreAdditional), opts);
644
- const date = formatDate(new Date(logObj.time), opts);
645
- const coloredDate = date ? opts.types.time.color(date) : "";
646
- const isBadge = logObj.level >= opts.badgeMinLevel;
647
- const type = formatType(logObj, isBadge, opts);
648
- const name = logObj.name ? opts.types.name.color(logObj.name) : "";
649
- let line;
650
- const left = filterAndJoin([type, characterFormat(message)]);
651
- const right = filterAndJoin([name, coloredDate]);
652
- const space = opts.columns - opts.sw.width(left) - opts.sw.width(right) - 2;
653
- line = space > 0 && opts.columns >= 80 ? left + " ".repeat(space) + right : (right ? `[${right}] ` : "") + left;
654
- if (additional) {
655
- line += "\n" + additional;
656
- }
657
- return isBadge ? "\n" + line + "\n" : line;
563
+ const opts = this;
564
+ const message = isString(logObj[opts.messageKey]) ? logObj[opts.messageKey] : "";
565
+ const additional = opts.nestedKey ? formatAdditional(logObj[opts.nestedKey], opts) : formatAdditional(omit(logObj, opts.ignoreAdditional), opts);
566
+ const date = formatDate(new Date(logObj.time), opts);
567
+ const coloredDate = date ? opts.types.time.color(date) : "";
568
+ const isBadge = logObj.level >= opts.badgeMinLevel;
569
+ const type = formatType(logObj, isBadge, opts);
570
+ const name = logObj.name ? opts.types.name.color(logObj.name) : "";
571
+ let line;
572
+ const left = filterAndJoin([type, characterFormat(message)]);
573
+ const right = filterAndJoin([name, coloredDate]);
574
+ const space = opts.columns - opts.sw.width(left) - opts.sw.width(right) - 2;
575
+ line = space > 0 && opts.columns >= 80 ? left + " ".repeat(space) + right : (right ? `[${right}] ` : "") + left;
576
+ if (additional) line += "\n" + additional;
577
+ return isBadge ? "\n" + line + "\n" : line;
658
578
  }
659
-
660
579
  function prettyFactory(options) {
661
- const opts = parseOptions(options);
662
- return pretty.bind(opts);
580
+ const opts = parseOptions(options);
581
+ return pretty.bind(opts);
663
582
  }
664
583
  function build(opts = {}) {
665
- var destination;
666
- return abstractTransport(
667
- function(source) {
668
- var pretty2 = prettyFactory({
669
- messageKey: source.messageKey || "msg",
670
- ...opts
671
- });
672
- var extraLine = false;
673
- var line;
674
- const stream = new Transform({
675
- objectMode: true,
676
- autoDestroy: true,
677
- transform(chunk, enc, cb) {
678
- line = pretty2(chunk);
679
- if (line.endsWith("\n")) {
680
- extraLine = true;
681
- } else if (extraLine) {
682
- line = "\n" + line + "\n";
683
- extraLine = false;
684
- } else {
685
- line = line + "\n";
686
- }
687
- cb(null, line);
688
- }
689
- });
690
- destination = buildSafeSonicBoom({
691
- dest: 1,
692
- append: true,
693
- mkdir: true,
694
- sync: false
695
- });
696
- source.on("unknown", function(line2) {
697
- destination.write(line2 + "\n");
698
- });
699
- pump(source, stream, destination);
700
- return stream;
701
- },
702
- {
703
- expectPinoConfig: true,
704
- enablePipelining: false,
705
- close(err, cb) {
706
- destination.on("close", () => {
707
- cb(err);
708
- });
709
- }
710
- }
711
- );
584
+ var destination;
585
+ return abstractTransport(function(source) {
586
+ var pretty = prettyFactory({
587
+ messageKey: source.messageKey || "msg",
588
+ ...opts
589
+ });
590
+ var extraLine = false;
591
+ var line;
592
+ const stream = new Transform({
593
+ objectMode: true,
594
+ autoDestroy: true,
595
+ transform(chunk, enc, cb) {
596
+ line = pretty(chunk);
597
+ if (line.endsWith("\n")) extraLine = true;
598
+ else if (extraLine) {
599
+ line = "\n" + line + "\n";
600
+ extraLine = false;
601
+ } else line = line + "\n";
602
+ cb(null, line);
603
+ }
604
+ });
605
+ destination = buildSafeSonicBoom({
606
+ dest: 1,
607
+ append: true,
608
+ mkdir: true,
609
+ sync: false
610
+ });
611
+ source.on("unknown", function(line) {
612
+ destination.write(line + "\n");
613
+ });
614
+ pump(source, stream, destination);
615
+ return stream;
616
+ }, {
617
+ expectPinoConfig: true,
618
+ enablePipelining: false,
619
+ close(err, cb) {
620
+ destination.on("close", () => {
621
+ cb(err);
622
+ });
623
+ }
624
+ });
712
625
  }
713
-
714
626
  export { build, build as default };
715
- //# sourceMappingURL=index.mjs.map
627
+
628
+ //# sourceMappingURL=index.mjs.map