nightingale 16.2.0 → 17.0.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -1
  3. package/dist/definitions/debug/getDebugString.d.ts +2 -0
  4. package/dist/definitions/debug/getDebugString.d.ts.map +1 -0
  5. package/dist/definitions/debug/getDebugString.web.d.ts +2 -0
  6. package/dist/definitions/debug/getDebugString.web.d.ts.map +1 -0
  7. package/dist/definitions/formatter-utils/formatRecordToString.d.ts +1 -1
  8. package/dist/definitions/formatter-utils/formatRecordToString.d.ts.map +1 -1
  9. package/dist/definitions/formatter-utils/index.d.ts +1 -4
  10. package/dist/definitions/formatter-utils/index.d.ts.map +1 -1
  11. package/dist/definitions/formatters/BrowserConsoleFormatter.d.ts +3 -3
  12. package/dist/definitions/formatters/BrowserConsoleFormatter.d.ts.map +1 -1
  13. package/dist/definitions/formatters/JSONFormatter.d.ts.map +1 -1
  14. package/dist/definitions/handlers/BrowserConsoleHandler.d.ts +0 -1
  15. package/dist/definitions/handlers/BrowserConsoleHandler.d.ts.map +1 -1
  16. package/dist/definitions/handlers/ConsoleCLIHandler.d.ts +1 -0
  17. package/dist/definitions/handlers/ConsoleCLIHandler.d.ts.map +1 -1
  18. package/dist/definitions/handlers/ConsoleHandler.d.ts +2 -1
  19. package/dist/definitions/handlers/ConsoleHandler.d.ts.map +1 -1
  20. package/dist/definitions/handlers/defaultFormatter.d.ts +2 -0
  21. package/dist/definitions/handlers/defaultFormatter.d.ts.map +1 -0
  22. package/dist/definitions/handlers/defaultFormatter.target-node.d.ts +2 -0
  23. package/dist/definitions/handlers/defaultFormatter.target-node.d.ts.map +1 -0
  24. package/dist/definitions/loggers/LoggerCLI.d.ts +6 -1
  25. package/dist/definitions/loggers/LoggerCLI.d.ts.map +1 -1
  26. package/dist/definitions/loggers/LoggerCLI.test.d.ts +2 -0
  27. package/dist/definitions/loggers/LoggerCLI.test.d.ts.map +1 -0
  28. package/dist/definitions/outputs/cliConsoleOutput.d.ts +1 -1
  29. package/dist/definitions/outputs/cliConsoleOutput.d.ts.map +1 -1
  30. package/dist/definitions/outputs/consoleOutput.d.ts +1 -1
  31. package/dist/definitions/outputs/consoleOutput.d.ts.map +1 -1
  32. package/dist/definitions/outputs/consoleOutput.target-node.d.ts +3 -0
  33. package/dist/definitions/outputs/consoleOutput.target-node.d.ts.map +1 -0
  34. package/dist/index-browser.es.js +262 -356
  35. package/dist/index-browser.es.js.map +1 -1
  36. package/dist/index-node20.mjs +256 -366
  37. package/dist/index-node20.mjs.map +1 -1
  38. package/dist/index-react-native.es.js +992 -0
  39. package/dist/index-react-native.es.js.map +1 -0
  40. package/package.json +17 -12
  41. package/src/debug/getDebugString.ts +3 -0
  42. package/src/debug/getDebugString.web.ts +24 -0
  43. package/src/formatter-utils/formatObject.test.ts +1 -3
  44. package/src/formatter-utils/formatRecordToString.ts +2 -2
  45. package/src/formatter-utils/index.ts +1 -5
  46. package/src/formatters/ANSIFormatter.test.ts +1 -1
  47. package/src/formatters/BrowserConsoleFormatter.ts +4 -6
  48. package/src/formatters/HTMLFormatter.test.ts +2 -2
  49. package/src/formatters/JSONFormatter.test.ts +5 -5
  50. package/src/formatters/JSONFormatter.ts +19 -15
  51. package/src/formatters/MarkdownFormatter.test.ts +3 -1
  52. package/src/formatters/RawFormatter.test.ts +2 -2
  53. package/src/handlers/BrowserConsoleHandler.ts +1 -25
  54. package/src/handlers/ConsoleCLIHandler.ts +11 -2
  55. package/src/handlers/ConsoleHandler.ts +3 -11
  56. package/src/handlers/StringHandler.ts +1 -1
  57. package/src/handlers/defaultFormatter.target-node.ts +7 -0
  58. package/src/handlers/defaultFormatter.ts +3 -0
  59. package/src/loggers/LoggerCLI.test.ts +19 -0
  60. package/src/loggers/LoggerCLI.ts +22 -2
  61. package/src/outputs/cliConsoleOutput.ts +2 -9
  62. package/src/outputs/consoleOutput.target-node.ts +10 -0
  63. package/src/outputs/consoleOutput.ts +2 -10
@@ -10,7 +10,7 @@ if (process.env.NODE_ENV !== "production" && globalOrWindow.__NIGHTINGALE_GLOBAL
10
10
  }
11
11
  if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
12
12
  globalOrWindow.__NIGHTINGALE_CONFIG = [];
13
- globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
13
+ globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = /* @__PURE__ */ new Map();
14
14
  globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
15
15
  handlers: [],
16
16
  processors: []
@@ -43,7 +43,9 @@ function handleConfig(config) {
43
43
  }
44
44
  if (config.processor) {
45
45
  if (config.processors) {
46
- throw new Error("Cannot have processors and processors for the same config");
46
+ throw new Error(
47
+ "Cannot have processors and processors for the same config"
48
+ );
47
49
  }
48
50
  config.processors = [config.processor];
49
51
  delete config.processor;
@@ -52,7 +54,6 @@ function handleConfig(config) {
52
54
  }
53
55
  function configure(config) {
54
56
  if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
55
- // eslint-disable-next-line no-console
56
57
  console.log("nightingale: warning: config overridden");
57
58
  }
58
59
  clearCache();
@@ -63,12 +64,12 @@ function addConfig(config, unshift = false) {
63
64
  globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? "unshift" : "push"](config);
64
65
  clearCache();
65
66
  }
