nightingale 17.0.0 → 18.0.0

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 (53) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/definitions/debug/getDebugString.d.ts +2 -0
  3. package/dist/definitions/debug/getDebugString.d.ts.map +1 -0
  4. package/dist/definitions/debug/getDebugString.web.d.ts +2 -0
  5. package/dist/definitions/debug/getDebugString.web.d.ts.map +1 -0
  6. package/dist/definitions/formatter-utils/formatRecordToString.d.ts +1 -1
  7. package/dist/definitions/formatter-utils/formatRecordToString.d.ts.map +1 -1
  8. package/dist/definitions/formatter-utils/index.d.ts +7 -7
  9. package/dist/definitions/formatter-utils/index.d.ts.map +1 -1
  10. package/dist/definitions/formatters/ANSIFormatter.d.ts.map +1 -1
  11. package/dist/definitions/formatters/BrowserConsoleFormatter.d.ts.map +1 -1
  12. package/dist/definitions/handlers/BrowserConsoleHandler.d.ts +0 -1
  13. package/dist/definitions/handlers/BrowserConsoleHandler.d.ts.map +1 -1
  14. package/dist/definitions/index.d.ts +16 -16
  15. package/dist/definitions/index.d.ts.map +1 -1
  16. package/dist/index-browser.es.js +1 -0
  17. package/dist/index-browser.es.js.map +1 -1
  18. package/dist/{index-node20.mjs → index-node22.mjs} +3 -17
  19. package/dist/index-node22.mjs.map +1 -0
  20. package/dist/index-react-native.es.js +992 -0
  21. package/dist/index-react-native.es.js.map +1 -0
  22. package/package.json +16 -13
  23. package/src/debug/debug.test.ts +1 -1
  24. package/src/debug/getDebugString.ts +3 -0
  25. package/src/debug/getDebugString.web.ts +24 -0
  26. package/src/formatter-utils/formatObject.test.ts +1 -1
  27. package/src/formatter-utils/formatObject.ts +1 -1
  28. package/src/formatter-utils/formatRecordToString.ts +4 -4
  29. package/src/formatter-utils/index.test.ts +1 -1
  30. package/src/formatter-utils/index.ts +7 -7
  31. package/src/formatter-utils/styleToHtmlStyle.ts +1 -1
  32. package/src/formatters/ANSIFormatter.test.ts +1 -1
  33. package/src/formatters/ANSIFormatter.ts +4 -1
  34. package/src/formatters/BrowserConsoleFormatter.test.ts +2 -2
  35. package/src/formatters/BrowserConsoleFormatter.ts +2 -2
  36. package/src/formatters/HTMLFormatter.test.ts +1 -1
  37. package/src/formatters/HTMLFormatter.ts +1 -1
  38. package/src/formatters/JSONFormatter.test.ts +1 -1
  39. package/src/formatters/MarkdownFormatter.test.ts +1 -1
  40. package/src/formatters/MarkdownFormatter.ts +1 -1
  41. package/src/formatters/RawFormatter.test.ts +1 -1
  42. package/src/formatters/RawFormatter.ts +1 -1
  43. package/src/handlers/BrowserConsoleHandler.ts +4 -28
  44. package/src/handlers/ConsoleCLIHandler.ts +6 -6
  45. package/src/handlers/ConsoleHandler.ts +3 -3
  46. package/src/handlers/StringHandler.ts +1 -1
  47. package/src/handlers/defaultFormatter.target-node.ts +2 -2
  48. package/src/handlers/defaultFormatter.ts +1 -1
  49. package/src/index.test.ts +2 -2
  50. package/src/index.ts +16 -16
  51. package/src/loggers/LoggerCLI.test.ts +1 -1
  52. package/src/loggers/LoggerCLI.ts +1 -1
  53. package/dist/index-node20.mjs.map +0 -1