66
- const configIsForKey = key => config => {
67
+ const configIsForKey = (key) => (config) => {
67
68
  if (config.keys) return config.keys.includes(key);
68
69
  if (config.pattern) return config.pattern.test(key);
69
70
  return true;
70
71
  };
71
- globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
72
+ globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (key) => {
72
73
  const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
73
74
  const existingCache = globalCache.get(key);
74
75
  if (existingCache) {
@@ -78,7 +79,7 @@ globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
78
79
  handlers: [],
79
80
  processors: []
80
81
  };
81
- globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
82
+ globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some((config) => {
82
83
  if (config.handlers) loggerConfig.handlers.push(...config.handlers);
83
84
  if (config.processors) loggerConfig.processors.push(...config.processors);
84
85
  return config.stop;
@@ -88,12 +89,11 @@ globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
88
89
  };
89
90
  if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
90
91
  globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
91
- const {
92
- handlers,
93
- processors
94
- } = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
92
+ const { handlers, processors } = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
95
93
  return {
96
- handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
94
+ handlers: handlers.filter(
95
+ (handler) => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))
96
+ ),
97
97
  processors
98
98
  };
99
99
  };
@@ -111,14 +111,14 @@ const levelToStyles = {
111
111
  };
112
112
 
113
113
  const levelToSymbol = {
114
- [Level.TRACE]: "",
115
- [Level.DEBUG]: "",
116
- [Level.INFO]: "",
117
- [Level.WARN]: "",
118
- [Level.ERROR]: "",
114
+ [Level.TRACE]: "\u2022",
115
+ [Level.DEBUG]: "\u2022",
116
+ [Level.INFO]: "\u2192",
117
+ [Level.WARN]: "\u26A0",
118
+ [Level.ERROR]: "\u2716",
119
119
  [Level.CRITICAL]: "!",
120
- [Level.FATAL]: "",
121
- [Level.EMERGENCY]: ""
120
+ [Level.FATAL]: "\u203C",
121
+ [Level.EMERGENCY]: "\u203C"
122
122
  };
123
123
 
124
124
  const styleToHexColor = {
@@ -127,14 +127,8 @@ const styleToHexColor = {
127
127
 
128
128
  const styleToHtmlStyleThemeLight = {
129
129
  // text style
130
- bold: {
131
- open: "font-weight: bold",
132
- close: "font-weight: normal"
133
- },
134
- italic: {
135
- open: "font-style: italic",
136
- close: "font-style: normal"
137
- },
130
+ bold: { open: "font-weight: bold", close: "font-weight: normal" },
131
+ italic: { open: "font-style: italic", close: "font-style: normal" },
138
132
  underline: {
139
133
  open: "text-decoration: underline",
140
134
  close: "text-decoration: none"
@@ -147,78 +141,24 @@ const styleToHtmlStyleThemeLight = {
147
141
  open: "text-decoration: line-through",
148
142
  close: "text-decoration: none"
149
143
  },
150
- black: {
151
- open: "color: black",
152
- close: "color: currentcolor"
153
- },
154
- red: {
155
- open: "color: #ff0020",
156
- close: "color: currentcolor"
157
- },
158
- green: {
159
- open: "color: #00b317",
160
- close: "color: currentcolor"
161
- },
162
- yellow: {
163
- open: "color: #ffcc00",
164
- close: "color: currentcolor"
165
- },
166
- blue: {
167
- open: "color: #00a0ff",
168
- close: "color: currentcolor"
169
- },
170
- magenta: {
171
- open: "color: #ff00a0",
172
- close: "color: currentcolor"
173
- },
174
- cyan: {
175
- open: "color: #00cfd8",
176
- close: "color: currentcolor"
177
- },
178
- white: {
179
- open: "color: white",
180
- close: "color: currentcolor"
181
- },
182
- gray: {
183
- open: "color: gray",
184
- close: "color: currentcolor"
185
- },
186
- dim: {
187
- open: "color: #808080",
188
- close: "color: currentcolor"
189
- },
190
- bgBlack: {
191
- open: "background: black",
192
- close: "background: initial"
193
- },
194
- bgRed: {
195
- open: "background: #ff0020",
196
- close: "background: initial"
197
- },
198
- bgGreen: {
199
- open: "background: #00b317",
200
- close: "background: initial"
201
- },
202
- bgYellow: {
203
- open: "background: #ffcc00",
204
- close: "background: initial"
205
- },
206
- bgBlue: {
207
- open: "background: #00a0ff",
208
- close: "background: initial"
209
- },
210
- bgMagenta: {
211
- open: "background: #ff00a0",
212
- close: "background: initial"
213
- },
214
- bgCyan: {
215
- open: "background: #00cfd8",
216
- close: "background: initial"
217
- },
218
- bgWhite: {
219
- open: "background: white",
220
- close: "background: initial"
221
- },
144
+ black: { open: "color: black", close: "color: currentcolor" },
145
+ red: { open: "color: #ff0020", close: "color: currentcolor" },
146
+ green: { open: "color: #00b317", close: "color: currentcolor" },
147
+ yellow: { open: "color: #ffcc00", close: "color: currentcolor" },
148
+ blue: { open: "color: #00a0ff", close: "color: currentcolor" },
149
+ magenta: { open: "color: #ff00a0", close: "color: currentcolor" },
150
+ cyan: { open: "color: #00cfd8", close: "color: currentcolor" },
151
+ white: { open: "color: white", close: "color: currentcolor" },
152
+ gray: { open: "color: gray", close: "color: currentcolor" },
153
+ dim: { open: "color: #808080", close: "color: currentcolor" },
154
+ bgBlack: { open: "background: black", close: "background: initial" },
155
+ bgRed: { open: "background: #ff0020", close: "background: initial" },
156
+ bgGreen: { open: "background: #00b317", close: "background: initial" },
157
+ bgYellow: { open: "background: #ffcc00", close: "background: initial" },
158
+ bgBlue: { open: "background: #00a0ff", close: "background: initial" },
159
+ bgMagenta: { open: "background: #ff00a0", close: "background: initial" },
160
+ bgCyan: { open: "background: #00cfd8", close: "background: initial" },
161
+ bgWhite: { open: "background: white", close: "background: initial" },
222
162
  orange: {
223
163
  open: `color: #${styleToHexColor.orange}`,
224
164
  close: "color: currentcolor"
@@ -230,14 +170,9 @@ const styleToHtmlStyleThemeDark = {
230
170
  bgBlack: styleToHtmlStyleThemeLight.bgWhite,
231
171
  white: styleToHtmlStyleThemeLight.black,
232
172
  bgWhite: styleToHtmlStyleThemeLight.bgBlack,
233
- gray: {
234
- open: "color: lightgray",
235
- close: "color: currentcolor"
236
- }
173
+ gray: { open: "color: lightgray", close: "color: currentcolor" }
237
174
  };
238
175
 
239
- /* eslint sort-keys: error */
240
-
241
176
  const formatStyles = {
242
177
  bigint: ["yellow", "bold"],
243
178
  boolean: ["green"],
@@ -252,8 +187,6 @@ const formatStyles = {
252
187
  undefined: ["dim"]
253
188
  };
254
189
 
255
- /* eslint-disable @typescript-eslint/no-use-before-define */
256
-
257
190
  const noStyleFn = (styles, value) => value;
258
191
  function tryStringify(arg) {
259
192
  try {
@@ -262,12 +195,12 @@ function tryStringify(arg) {
262
195
  return "[Circular]";
263
196
  }
264
197
  }
265
- const sameRawFormattedValue = value => ({
198
+ const sameRawFormattedValue = (value) => ({
266
199
  stringValue: value,
267
200
  formattedValue: value
268
201
  });
269
202
  const numericSeparator = "_";
270
- const formatIntegerValue = integerAsString => {
203
+ const formatIntegerValue = (integerAsString) => {
271
204
  let result = "";
272
205
  let i = integerAsString.length;
273
206
  const start = integerAsString.startsWith("-") ? 1 : 0;
@@ -276,7 +209,7 @@ const formatIntegerValue = integerAsString => {
276
209
  }
277
210
  return i === integerAsString.length ? integerAsString : `${integerAsString.slice(0, i)}${result}`;
278
211
  };
279
- const formatDecimalIntegerValue = integerAsString => {
212
+ const formatDecimalIntegerValue = (integerAsString) => {
280
213
  let result = "";
281
214
  let i = 0;
282
215
  for (; i < integerAsString.length - 3; i += 3) {
@@ -284,7 +217,7 @@ const formatDecimalIntegerValue = integerAsString => {
284
217
  }
285
218
  return i === 0 ? integerAsString : `${result}${integerAsString.slice(i)}`;
286
219
  };
287
- const formatNumberValue = value => {
220
+ const formatNumberValue = (value) => {
288
221
  if (Number.isNaN(value)) {
289
222
  return "NaN";
290
223
  }
@@ -311,12 +244,7 @@ const formatNumberValue = value => {
311
244
  return `${formatIntegerValue(integerAsString)}.${formatDecimalIntegerValue(String(value).slice(integerAsString.length + 1))}`;
312
245
  }
313
246
  };
314
- function internalFormatValue(value, styleFn, styles, {
315
- padding,
316
- depth,
317
- maxDepth,
318
- objects
319
- }) {
247
+ function internalFormatValue(value, styleFn, styles, { padding, depth, maxDepth, objects }) {
320
248
  const typeofValue = typeof value;
321
249
  if (!styles) {
322
250
  if (value === null) {
@@ -361,23 +289,27 @@ function internalFormatValue(value, styleFn, styles, {
361
289
  let stringValue;
362
290
  if (value === null) {
363
291
  stringValue = "null";
364
- } else if (value === undefined) {
292
+ } else if (value === void 0) {
365
293
  stringValue = "undefined";
366
294
  } else if (typeofValue === "number") {
367
295
  stringValue = formatNumberValue(value);
368
296
  } else if (typeofValue === "boolean") {
369
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
370
297
  stringValue = value.toString();
371
298
  } else if (value.constructor === Object) {
372
299
  if (depth >= maxDepth) {
373
300
  stringValue = "{Object...}";
374
301
  } else {
375
- return internalFormatObject(value, styleFn, undefined, {
376
- padding,
377
- depth: depth + 1,
378
- maxDepth,
379
- objects
380
- });
302
+ return internalFormatObject(
303
+ value,
304
+ styleFn,
305
+ void 0,
306
+ {
307
+ padding,
308
+ depth: depth + 1,
309
+ maxDepth,
310
+ objects
311
+ }
312
+ );
381
313
  }
382
314
  } else if (Array.isArray(value)) {
383
315
  if (depth >= maxDepth) {
@@ -392,7 +324,8 @@ function internalFormatValue(value, styleFn, styles, {
392
324
  }
393
325
  } else if (value instanceof Error) {
394
326
  const stack = value.stack;
395
- stringValue = stack?.startsWith(value.message) || stack?.startsWith(`${value.name}: ${value.message}`) ? stack : `${value.message}\n${stack || ""}`;
327
+ stringValue = stack?.startsWith(value.message) || stack?.startsWith(`${value.name}: ${value.message}`) ? stack : `${value.message}
328
+ ${stack || ""}`;
396
329
  } else if (value instanceof Map) {
397
330
  const name = value.constructor.name;
398
331
  if (depth >= maxDepth) {
@@ -441,34 +374,28 @@ function internalFormatValue(value, styleFn, styles, {
441
374
  };
442
375
  }
443
376
  const separator = ",";
444
- const internalFormatKey = (key, styleFn) => {
377
+ const internalFormatKey = (key, styleFn, internalFormatParams) => {
445
378
  return {
446
379
  stringKey: `${key}: `,
447
380
  formattedKey: `${styleFn(["dim", "bold"], `${key}:`)} `
448
381
  };
449
382
  };
450
- const internalNoKey = () => {
451
- return {
452
- stringKey: "",
453
- formattedKey: ""
454
- };
383
+ const internalNoKey = (key, styleFn, internalFormatParams) => {
384
+ return { stringKey: "", formattedKey: "" };
455
385
  };
456
386
  const internalFormatMapKey = (key, styleFn, internalFormatParams) => {
457
- const {
458
- stringValue,
459
- formattedValue
460
- } = internalFormatValue(key, noStyleFn, undefined, internalFormatParams);
387
+ const { stringValue, formattedValue } = internalFormatValue(
388
+ key,
389
+ noStyleFn,
390
+ void 0,
391
+ internalFormatParams
392
+ );
461
393
  return {
462
394
  stringKey: `${stringValue} => `,
463
395
  formattedKey: `${styleFn(["dim", "bold"], `${formattedValue}:`)} `
464
396
  };
465
397
  };
466
- const internalFormatIterator = (values, styleFn, objectStyles, {
467
- padding,
468
- depth,
469
- maxDepth,
470
- objects
471
- }, {
398
+ const internalFormatIterator = (values, styleFn, objectStyles, { padding, depth, maxDepth, objects }, {
472
399
  prefix,
473
400
  suffix,
474
401
  prefixSuffixSpace = " ",
@@ -477,48 +404,52 @@ const internalFormatIterator = (values, styleFn, objectStyles, {
477
404
  let breakLine = false;
478
405
  const formattedSeparator = () => styleFn(["gray"], separator);
479
406
  const valuesMaxIndex = values.length - 1;
480
- const formattedValues = values.map(({
481
- key,
482
- value
483
- }, index) => {
484
- const internalFormatParams = {
485
- padding,
486
- depth: depth + 1,
487
- maxDepth,
488
- objects
489
- };
490
-
491
- // key must be formatted before value (browser-formatter needs order)
492
- const {
493
- stringKey,
494
- formattedKey
495
- } = formatKey(key, styleFn, internalFormatParams);
496
- let {
497
- stringValue,
498
- formattedValue
499
- } = internalFormatValue(value, styleFn, key && objectStyles ? objectStyles[key] : undefined, internalFormatParams);
500
- if (stringValue && (stringValue.length > 80 || stringValue.includes("\n"))) {
501
- breakLine = true;
502
- stringValue = stringValue.replace(/\n/g, `\n${padding}`);
503
- formattedValue = formattedValue.replace(/\n/g, `\n${padding}`);
407
+ const formattedValues = values.map(
408
+ ({ key, value }, index) => {
409
+ const nextDepth = depth + 1;
410
+ const internalFormatParams = {
411
+ padding,
412
+ depth: nextDepth,
413
+ maxDepth,
414
+ objects
415
+ };
416
+ const { stringKey, formattedKey } = formatKey(
417
+ key,
418
+ styleFn,
419
+ internalFormatParams
420
+ );
421
+ let { stringValue, formattedValue } = internalFormatValue(
422
+ value,
423
+ styleFn,
424
+ key && objectStyles ? objectStyles[key] : void 0,
425
+ internalFormatParams
426
+ );
427
+ if (stringValue && (stringValue.length > 80 || stringValue.includes("\n"))) {
428
+ breakLine = true;
429
+ stringValue = stringValue.replace(/\n/g, `
430
+ ${padding}`);
431
+ formattedValue = formattedValue.replace(/\n/g, `
432
+ ${padding}`);
433
+ }
434
+ return {
435
+ stringValue: stringKey + stringValue + (index === valuesMaxIndex ? "" : separator),
436
+ formattedValue: formattedKey + formattedValue + (index === valuesMaxIndex ? "" : formattedSeparator())
437
+ // note: we need to format the separator for each values for browser-formatter
438
+ };
504
439
  }
505
- return {
506
- stringValue: stringKey + stringValue + (index === valuesMaxIndex ? "" : separator),
507
- formattedValue: formattedKey + formattedValue + (index === valuesMaxIndex ? "" : formattedSeparator())
508
- // note: we need to format the separator for each values for browser-formatter
509
- };
510
- });
440
+ );
511
441
  return {
512
- stringValue: prefix + formattedValues.map(breakLine ? v => `\n${padding}${v.stringValue}` : fv => fv.stringValue).join(breakLine ? "\n" : " ") + suffix,
513
- formattedValue: `${prefix}${breakLine ? "" : prefixSuffixSpace}${formattedValues.map(breakLine ? v => `\n${padding}${v.formattedValue}` : v => v.formattedValue).join(breakLine ? "" : " ")}${breakLine ? ",\n" : prefixSuffixSpace}${suffix}`
442
+ stringValue: prefix + formattedValues.map(
443
+ breakLine ? (v) => `
444
+ ${padding}${v.stringValue}` : (fv) => fv.stringValue
445
+ ).join(breakLine ? "\n" : " ") + suffix,
446
+ formattedValue: `${prefix}${breakLine ? "" : prefixSuffixSpace}${formattedValues.map(
447
+ breakLine ? (v) => `
448
+ ${padding}${v.formattedValue}` : (v) => v.formattedValue
449
+ ).join(breakLine ? "" : " ")}${breakLine ? ",\n" : prefixSuffixSpace}${suffix}`
514
450
  };
515
451
  };
516
- function internalFormatObject(object, styleFn, objectStyles, {
517
- padding,
518
- depth,
519
- maxDepth,
520
- objects
521
- }) {
452
+ function internalFormatObject(object, styleFn, objectStyles, { padding, depth, maxDepth, objects }) {
522
453
  if (objects.has(object)) {
523
454
  return sameRawFormattedValue("{Circular Object}");
524
455
  }
@@ -527,28 +458,17 @@ function internalFormatObject(object, styleFn, objectStyles, {
527
458
  return sameRawFormattedValue("{}");
528
459
  }
529
460
  objects.add(object);
530
- const result = internalFormatIterator(keys.map(key => ({
531
- key,
532
- value: object[key]
533
- })), styleFn, objectStyles, {
534
- padding,
535
- depth,
536
- maxDepth,
537
- objects
538
- }, {
539
- prefix: "{",
540
- suffix: "}",
541
- formatKey: internalFormatKey
542
- });
461
+ const result = internalFormatIterator(
462
+ keys.map((key) => ({ key, value: object[key] })),
463
+ styleFn,
464
+ objectStyles,
465
+ { padding, depth, maxDepth, objects },
466
+ { prefix: "{", suffix: "}", formatKey: internalFormatKey }
467
+ );
543
468
  objects.delete(object);
544
469
  return result;
545
470
  }
546
- function internalFormatMap(name, map, styleFn, {
547
- padding,
548
- depth,
549
- maxDepth,
550
- objects
551
- }) {
471
+ function internalFormatMap(name, map, styleFn, { padding, depth, maxDepth, objects }) {
552
472
  if (objects.has(map)) {
553
473
  return sameRawFormattedValue(`{Circular ${name}}`);
554
474
  }
@@ -557,28 +477,17 @@ function internalFormatMap(name, map, styleFn, {
557
477
  return sameRawFormattedValue(`${name} {}`);
558
478
  }
559
479
  objects.add(map);
560
- const result = internalFormatIterator(keys.map(key => ({
561
- key,
562
- value: map.get(key)
563
- })), styleFn, undefined, {
564
- padding,
565
- depth,
566
- maxDepth,
567
- objects
568
- }, {
569
- prefix: `${name} {`,
570
- suffix: "}",
571
- formatKey: internalFormatMapKey
572
- });
480
+ const result = internalFormatIterator(
481
+ keys.map((key) => ({ key, value: map.get(key) })),
482
+ styleFn,
483
+ void 0,
484
+ { padding, depth, maxDepth, objects },
485
+ { prefix: `${name} {`, suffix: "}", formatKey: internalFormatMapKey }
486
+ );
573
487
  objects.delete(map);
574
488
  return result;
575
489
  }
576
- function internalFormatArray(array, styleFn, {
577
- padding,
578
- depth,
579
- maxDepth,
580
- objects
581
- }) {
490
+ function internalFormatArray(array, styleFn, { padding, depth, maxDepth, objects }) {
582
491
  if (objects.has(array)) {
583
492
  return sameRawFormattedValue("{Circular Array}");
584
493
  }
@@ -586,29 +495,22 @@ function internalFormatArray(array, styleFn, {
586
495
  return sameRawFormattedValue("[]");
587
496
  }
588
497
  objects.add(array);
589
- const result = internalFormatIterator(array.map(value => ({
590
- key: undefined,
591
- value
592
- })), styleFn, undefined, {
593
- padding,
594
- depth,
595
- maxDepth,
596
- objects
597
- }, {
598
- prefix: "[",
599
- suffix: "]",
600
- prefixSuffixSpace: "",
601
- formatKey: internalNoKey
602
- });
498
+ const result = internalFormatIterator(
499
+ array.map((value) => ({ key: void 0, value })),
500
+ styleFn,
501
+ void 0,
502
+ { padding, depth, maxDepth, objects },
503
+ {
504
+ prefix: "[",
505
+ suffix: "]",
506
+ prefixSuffixSpace: "",
507
+ formatKey: internalNoKey
508
+ }
509
+ );
603
510
  objects.delete(array);
604
511
  return result;
605
512
  }
606
- function internalFormatSet(name, set, styleFn, {
607
- padding,
608
- depth,
609
- maxDepth,
610
- objects
611
- }) {
513
+ function internalFormatSet(name, set, styleFn, { padding, depth, maxDepth, objects }) {
612
514
  if (objects.has(set)) {
613
515
  return sameRawFormattedValue(`{Circular ${name}}`);
614
516
  }
@@ -617,34 +519,28 @@ function internalFormatSet(name, set, styleFn, {
617
519
  return sameRawFormattedValue(`${name} []`);
618
520
  }
619
521
  objects.add(set);
620
- const result = internalFormatIterator(values.map(value => ({
621
- key: undefined,
622
- value
623
- })), styleFn, undefined, {
624
- padding,
625
- depth,
626
- maxDepth,
627
- objects
628
- }, {
629
- prefix: `${name} [`,
630
- suffix: "]",
631
- formatKey: internalNoKey
632
- });
522
+ const result = internalFormatIterator(
523
+ values.map((value) => ({ key: void 0, value })),
524
+ styleFn,
525
+ void 0,
526
+ { padding, depth, maxDepth, objects },
527
+ { prefix: `${name} [`, suffix: "]", formatKey: internalNoKey }
528
+ );
633
529
  objects.delete(set);
634
530
  return result;
635
531
  }
636
- function formatObject(object, styleFn = noStyleFn, objectStyles, {
637
- padding = " ",
638
- maxDepth = 10
639
- } = {}) {
640
- const {
641
- formattedValue: result
642
- } = internalFormatObject(object, styleFn, objectStyles, {
643
- padding,
644
- maxDepth,
645
- depth: 0,
646
- objects: new Set()
647
- });
532
+ function formatObject(object, styleFn = noStyleFn, objectStyles, { padding = " ", maxDepth = 10 } = {}) {
533
+ const { formattedValue: result } = internalFormatObject(
534
+ object,
535
+ styleFn,
536
+ objectStyles,
537
+ {
538
+ padding,
539
+ maxDepth,
540
+ depth: 0,
541
+ objects: /* @__PURE__ */ new Set()
542
+ }
543
+ );
648
544
  if (result === "{}") {
649
545
  return "";
650
546
  }
@@ -659,8 +555,9 @@ function formatRecordToString(record, style) {
659
555
  parts.push(style(["dim"], record.key));
660
556
  }
661
557
  if (record.datetime) {
662
- parts.push(style(["gray", "bold"], record.datetime.toTimeString().split(" ", 2)[0]));
663
- /* new Date().toFormat('HH24:MI:SS') */
558
+ parts.push(
559
+ style(["gray", "bold"], record.datetime.toTimeString().split(" ", 2)[0])
560
+ );
664
561
  }
665
562
  let message = record.symbol || levelToSymbol[record.level] || "";
666
563
  const styles = record.styles || levelToStyles[record.level];
@@ -688,24 +585,23 @@ function formatRecordToString(record, style) {
688
585
  parts.push(stringObject);
689
586
  };
690
587
  formatRecordObject("metadata", record.metadata, record.metadataStyles);
691
- formatRecordObject("extra", record.extra, undefined);
692
- formatRecordObject("context", record.context, undefined);
693
- return parts.join(" ");
588
+ formatRecordObject("extra", record.extra, void 0);
589
+ formatRecordObject("context", record.context, void 0);
590
+ return [parts.join(" ")];
694
591
  }
695
592
 
696
- /* eslint-disable complexity */
697
593
  const specialRegexpChars = /[$()+.?[\\\]^{|}]/;
698
- const createTestFunctionFromRegexp = regexp => string => regexp.test(string);
699
- const createTestFunctionFromRegexpString = value => {
594
+ const createTestFunctionFromRegexp = (regexp) => (string) => regexp.test(string);
595
+ const createTestFunctionFromRegexpString = (value) => {
700
596
  if (!value.endsWith("/")) throw new Error("Invalid RegExp DEBUG value");
701
597
  return createTestFunctionFromRegexp(new RegExp(value.slice(1, -1)));
702
598
  };
703
- const createTestFunctionFromValue = value => {
599
+ const createTestFunctionFromValue = (value) => {
704
600
  if (value.endsWith(":*")) {
705
601
  value = value.slice(0, -2);
706
- return string => string.startsWith(value);
602
+ return (string) => string.startsWith(value);
707
603
  }
708
- return string => string === value;
604
+ return (string) => string === value;
709
605
  };
710
606
  function createFindDebugLevel(debugValue) {
711
607
  let isWildcard = false;
@@ -714,21 +610,23 @@ function createFindDebugLevel(debugValue) {
714
610
  if (!Array.isArray(debugValue)) {
715
611
  if (debugValue instanceof RegExp) {
716
612
  debugValues.push(createTestFunctionFromRegexp(debugValue));
717
- debugValue = undefined;
613
+ debugValue = void 0;
718
614
  } else if (debugValue) {
719
615
  debugValue = debugValue.trim();
720
616
  if (debugValue.startsWith("/")) {
721
617
  debugValues.push(createTestFunctionFromRegexpString(debugValue));
722
- debugValue = undefined;
618
+ debugValue = void 0;
723
619
  } else {
724
620
  debugValue = debugValue.split(/[\s,]+/);
725
621
  }
726
622
  }
727
623
  }
728
624
  if (debugValue) {
729
- debugValue.forEach(value => {
625
+ debugValue.forEach((value) => {
730
626
  if (specialRegexpChars.test(value)) {
731
- throw new Error(`Invalid debug value: "${value}" (contains special chars)`);
627
+ throw new Error(
628
+ `Invalid debug value: "${value}" (contains special chars)`
629
+ );
732
630
  }
733
631
  if (!value) return;
734
632
  if (value === "*") {
@@ -746,18 +644,18 @@ function createFindDebugLevel(debugValue) {
746
644
  if (skips.length === 0) {
747
645
  return () => Level.ALL;
748
646
  } else {
749
- return (minLevel, key) => skips.some(skip => skip(key)) ? minLevel : Level.ALL;
647
+ return (minLevel, key) => skips.some((skip) => skip(key)) ? minLevel : Level.ALL;
750
648
  }
751
649
  }
752
650
  if (debugValues.length === 0) {
753
- return minLevel => minLevel;
651
+ return (minLevel) => minLevel;
754
652
  }
755
653
  return (minLevel, key) => {
756
654
  if (minLevel === Level.ALL || !key) {
757
655
  return minLevel;
758
656
  }
759
- if (debugValues.some(dv => dv(key))) {
760
- return skips.some(skip => skip(key)) ? minLevel : Level.ALL;
657
+ if (debugValues.some((dv) => dv(key))) {
658
+ return skips.some((skip) => skip(key)) ? minLevel : Level.ALL;
761
659
  }
762
660
  return minLevel;
763
661
  };
@@ -776,8 +674,6 @@ function style$3(styles, string) {
776
674
  if (!styles || styles.length === 0 || !string) {
777
675
  return string;
778
676
  }
779
-
780
- // eslint-disable-next-line unicorn/no-array-reduce
781
677
  return styles.reduce((part, styleName) => {
782
678
  switch (styleName) {
783
679
  case "bold":
@@ -786,8 +682,6 @@ function style$3(styles, string) {
786
682
  return `_${part}_`;
787
683
  case "strikethrough":
788
684
  return `~${part}~`;
789
-
790
- // no default
791
685
  }
792
686
  return part;
793
687
  }, string);
@@ -802,39 +696,42 @@ function map2object(map) {
802
696
  const object = {};
803
697
  map.forEach((value, key) => {
804
698
  if (typeof key === "object") {
805
- // ignore key
806
699
  return;
807
700
  }
808
-
809
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
810
701
  object[String(key)] = value;
811
702
  });
812
703
  return object;
813
704
  }
814
705
  function stringify(value, space) {
815
- return JSON.stringify(value, (key, objectValue) => {
816
- if (objectValue instanceof Map) {
817
- return map2object(objectValue);
818
- }
819
- if (objectValue instanceof Error) {
820
- return {
821
- message: objectValue.message,
822
- stack: objectValue.stack
823
- };
824
- }
825
- return objectValue;
826
- }, space);
706
+ return JSON.stringify(
707
+ value,
708
+ (key, objectValue) => {
709
+ if (objectValue instanceof Map) {
710
+ return map2object(objectValue);
711
+ }
712
+ if (objectValue instanceof Error) {
713
+ return {
714
+ message: objectValue.message,
715
+ stack: objectValue.stack
716
+ };
717
+ }
718
+ return objectValue;
719
+ },
720
+ space
721
+ );
827
722
  }
828
723
  const JSONFormatter = {
829
724
  format(record) {
830
- return stringify({
831
- key: record.key,
832
- level: record.level,
833
- datetime: record.datetime,
834
- message: record.message,
835
- metadata: record.metadata,
836
- extra: record.extra
837
- });
725
+ return [
726
+ stringify({
727
+ key: record.key,
728
+ level: record.level,
729
+ datetime: record.datetime,
730
+ message: record.message,
731
+ metadata: record.metadata,
732
+ extra: record.extra
733
+ })
734
+ ];
838
735
  }
839
736
  };
840
737
 
@@ -869,8 +766,6 @@ function style$2(styles, string) {
869
766
  if (!styles || styles.length === 0 || !string) {
870
767
  return string;
871
768
  }
872
-
873
- // eslint-disable-next-line unicorn/no-array-reduce
874
769
  return styles.reduce((styledString, styleName) => {
875
770
  const codePair = ansiStyles[styleName];
876
771
  if (!codePair) {
@@ -880,14 +775,16 @@ function style$2(styles, string) {
880
775
  }, string);
881
776
  }
882
777
  const ANSIFormatter = {
883
- format: record => formatRecordToString(record, style$2)
778
+ format: (record) => formatRecordToString(record, style$2)
884
779
  };
885
780
 
886
781
  function style$1(styles, string) {
887
782
  if (!styles || styles.length === 0 || !string) {
888
783
  return string;
889
784
  }
890
- return `<span style="${styles.map(styleName => styleToHtmlStyleThemeLight[styleName].open).join("; ")}">${string}</span>`;
785
+ return `<span style="${styles.map(
786
+ (styleName) => styleToHtmlStyleThemeLight[styleName].open
787
+ ).join("; ")}">${string}</span>`;
891
788
  }
892
789
  const HTMLFormatter = {
893
790
  format(record) {
@@ -899,8 +796,13 @@ const style = (styleToHtmlStyle, args) => (styles, string) => {
899
796
  if (!styles || styles.length === 0 || !string) {
900
797
  return string;
901
798
  }
902
- const htmlStyles = styles.map(styleName => styleToHtmlStyle[styleName]);
903
- args.push(htmlStyles.map(s => s.open).join("; "), htmlStyles.map(s => s.close).join("; "));
799
+ const htmlStyles = styles.map(
800
+ (styleName) => styleToHtmlStyle[styleName]
801
+ );
802
+ args.push(
803
+ htmlStyles.map((s) => s.open).join("; "),
804
+ htmlStyles.map((s) => s.close).join("; ")
805
+ );
904
806
  return `%c${string}%c`;
905
807
  };
906
808
  class BrowserConsoleFormatter {
@@ -909,48 +811,50 @@ class BrowserConsoleFormatter {
909
811
  }
910
812
  format(record) {
911
813
  const args = [];
912
- const string = formatRecordToString(record, style(this.styleToHtmlStyle, args));
814
+ const string = formatRecordToString(
815
+ record,
816
+ style(this.styleToHtmlStyle, args)
817
+ )[0];
913
818
  return [string, ...args];
914
819
  }
915
820
  }
916
821
 
917
- /* eslint-disable no-console */
918
822
  function consoleOutput(param, record) {
919
823
  console[record.level >= Level.ERROR ? "error" : "log"](...param);
920
824
  }
921
825
 
922
- /* eslint-disable prefer-template */
923
-
924
826
  class StringHandler {
925
- _buffer = "";
926
827
  constructor(minLevel) {
828
+ this._buffer = "";
927
829
  this.minLevel = minLevel;
928
830
  }
929
831
  get string() {
930
832
  return this._buffer;
931
833
  }
932
834
  handle(record) {
933
- this._buffer += RawFormatter.format(record) + "\n";
835
+ this._buffer += RawFormatter.format(record)[0] + "\n";
934
836
  }
935
837
  }
936
838
 
937
839
  function getDebugString() {
938
840
  const querystring = document.location.search;
939
- const debugFromLocalStorage =
940
- // eslint-disable-next-line unicorn/prefer-global-this, @typescript-eslint/no-unnecessary-condition
941
- window.localStorage?.getItem("debug") || "";
841
+ const debugFromLocalStorage = (
842
+ // eslint-disable-next-line unicorn/prefer-global-this, @typescript-eslint/no-unnecessary-condition
843
+ window.localStorage?.getItem("debug") || ""
844
+ );
942
845
  if (!querystring) {
943
846
  return debugFromLocalStorage;
944
847
  }
945
-
946
- // https://developer.mozilla.org/en-US/docs/Web/API/URLUtils/search#Get_the_value_of_a_single_search_param
947
- const debugFromQueryString = decodeURI(querystring.replace(
948
- // eslint-disable-next-line prefer-regex-literals, regexp/no-super-linear-backtracking
949
- new RegExp("^(?:.*[&?]DEBUG(?:=([^&]*))?)?.*$", "i"), "$1"));
848
+ const debugFromQueryString = decodeURI(
849
+ querystring.replace(
850
+ // eslint-disable-next-line prefer-regex-literals, regexp/no-super-linear-backtracking
851
+ new RegExp("^(?:.*[&?]DEBUG(?:=([^&]*))?)?.*$", "i"),
852
+ "$1"
853
+ )
854
+ );
950
855
  return (debugFromLocalStorage ? `${debugFromLocalStorage},` : "") + debugFromQueryString;
951
856
  }
952
857
 
953
- // debug string can change any time (localStorage), so we need a new object each time.
954
858
  const findDebugLevel$2 = (minLevel, key) => createFindDebugLevel(getDebugString())(minLevel, key);
955
859
  const getDefaultTheme = () => {
956
860
  try {
@@ -958,57 +862,63 @@ const getDefaultTheme = () => {
958
862
  if (configInLocalStorage && configInLocalStorage === "dark") {
959
863
  return configInLocalStorage;
960
864
  }
961
- } catch {}
865
+ } catch {
866
+ }
962
867
  return "light";
963
868
  };
964
869
  const createHandler = (theme = getDefaultTheme()) => {
965
870
  const browserConsoleFormatter = new BrowserConsoleFormatter(theme);
966
- return record => {
871
+ return (record) => {
967
872
  consoleOutput(browserConsoleFormatter.format(record), record);
968
873
  };
969
874
  };
970
875
  class BrowserConsoleHandler {
971
- minLevel = 0;
972
876
  constructor(minLevel, options = {}) {
877
+ this.minLevel = 0;
973
878
  this.isHandling = (level, key) => level >= findDebugLevel$2(minLevel, key);
974
879
  this.handle = createHandler(options.theme);
975
880
  }
976
881
  }
977
882
 
978
883
  const defaultFormatter = ANSIFormatter.format;
884
+
979
885
  const createHandle$1 = (formatter = defaultFormatter, output = consoleOutput) => {
980
- return record => {
886
+ return (record) => {
981
887
  output(formatter(record), record);
982
888
  };
983
889
  };
984
890
  const findDebugLevel$1 = createFindDebugLevel(process.env.DEBUG);
985
891
  class ConsoleHandler {
986
- minLevel = (() => Level.ALL)();
987
892
  constructor(minLevel, options = {}) {
893
+ this.minLevel = Level.ALL;
988
894
  this.minLevel = minLevel;
989
895
  this.isHandling = (level, key) => level >= findDebugLevel$1(minLevel, key);
990
896
  this.handle = createHandle$1(options.formatter, options.output);
991
897
  }
992
898
  }
993
899
 
994
- /* eslint-disable no-console */
995
900
  function cliConsoleOutput(param, record) {
996
901
  console[record.level >= Level.ERROR ? "error" : "log"](...param);
997
902
  }
998
903
 
999
904
  const createHandle = ({
1000
- json
905
+ json,
906
+ noColor = process.env.NO_COLOR === "1" || process.env.NO_COLOR === "true"
1001
907
  }) => {
1002
- const formatter = json ? JSONFormatter.format : ANSIFormatter.format;
908
+ const formatter = (() => {
909
+ if (json) return JSONFormatter.format;
910
+ if (noColor) return RawFormatter.format;
911
+ return ANSIFormatter.format;
912
+ })();
1003
913
  const output = json ? consoleOutput : cliConsoleOutput;
1004
- return record => {
914
+ return (record) => {
1005
915
  output(formatter(record), record);
1006
916
  };
1007
917
  };
1008
918
  const findDebugLevel = createFindDebugLevel(process.env.DEBUG);
1009
919
  class ConsoleCLIHandler {
1010
- minLevel = (() => Level.ALL)();
1011
920
  constructor(minLevel, options = {}) {
921
+ this.minLevel = Level.ALL;
1012
922
  this.minLevel = minLevel;
1013
923
  this.isHandling = (level, key) => level >= findDebugLevel(minLevel, key);
1014
924
  this.handle = createHandle(options);
@@ -1016,20 +926,14 @@ class ConsoleCLIHandler {
1016
926
  }
1017
927
 
1018
928
  class LoggerCLI extends Logger {
1019
- processors = [];
1020
- constructor(key, {
1021
- displayName,
1022
- processors,
1023
- json = false
1024
- } = {}) {
929
+ constructor(key, { displayName, processors, json = false, noColor } = {}) {
1025
930
  super(key, displayName);
1026
- this.handlers = [new ConsoleCLIHandler(Level$1.INFO, {
1027
- json
1028
- })];
931
+ this.processors = [];
932
+ this.handlers = [new ConsoleCLIHandler(Level$1.INFO, { json, noColor })];
1029
933
  this.processors = processors ?? [];
1030
934
  this.json = json;
1031
935
  }
1032
- getHandlersAndProcessors() {
936
+ getHandlersAndProcessors(recordLevel) {
1033
937
  return {
1034
938
  handlers: this.handlers,
1035
939
  processors: this.processors
@@ -1076,20 +980,22 @@ class LoggerCLI extends Logger {
1076
980
  }
1077
981
  }
1078
982
  }
983
+ separator() {
984
+ console.log();
985
+ }
1079
986
  }
1080
987
 
1081
- /**
1082
- * listen to uncaughtException and unhandledRejection
1083
- * @param {Logger} [logger]
1084
- */
1085
- function listenUnhandledErrors(logger = new Logger("nightingale:listenUnhandledErrors", "UnhandledErrors")) {
1086
- process.on("uncaughtException", error => {
988
+ function listenUnhandledErrors(logger = new Logger(
989
+ "nightingale:listenUnhandledErrors",
990
+ "UnhandledErrors"
991
+ )) {
992
+ process.on("uncaughtException", (error) => {
1087
993
  logger.error(error, {
1088
994
  unhandled: true,
1089
995
  type: "uncaughtException"
1090
996
  });
1091
997
  });
1092
- process.on("unhandledRejection", error => {
998
+ process.on("unhandledRejection", (error) => {
1093
999
  logger.error(error, {
1094
1000
  unhandled: true,
1095
1001
  type: "unhandledRejection"