@@ -0,0 +1,992 @@
1
+ import { Logger, Level as Level$1 } from 'nightingale-logger';
2
+ export { Logger } from 'nightingale-logger';
3
+ import { Level } from 'nightingale-levels';
4
+ export { Level, Level as levels } from 'nightingale-levels';
5
+ import ansi from 'ansi-styles';
6
+
7
+ const globalOrWindow = typeof global !== "undefined" ? global : window;
8
+ if (process.env.NODE_ENV !== "production" && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
9
+ throw new Error("nightingale: update all to ^5.0.0");
10
+ }
11
+ if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
12
+ globalOrWindow.__NIGHTINGALE_CONFIG = [];
13
+ globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = /* @__PURE__ */ new Map();
14
+ globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
15
+ handlers: [],
16
+ processors: []
17
+ };
18
+ }
19
+ function clearCache() {
20
+ globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
21
+ }
22
+ function handleConfig(config) {
23
+ if (config.keys) {
24
+ if (config.pattern) {
25
+ throw new Error("Cannot have key and pattern for the same config");
26
+ }
27
+ if (config.key) {
28
+ throw new Error("Cannot have key and keys for the same config");
29
+ }
30
+ } else if (config.key) {
31
+ if (config.pattern) {
32
+ throw new Error("Cannot have key and pattern for the same config");
33
+ }
34
+ config.keys = [config.key];
35
+ delete config.key;
36
+ }
37
+ if (config.handler) {
38
+ if (config.handlers) {
39
+ throw new Error("Cannot have handler and handlers for the same config");
40
+ }
41
+ config.handlers = [config.handler];
42
+ delete config.handler;
43
+ }
44
+ if (config.processor) {
45
+ if (config.processors) {
46
+ throw new Error(
47
+ "Cannot have processors and processors for the same config"
48
+ );
49
+ }
50
+ config.processors = [config.processor];
51
+ delete config.processor;
52
+ }
53
+ return config;
54
+ }
55
+ function configure(config) {
56
+ if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
57
+ console.log("nightingale: warning: config overridden");
58
+ }
59
+ clearCache();
60
+ globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
61
+ }
62
+ function addConfig(config, unshift = false) {
63
+ config = handleConfig(config);
64
+ globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? "unshift" : "push"](config);
65
+ clearCache();
66
+ }
67
+ const configIsForKey = (key) => (config) => {
68
+ if (config.keys) return config.keys.includes(key);
69
+ if (config.pattern) return config.pattern.test(key);
70
+ return true;
71
+ };
72
+ globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (key) => {
73
+ const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
74
+ const existingCache = globalCache.get(key);
75
+ if (existingCache) {
76
+ return existingCache;
77
+ }
78
+ const loggerConfig = {
79
+ handlers: [],
80
+ processors: []
81
+ };
82
+ globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some((config) => {
83
+ if (config.handlers) loggerConfig.handlers.push(...config.handlers);
84
+ if (config.processors) loggerConfig.processors.push(...config.processors);
85
+ return config.stop;
86
+ });
87
+ globalCache.set(key, loggerConfig);
88
+ return loggerConfig;
89
+ };
90
+ if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
91
+ globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
92
+ const { handlers, processors } = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
93
+ return {
94
+ handlers: handlers.filter(
95
+ (handler) => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))
96
+ ),
97
+ processors
98
+ };
99
+ };
100
+ }
101
+
102
+ const levelToStyles = {
103
+ [Level.TRACE]: ["gray"],
104
+ [Level.DEBUG]: ["gray"],
105
+ // [Level.INFO]: ['gray'],
106
+ [Level.WARN]: ["yellow"],
107
+ [Level.ERROR]: ["red", "bold"],
108
+ [Level.CRITICAL]: ["red", "bold"],
109
+ [Level.FATAL]: ["bgRed", "white"],
110
+ [Level.EMERGENCY]: ["bgRed", "white"]
111
+ };
112
+
113
+ const levelToSymbol = {
114
+ [Level.TRACE]: "\u2022",
115
+ [Level.DEBUG]: "\u2022",
116
+ [Level.INFO]: "\u2192",
117
+ [Level.WARN]: "\u26A0",
118
+ [Level.ERROR]: "\u2716",
119
+ [Level.CRITICAL]: "!",
120
+ [Level.FATAL]: "\u203C",
121
+ [Level.EMERGENCY]: "\u203C"
122
+ };
123
+
124
+ const styleToHexColor = {
125
+ orange: "ff5f00"
126
+ };
127
+
128
+ const styleToHtmlStyleThemeLight = {
129
+ // text style
130
+ bold: { open: "font-weight: bold", close: "font-weight: normal" },
131
+ italic: { open: "font-style: italic", close: "font-style: normal" },
132
+ underline: {
133
+ open: "text-decoration: underline",
134
+ close: "text-decoration: none"
135
+ },
136
+ inverse: {
137
+ open: "unicode-bidi: bidi-override; direction: rtl",
138
+ close: "unicode-bidi: normal; direction: ltr"
139
+ },
140
+ strikethrough: {
141
+ open: "text-decoration: line-through",
142
+ close: "text-decoration: none"
143
+ },
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" },
162
+ orange: {
163
+ open: `color: #${styleToHexColor.orange}`,
164
+ close: "color: currentcolor"
165
+ }
166
+ };
167
+ const styleToHtmlStyleThemeDark = {
168
+ ...styleToHtmlStyleThemeLight,
169
+ black: styleToHtmlStyleThemeLight.white,
170
+ bgBlack: styleToHtmlStyleThemeLight.bgWhite,
171
+ white: styleToHtmlStyleThemeLight.black,
172
+ bgWhite: styleToHtmlStyleThemeLight.bgBlack,
173
+ gray: { open: "color: lightgray", close: "color: currentcolor" }
174
+ };
175
+
176
+ const formatStyles = {
177
+ bigint: ["yellow", "bold"],
178
+ boolean: ["green"],
179
+ date: ["magenta"],
180
+ error: ["red"],
181
+ function: ["blue"],
182
+ null: ["bold"],
183
+ number: ["yellow"],
184
+ regexp: ["magenta"],
185
+ string: ["orange"],
186
+ symbol: ["magenta"],
187
+ undefined: ["dim"]
188
+ };
189
+
190
+ const noStyleFn = (styles, value) => value;
191
+ function tryStringify(arg) {
192
+ try {
193
+ return JSON.stringify(arg).replace(/\\n/g, "\n");
194
+ } catch {
195
+ return "[Circular]";
196
+ }
197
+ }
198
+ const sameRawFormattedValue = (value) => ({
199
+ stringValue: value,
200
+ formattedValue: value
201
+ });
202
+ const numericSeparator = "_";
203
+ const formatIntegerValue = (integerAsString) => {
204
+ let result = "";
205
+ let i = integerAsString.length;
206
+ const start = integerAsString.startsWith("-") ? 1 : 0;
207
+ for (; i >= start + 4; i -= 3) {
208
+ result = `${numericSeparator}${integerAsString.slice(i - 3, i)}${result}`;
209
+ }
210
+ return i === integerAsString.length ? integerAsString : `${integerAsString.slice(0, i)}${result}`;
211
+ };
212
+ const formatDecimalIntegerValue = (integerAsString) => {
213
+ let result = "";
214
+ let i = 0;
215
+ for (; i < integerAsString.length - 3; i += 3) {
216
+ result += `${integerAsString.slice(i, i + 3)}${numericSeparator}`;
217
+ }
218
+ return i === 0 ? integerAsString : `${result}${integerAsString.slice(i)}`;
219
+ };
220
+ const formatNumberValue = (value) => {
221
+ if (Number.isNaN(value)) {
222
+ return "NaN";
223
+ }
224
+ if (value === Number.POSITIVE_INFINITY) {
225
+ return "+Infinity";
226
+ }
227
+ if (value === Number.NEGATIVE_INFINITY) {
228
+ return "-Infinity";
229
+ }
230
+ if (value === Number.EPSILON) {
231
+ return "Epsilon";
232
+ }
233
+ if (Object.is(value, -0)) {
234
+ return "-0";
235
+ }
236
+ const integer = Math.trunc(value);
237
+ const integerAsString = integer.toString();
238
+ if (integer === value) {
239
+ if (integerAsString.includes("e")) {
240
+ return integerAsString;
241
+ }
242
+ return formatIntegerValue(integerAsString);
243
+ } else {
244
+ return `${formatIntegerValue(integerAsString)}.${formatDecimalIntegerValue(String(value).slice(integerAsString.length + 1))}`;
245
+ }
246
+ };
247
+ function internalFormatValue(value, styleFn, styles, { padding, depth, maxDepth, objects }) {
248
+ const typeofValue = typeof value;
249
+ if (!styles) {
250
+ if (value === null) {
251
+ styles = ["bold"];
252
+ } else {
253
+ switch (typeofValue) {
254
+ case "bigint":
255
+ styles = formatStyles.bigint;
256
+ break;
257
+ case "boolean":
258
+ styles = formatStyles.boolean;
259
+ break;
260
+ case "undefined":
261
+ styles = formatStyles.undefined;
262
+ break;
263
+ case "number":
264
+ styles = formatStyles.number;
265
+ break;
266
+ case "string":
267
+ styles = formatStyles.string;
268
+ break;
269
+ case "symbol":
270
+ styles = formatStyles.symbol;
271
+ break;
272
+ case "object":
273
+ if (value instanceof Date) {
274
+ styles = formatStyles.date;
275
+ }
276
+ if (value instanceof RegExp) {
277
+ styles = formatStyles.regexp;
278
+ }
279
+ if (value instanceof Error) {
280
+ styles = formatStyles.error;
281
+ }
282
+ break;
283
+ case "function":
284
+ styles = formatStyles.function;
285
+ break;
286
+ }
287
+ }
288
+ }
289
+ let stringValue;
290
+ if (value === null) {
291
+ stringValue = "null";
292
+ } else if (value === void 0) {
293
+ stringValue = "undefined";
294
+ } else if (typeofValue === "number") {
295
+ stringValue = formatNumberValue(value);
296
+ } else if (typeofValue === "boolean") {
297
+ stringValue = value.toString();
298
+ } else if (value.constructor === Object) {
299
+ if (depth >= maxDepth) {
300
+ stringValue = "{Object...}";
301
+ } else {
302
+ return internalFormatObject(
303
+ value,
304
+ styleFn,
305
+ void 0,
306
+ {
307
+ padding,
308
+ depth: depth + 1,
309
+ maxDepth,
310
+ objects
311
+ }
312
+ );
313
+ }
314
+ } else if (Array.isArray(value)) {
315
+ if (depth >= maxDepth) {
316
+ stringValue = "[Array...]";
317
+ } else {
318
+ return internalFormatArray(value, styleFn, {
319
+ padding,
320
+ depth: depth + 1,
321
+ maxDepth,
322
+ objects
323
+ });
324
+ }
325
+ } else if (value instanceof Error) {
326
+ const stack = value.stack;
327
+ stringValue = stack?.startsWith(value.message) || stack?.startsWith(`${value.name}: ${value.message}`) ? stack : `${value.message}
328
+ ${stack || ""}`;
329
+ } else if (value instanceof Map) {
330
+ const name = value.constructor.name;
331
+ if (depth >= maxDepth) {
332
+ stringValue = `{${name}...}`;
333
+ } else {
334
+ return internalFormatMap(name, value, styleFn, {
335
+ padding,
336
+ depth: depth + 1,
337
+ maxDepth,
338
+ objects
339
+ });
340
+ }
341
+ } else if (typeofValue === "bigint") {
342
+ stringValue = `[BigInt: ${value.toString()}]`;
343
+ } else if (typeofValue === "symbol") {
344
+ stringValue = value.toString();
345
+ } else if (value instanceof Set) {
346
+ const name = value.constructor.name;
347
+ if (depth >= maxDepth) {
348
+ stringValue = `{${name}...}`;
349
+ } else {
350
+ return internalFormatSet(name, value, styleFn, {
351
+ padding,
352
+ depth: depth + 1,
353
+ maxDepth,
354
+ objects
355
+ });
356
+ }
357
+ } else if (value instanceof WeakMap) {
358
+ stringValue = "{WeakMap...}";
359
+ } else if (value instanceof WeakSet) {
360
+ stringValue = "{WeakSet...}";
361
+ } else if (value instanceof Date) {
362
+ stringValue = `[Date: ${value.toISOString()}]`;
363
+ } else if (value instanceof RegExp) {
364
+ stringValue = `[RegExp: ${value.toString()}]`;
365
+ } else if (typeof value === "function") {
366
+ stringValue = `[Function: ${value.name}]`;
367
+ } else {
368
+ stringValue = tryStringify(value);
369
+ }
370
+ const formattedValue = styleFn(styles, stringValue);
371
+ return {
372
+ stringValue,
373
+ formattedValue
374
+ };
375
+ }
376
+ const separator = ",";
377
+ const internalFormatKey = (key, styleFn, internalFormatParams) => {
378
+ return {
379
+ stringKey: `${key}: `,
380
+ formattedKey: `${styleFn(["dim", "bold"], `${key}:`)} `
381
+ };
382
+ };
383
+ const internalNoKey = (key, styleFn, internalFormatParams) => {
384
+ return { stringKey: "", formattedKey: "" };
385
+ };
386
+ const internalFormatMapKey = (key, styleFn, internalFormatParams) => {
387
+ const { stringValue, formattedValue } = internalFormatValue(
388
+ key,
389
+ noStyleFn,
390
+ void 0,
391
+ internalFormatParams
392
+ );
393
+ return {
394
+ stringKey: `${stringValue} => `,
395
+ formattedKey: `${styleFn(["dim", "bold"], `${formattedValue}:`)} `
396
+ };
397
+ };
398
+ const internalFormatIterator = (values, styleFn, objectStyles, { padding, depth, maxDepth, objects }, {
399
+ prefix,
400
+ suffix,
401
+ prefixSuffixSpace = " ",
402
+ formatKey
403
+ }) => {
404
+ let breakLine = false;
405
+ const formattedSeparator = () => styleFn(["gray"], separator);
406
+ const valuesMaxIndex = values.length - 1;
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
+ };
439
+ }
440
+ );
441
+ return {
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}`
450
+ };
451
+ };
452
+ function internalFormatObject(object, styleFn, objectStyles, { padding, depth, maxDepth, objects }) {
453
+ if (objects.has(object)) {
454
+ return sameRawFormattedValue("{Circular Object}");
455
+ }
456
+ const keys = Object.keys(object);
457
+ if (keys.length === 0) {
458
+ return sameRawFormattedValue("{}");
459
+ }
460
+ objects.add(object);
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
+ );
468
+ objects.delete(object);
469
+ return result;
470
+ }
471
+ function internalFormatMap(name, map, styleFn, { padding, depth, maxDepth, objects }) {
472
+ if (objects.has(map)) {
473
+ return sameRawFormattedValue(`{Circular ${name}}`);
474
+ }
475
+ const keys = [...map.keys()];
476
+ if (keys.length === 0) {
477
+ return sameRawFormattedValue(`${name} {}`);
478
+ }
479
+ objects.add(map);
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
+ );
487
+ objects.delete(map);
488
+ return result;
489
+ }
490
+ function internalFormatArray(array, styleFn, { padding, depth, maxDepth, objects }) {
491
+ if (objects.has(array)) {
492
+ return sameRawFormattedValue("{Circular Array}");
493
+ }
494
+ if (array.length === 0) {
495
+ return sameRawFormattedValue("[]");
496
+ }
497
+ objects.add(array);
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
+ );
510
+ objects.delete(array);
511
+ return result;
512
+ }
513
+ function internalFormatSet(name, set, styleFn, { padding, depth, maxDepth, objects }) {
514
+ if (objects.has(set)) {
515
+ return sameRawFormattedValue(`{Circular ${name}}`);
516
+ }
517
+ const values = [...set.values()];
518
+ if (values.length === 0) {
519
+ return sameRawFormattedValue(`${name} []`);
520
+ }
521
+ objects.add(set);
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
+ );
529
+ objects.delete(set);
530
+ return result;
531
+ }
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
+ );
544
+ if (result === "{}") {
545
+ return "";
546
+ }
547
+ return result;
548
+ }
549
+
550
+ function formatRecordToString(record, style) {
551
+ const parts = [];
552
+ if (record.displayName) {
553
+ parts.push(style(["dim"], record.displayName));
554
+ } else if (record.key) {
555
+ parts.push(style(["dim"], record.key));
556
+ }
557
+ if (record.datetime) {
558
+ parts.push(
559
+ style(["gray", "bold"], record.datetime.toTimeString().split(" ", 2)[0])
560
+ );
561
+ }
562
+ let message = record.symbol || levelToSymbol[record.level] || "";
563
+ const styles = record.styles || levelToStyles[record.level];
564
+ if (record.message) {
565
+ if (message) {
566
+ message += ` ${record.message}`;
567
+ } else {
568
+ message = record.message;
569
+ }
570
+ }
571
+ if (message) {
572
+ if (styles) {
573
+ message = style(styles, message);
574
+ }
575
+ parts.push(message);
576
+ }
577
+ const formatRecordObject = (key, object, objectStyles) => {
578
+ if (!object) {
579
+ return;
580
+ }
581
+ const stringObject = formatObject(object, style, objectStyles);
582
+ if (!stringObject) {
583
+ return;
584
+ }
585
+ parts.push(stringObject);
586
+ };
587
+ formatRecordObject("metadata", record.metadata, record.metadataStyles);
588
+ formatRecordObject("extra", record.extra, void 0);
589
+ formatRecordObject("context", record.context, void 0);
590
+ return [parts.join(" ")];
591
+ }
592
+
593
+ const specialRegexpChars = /[$()+.?[\\\]^{|}]/;
594
+ const createTestFunctionFromRegexp = (regexp) => (string) => regexp.test(string);
595
+ const createTestFunctionFromRegexpString = (value) => {
596
+ if (!value.endsWith("/")) throw new Error("Invalid RegExp DEBUG value");
597
+ return createTestFunctionFromRegexp(new RegExp(value.slice(1, -1)));
598
+ };
599
+ const createTestFunctionFromValue = (value) => {
600
+ if (value.endsWith(":*")) {
601
+ value = value.slice(0, -2);
602
+ return (string) => string.startsWith(value);
603
+ }
604
+ return (string) => string === value;
605
+ };
606
+ function createFindDebugLevel(debugValue) {
607
+ let isWildcard = false;
608
+ const debugValues = [];
609
+ const skips = [];
610
+ if (!Array.isArray(debugValue)) {
611
+ if (debugValue instanceof RegExp) {
612
+ debugValues.push(createTestFunctionFromRegexp(debugValue));
613
+ debugValue = void 0;
614
+ } else if (debugValue) {
615
+ debugValue = debugValue.trim();
616
+ if (debugValue.startsWith("/")) {
617
+ debugValues.push(createTestFunctionFromRegexpString(debugValue));
618
+ debugValue = void 0;
619
+ } else {
620
+ debugValue = debugValue.split(/[\s,]+/);
621
+ }
622
+ }
623
+ }
624
+ if (debugValue) {
625
+ debugValue.forEach((value) => {
626
+ if (specialRegexpChars.test(value)) {
627
+ throw new Error(
628
+ `Invalid debug value: "${value}" (contains special chars)`
629
+ );
630
+ }
631
+ if (!value) return;
632
+ if (value === "*") {
633
+ isWildcard = true;
634
+ return;
635
+ }
636
+ if (value.startsWith("-")) {
637
+ skips.push(createTestFunctionFromValue(value.slice(1)));
638
+ } else if (!isWildcard) {
639
+ debugValues.push(createTestFunctionFromValue(value));
640
+ }
641
+ });
642
+ }
643
+ if (isWildcard) {
644
+ if (skips.length === 0) {
645
+ return () => Level.ALL;
646
+ } else {
647
+ return (minLevel, key) => skips.some((skip) => skip(key)) ? minLevel : Level.ALL;
648
+ }
649
+ }
650
+ if (debugValues.length === 0) {
651
+ return (minLevel) => minLevel;
652
+ }
653
+ return (minLevel, key) => {
654
+ if (minLevel === Level.ALL || !key) {
655
+ return minLevel;
656
+ }
657
+ if (debugValues.some((dv) => dv(key))) {
658
+ return skips.some((skip) => skip(key)) ? minLevel : Level.ALL;
659
+ }
660
+ return minLevel;
661
+ };
662
+ }
663
+
664
+ function style$4(styles, value) {
665
+ return value;
666
+ }
667
+ const RawFormatter = {
668
+ format(record) {
669
+ return formatRecordToString(record, style$4);
670
+ }
671
+ };
672
+
673
+ function style$3(styles, string) {
674
+ if (!styles || styles.length === 0 || !string) {
675
+ return string;
676
+ }
677
+ return styles.reduce((part, styleName) => {
678
+ switch (styleName) {
679
+ case "bold":
680
+ return `*${part}*`;
681
+ case "italic":
682
+ return `_${part}_`;
683
+ case "strikethrough":
684
+ return `~${part}~`;
685
+ }
686
+ return part;
687
+ }, string);
688
+ }
689
+ const MarkdownFormatter = {
690
+ format(record) {
691
+ return formatRecordToString(record, style$3);
692
+ }
693
+ };
694
+
695
+ function map2object(map) {
696
+ const object = {};
697
+ map.forEach((value, key) => {
698
+ if (typeof key === "object") {
699
+ return;
700
+ }
701
+ object[String(key)] = value;
702
+ });
703
+ return object;
704
+ }
705
+ function stringify(value, 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
+ );
722
+ }
723
+ const JSONFormatter = {
724
+ format(record) {
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
+ ];
735
+ }
736
+ };
737
+
738
+ const ansiStyles = {
739
+ black: ansi.black,
740
+ red: ansi.red,
741
+ green: ansi.green,
742
+ yellow: ansi.yellow,
743
+ blue: ansi.blue,
744
+ magenta: ansi.magenta,
745
+ cyan: ansi.cyan,
746
+ white: ansi.white,
747
+ gray: ansi.gray,
748
+ dim: ansi.dim,
749
+ bgBlack: ansi.bgBlack,
750
+ bgRed: ansi.bgRed,
751
+ bgGreen: ansi.bgGreen,
752
+ bgYellow: ansi.bgYellow,
753
+ bgBlue: ansi.bgBlue,
754
+ bgMagenta: ansi.bgMagenta,
755
+ bgCyan: ansi.bgCyan,
756
+ bgWhite: ansi.bgWhite,
757
+ bold: ansi.bold,
758
+ underline: ansi.underline,
759
+ // http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html
760
+ orange: {
761
+ open: ansi.color.ansi256(ansi.hexToAnsi256(styleToHexColor.orange)),
762
+ close: ansi.color.close
763
+ }
764
+ };
765
+ function style$2(styles, string) {
766
+ if (!styles || styles.length === 0 || !string) {
767
+ return string;
768
+ }
769
+ return styles.reduce((styledString, styleName) => {
770
+ const codePair = ansiStyles[styleName];
771
+ if (!codePair) {
772
+ throw new Error(`Unknown style: ${styleName}`);
773
+ }
774
+ return codePair.open + styledString + codePair.close;
775
+ }, string);
776
+ }
777
+ const ANSIFormatter = {
778
+ format: (record) => formatRecordToString(record, style$2)
779
+ };
780
+
781
+ function style$1(styles, string) {
782
+ if (!styles || styles.length === 0 || !string) {
783
+ return string;
784
+ }
785
+ return `<span style="${styles.map(
786
+ (styleName) => styleToHtmlStyleThemeLight[styleName].open
787
+ ).join("; ")}">${string}</span>`;
788
+ }
789
+ const HTMLFormatter = {
790
+ format(record) {
791
+ return formatRecordToString(record, style$1);
792
+ }
793
+ };
794
+
795
+ const style = (styleToHtmlStyle, args) => (styles, string) => {
796
+ if (!styles || styles.length === 0 || !string) {
797
+ return string;
798
+ }
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
+ );
806
+ return `%c${string}%c`;
807
+ };
808
+ class BrowserConsoleFormatter {
809
+ constructor(theme = "light") {
810
+ this.styleToHtmlStyle = theme === "dark" ? styleToHtmlStyleThemeDark : styleToHtmlStyleThemeLight;
811
+ }
812
+ format(record) {
813
+ const args = [];
814
+ const string = formatRecordToString(
815
+ record,
816
+ style(this.styleToHtmlStyle, args)
817
+ )[0];
818
+ return [string, ...args];
819
+ }
820
+ }
821
+
822
+ function consoleOutput(param, record) {
823
+ console[record.level >= Level.ERROR ? "error" : "log"](...param);
824
+ }
825
+
826
+ class StringHandler {
827
+ constructor(minLevel) {
828
+ this._buffer = "";
829
+ this.minLevel = minLevel;
830
+ }
831
+ get string() {
832
+ return this._buffer;
833
+ }
834
+ handle(record) {
835
+ this._buffer += RawFormatter.format(record)[0] + "\n";
836
+ }
837
+ }
838
+
839
+ function getDebugString() {
840
+ return "";
841
+ }
842
+
843
+ const findDebugLevel$2 = (minLevel, key) => createFindDebugLevel(getDebugString())(minLevel, key);
844
+ const getDefaultTheme = () => {
845
+ try {
846
+ const configInLocalStorage = localStorage.getItem("NIGHTINGALE_THEME");
847
+ if (configInLocalStorage && configInLocalStorage === "dark") {
848
+ return configInLocalStorage;
849
+ }
850
+ } catch {
851
+ }
852
+ return "light";
853
+ };
854
+ const createHandler = (theme = getDefaultTheme()) => {
855
+ const browserConsoleFormatter = new BrowserConsoleFormatter(theme);
856
+ return (record) => {
857
+ consoleOutput(browserConsoleFormatter.format(record), record);
858
+ };
859
+ };
860
+ class BrowserConsoleHandler {
861
+ constructor(minLevel, options = {}) {
862
+ this.minLevel = 0;
863
+ this.isHandling = (level, key) => level >= findDebugLevel$2(minLevel, key);
864
+ this.handle = createHandler(options.theme);
865
+ }
866
+ }
867
+
868
+ const defaultFormatter = ANSIFormatter.format;
869
+
870
+ const createHandle$1 = (formatter = defaultFormatter, output = consoleOutput) => {
871
+ return (record) => {
872
+ output(formatter(record), record);
873
+ };
874
+ };
875
+ const findDebugLevel$1 = createFindDebugLevel(process.env.DEBUG);
876
+ class ConsoleHandler {
877
+ constructor(minLevel, options = {}) {
878
+ this.minLevel = Level.ALL;
879
+ this.minLevel = minLevel;
880
+ this.isHandling = (level, key) => level >= findDebugLevel$1(minLevel, key);
881
+ this.handle = createHandle$1(options.formatter, options.output);
882
+ }
883
+ }
884
+
885
+ function cliConsoleOutput(param, record) {
886
+ console[record.level >= Level.ERROR ? "error" : "log"](...param);
887
+ }
888
+
889
+ const createHandle = ({
890
+ json,
891
+ noColor = process.env.NO_COLOR === "1" || process.env.NO_COLOR === "true"
892
+ }) => {
893
+ const formatter = (() => {
894
+ if (json) return JSONFormatter.format;
895
+ if (noColor) return RawFormatter.format;
896
+ return ANSIFormatter.format;
897
+ })();
898
+ const output = json ? consoleOutput : cliConsoleOutput;
899
+ return (record) => {
900
+ output(formatter(record), record);
901
+ };
902
+ };
903
+ const findDebugLevel = createFindDebugLevel(process.env.DEBUG);
904
+ class ConsoleCLIHandler {
905
+ constructor(minLevel, options = {}) {
906
+ this.minLevel = Level.ALL;
907
+ this.minLevel = minLevel;
908
+ this.isHandling = (level, key) => level >= findDebugLevel(minLevel, key);
909
+ this.handle = createHandle(options);
910
+ }
911
+ }
912
+
913
+ class LoggerCLI extends Logger {
914
+ constructor(key, { displayName, processors, json = false, noColor } = {}) {
915
+ super(key, displayName);
916
+ this.processors = [];
917
+ this.handlers = [new ConsoleCLIHandler(Level$1.INFO, { json, noColor })];
918
+ this.processors = processors ?? [];
919
+ this.json = json;
920
+ }
921
+ getHandlersAndProcessors(recordLevel) {
922
+ return {
923
+ handlers: this.handlers,
924
+ processors: this.processors
925
+ };
926
+ }
927
+ logJsonOnly(messageOrError, metadata, level = Level$1.INFO) {
928
+ if (this.json) {
929
+ this.log(messageOrError, metadata, level);
930
+ }
931
+ }
932
+ debugJsonOnly(messageOrError, metadata) {
933
+ if (this.json) {
934
+ this.debug(messageOrError, metadata);
935
+ }
936
+ }
937
+ noticeJsonOnly(messageOrError, metadata) {
938
+ if (this.json) {
939
+ this.notice(messageOrError, metadata);
940
+ }
941
+ }
942
+ infoJsonOnly(messageOrError, metadata) {
943
+ if (this.json) {
944
+ this.info(messageOrError, metadata);
945
+ }
946
+ }
947
+ warnJsonOnly(messageOrError, metadata) {
948
+ if (this.json) {
949
+ this.warn(messageOrError, metadata);
950
+ }
951
+ }
952
+ group(name, fn) {
953
+ if (this.json) {
954
+ return fn();
955
+ } else {
956
+ console.group(name);
957
+ const result = fn();
958
+ if (result instanceof Promise) {
959
+ return result.finally(() => {
960
+ console.groupEnd();
961
+ });
962
+ } else {
963
+ console.groupEnd();
964
+ return result;
965
+ }
966
+ }
967
+ }
968
+ separator() {
969
+ console.log();
970
+ }
971
+ }
972
+
973
+ function listenUnhandledErrors(logger = new Logger(
974
+ "nightingale:listenUnhandledErrors",
975
+ "UnhandledErrors"
976
+ )) {
977
+ process.on("uncaughtException", (error) => {
978
+ logger.error(error, {
979
+ unhandled: true,
980
+ type: "uncaughtException"
981
+ });
982
+ });
983
+ process.on("unhandledRejection", (error) => {
984
+ logger.error(error, {
985
+ unhandled: true,
986
+ type: "unhandledRejection"
987
+ });
988
+ });
989
+ }
990
+
991
+ export { ANSIFormatter, BrowserConsoleFormatter, BrowserConsoleHandler, ConsoleCLIHandler, ConsoleHandler, HTMLFormatter, JSONFormatter, LoggerCLI, MarkdownFormatter, RawFormatter, StringHandler, addConfig, configure, consoleOutput, createFindDebugLevel, formatObject, formatRecordToString, formatStyles, levelToStyles, levelToSymbol, listenUnhandledErrors, styleToHexColor, styleToHtmlStyleThemeDark, styleToHtmlStyleThemeLight };
992
+ //# sourceMappingURL=index-react-native.es.js.map