@logtape/pretty 1.0.0-dev.231 → 1.0.0-dev.232
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/README.md +167 -92
- package/deno.json +1 -1
- package/dist/formatter.cjs +76 -82
- package/dist/formatter.d.cts +23 -23
- package/dist/formatter.d.cts.map +1 -1
- package/dist/formatter.d.ts +23 -23
- package/dist/formatter.d.ts.map +1 -1
- package/dist/formatter.js +76 -82
- package/dist/formatter.js.map +1 -1
- package/dist/wcwidth.cjs +193 -2
- package/dist/wcwidth.js +193 -2
- package/dist/wcwidth.js.map +1 -1
- package/formatter.test.ts +24 -2
- package/formatter.ts +117 -128
- package/package.json +3 -3
- package/wcwidth.ts +210 -179
package/dist/formatter.d.cts
CHANGED
|
@@ -80,7 +80,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
80
80
|
*
|
|
81
81
|
* @default `"rgb(100,116,139)"` (slate gray)
|
|
82
82
|
*/
|
|
83
|
-
timestampColor?: Color;
|
|
83
|
+
readonly timestampColor?: Color;
|
|
84
84
|
/**
|
|
85
85
|
* Visual style applied to timestamp text.
|
|
86
86
|
*
|
|
@@ -99,7 +99,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
99
99
|
*
|
|
100
100
|
* @default `"dim"`
|
|
101
101
|
*/
|
|
102
|
-
timestampStyle?: Style;
|
|
102
|
+
readonly timestampStyle?: Style;
|
|
103
103
|
/**
|
|
104
104
|
* Custom colors for each log level.
|
|
105
105
|
*
|
|
@@ -119,7 +119,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
119
119
|
*
|
|
120
120
|
* @default Built-in color scheme (purple trace, blue debug, green info, amber warning, red error, dark red fatal)
|
|
121
121
|
*/
|
|
122
|
-
levelColors?: Partial<Record<LogLevel, Color>>;
|
|
122
|
+
readonly levelColors?: Partial<Record<LogLevel, Color>>;
|
|
123
123
|
/**
|
|
124
124
|
* Visual style applied to log level text.
|
|
125
125
|
*
|
|
@@ -138,7 +138,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
138
138
|
*
|
|
139
139
|
* @default `null` (no additional styling)
|
|
140
140
|
*/
|
|
141
|
-
levelStyle?: Style;
|
|
141
|
+
readonly levelStyle?: Style;
|
|
142
142
|
/**
|
|
143
143
|
* Icon configuration for each log level.
|
|
144
144
|
*
|
|
@@ -162,7 +162,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
162
162
|
*
|
|
163
163
|
* @default `true` (use default emoji icons)
|
|
164
164
|
*/
|
|
165
|
-
icons?: boolean | Partial<Record<LogLevel, string>>;
|
|
165
|
+
readonly icons?: boolean | Partial<Record<LogLevel, string>>;
|
|
166
166
|
/**
|
|
167
167
|
* Character(s) used to separate category hierarchy levels.
|
|
168
168
|
*
|
|
@@ -180,7 +180,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
180
180
|
*
|
|
181
181
|
* @default `"·"` (interpunct)
|
|
182
182
|
*/
|
|
183
|
-
categorySeparator?: string;
|
|
183
|
+
readonly categorySeparator?: string;
|
|
184
184
|
/**
|
|
185
185
|
* Default color for category display.
|
|
186
186
|
*
|
|
@@ -197,7 +197,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
197
197
|
*
|
|
198
198
|
* @default `"rgb(100,116,139)"` (slate gray)
|
|
199
199
|
*/
|
|
200
|
-
categoryColor?: Color;
|
|
200
|
+
readonly categoryColor?: Color;
|
|
201
201
|
/**
|
|
202
202
|
* Category-specific color mapping based on prefixes.
|
|
203
203
|
*
|
|
@@ -215,7 +215,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
215
215
|
* ])
|
|
216
216
|
* ```
|
|
217
217
|
*/
|
|
218
|
-
categoryColorMap?: CategoryColorMap;
|
|
218
|
+
readonly categoryColorMap?: CategoryColorMap;
|
|
219
219
|
/**
|
|
220
220
|
* Visual style applied to category text.
|
|
221
221
|
*
|
|
@@ -234,7 +234,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
234
234
|
*
|
|
235
235
|
* @default `["dim", "italic"]` (dimmed for subtle appearance)
|
|
236
236
|
*/
|
|
237
|
-
categoryStyle?: Style;
|
|
237
|
+
readonly categoryStyle?: Style;
|
|
238
238
|
/**
|
|
239
239
|
* Maximum display width for category names.
|
|
240
240
|
*
|
|
@@ -253,7 +253,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
253
253
|
*
|
|
254
254
|
* @default `20` (20 character limit)
|
|
255
255
|
*/
|
|
256
|
-
categoryWidth?: number | "auto";
|
|
256
|
+
readonly categoryWidth?: number | "auto";
|
|
257
257
|
/**
|
|
258
258
|
* Strategy for truncating long category names.
|
|
259
259
|
*
|
|
@@ -273,7 +273,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
273
273
|
*
|
|
274
274
|
* @default `"middle"` (smart context-preserving truncation)
|
|
275
275
|
*/
|
|
276
|
-
categoryTruncate?: TruncationStrategy;
|
|
276
|
+
readonly categoryTruncate?: TruncationStrategy;
|
|
277
277
|
/**
|
|
278
278
|
* Color for log message text content.
|
|
279
279
|
*
|
|
@@ -290,7 +290,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
290
290
|
*
|
|
291
291
|
* @default `"rgb(148,163,184)"` (light slate gray)
|
|
292
292
|
*/
|
|
293
|
-
messageColor?: Color;
|
|
293
|
+
readonly messageColor?: Color;
|
|
294
294
|
/**
|
|
295
295
|
* Visual style applied to log message text.
|
|
296
296
|
*
|
|
@@ -309,7 +309,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
309
309
|
*
|
|
310
310
|
* @default `"dim"` (dimmed for subtle readability)
|
|
311
311
|
*/
|
|
312
|
-
messageStyle?: Style;
|
|
312
|
+
readonly messageStyle?: Style;
|
|
313
313
|
/**
|
|
314
314
|
* Global color control for the entire formatter.
|
|
315
315
|
*
|
|
@@ -325,7 +325,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
325
325
|
*
|
|
326
326
|
* @default `true` (colors enabled)
|
|
327
327
|
*/
|
|
328
|
-
colors?: boolean;
|
|
328
|
+
readonly colors?: boolean;
|
|
329
329
|
/**
|
|
330
330
|
* Column alignment for consistent visual layout.
|
|
331
331
|
*
|
|
@@ -341,7 +341,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
341
341
|
*
|
|
342
342
|
* @default `true` (alignment enabled)
|
|
343
343
|
*/
|
|
344
|
-
align?: boolean;
|
|
344
|
+
readonly align?: boolean;
|
|
345
345
|
/**
|
|
346
346
|
* Configuration for structured value inspection and rendering.
|
|
347
347
|
*
|
|
@@ -359,22 +359,22 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
359
359
|
*
|
|
360
360
|
* @default `{}` (use built-in defaults: depth=unlimited, colors=auto, compact=true)
|
|
361
361
|
*/
|
|
362
|
-
inspectOptions?: {
|
|
362
|
+
readonly inspectOptions?: {
|
|
363
363
|
/**
|
|
364
364
|
* Maximum depth to traverse when inspecting nested objects.
|
|
365
365
|
* @default Infinity (no depth limit)
|
|
366
366
|
*/
|
|
367
|
-
depth?: number;
|
|
367
|
+
readonly depth?: number;
|
|
368
368
|
/**
|
|
369
369
|
* Whether to use syntax highlighting colors for inspected values.
|
|
370
370
|
* @default Inherited from global `colors` setting
|
|
371
371
|
*/
|
|
372
|
-
colors?: boolean;
|
|
372
|
+
readonly colors?: boolean;
|
|
373
373
|
/**
|
|
374
374
|
* Whether to use compact formatting for objects and arrays.
|
|
375
375
|
* @default `true` (compact formatting)
|
|
376
376
|
*/
|
|
377
|
-
compact?: boolean;
|
|
377
|
+
readonly compact?: boolean;
|
|
378
378
|
};
|
|
379
379
|
/**
|
|
380
380
|
* Enable word wrapping for long messages.
|
|
@@ -399,10 +399,10 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
399
399
|
* wordWrap: false
|
|
400
400
|
* ```
|
|
401
401
|
*
|
|
402
|
-
* @default `
|
|
402
|
+
* @default `true` (auto-detect terminal width)
|
|
403
403
|
* @since 1.0.0
|
|
404
404
|
*/
|
|
405
|
-
wordWrap?: boolean | number;
|
|
405
|
+
readonly wordWrap?: boolean | number;
|
|
406
406
|
}
|
|
407
407
|
/**
|
|
408
408
|
* Creates a beautiful console formatter optimized for local development.
|
|
@@ -426,7 +426,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
426
426
|
* @example
|
|
427
427
|
* ```typescript
|
|
428
428
|
* import { configure } from "@logtape/logtape";
|
|
429
|
-
* import { getConsoleSink } from "@logtape/logtape";
|
|
429
|
+
* import { getConsoleSink } from "@logtape/logtape/sink";
|
|
430
430
|
* import { getPrettyFormatter } from "@logtape/pretty";
|
|
431
431
|
*
|
|
432
432
|
* await configure({
|
|
@@ -468,7 +468,7 @@ declare function getPrettyFormatter(options?: PrettyFormatterOptions): TextForma
|
|
|
468
468
|
* @example
|
|
469
469
|
* ```typescript
|
|
470
470
|
* import { configure } from "@logtape/logtape";
|
|
471
|
-
* import { getConsoleSink } from "@logtape/logtape";
|
|
471
|
+
* import { getConsoleSink } from "@logtape/logtape/sink";
|
|
472
472
|
* import { prettyFormatter } from "@logtape/pretty";
|
|
473
473
|
*
|
|
474
474
|
* await configure({
|
package/dist/formatter.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.cts","names":[],"sources":["../formatter.ts"],"sourcesContent":[],"mappings":";;;;;;;AAQ0E;AAiChE,cAPJ,MAqBI,EAAA;EAKE,SAAK,KAAA,EAAA,WACA;EAsBL,SAAA,IAAA,EAAA,WAAgB;EAAA,SAAA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,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAqCjB;;;;;;;;;;;;;;;;;;8BAmBG;;;;;;;;;;;;;;;;;;;2BAoBH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BAyCG;;;;;;;;;;;;;;;;;0BAkBJ;;;;;;;;;;;;;;;;;;;0BAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiJV,kBAAA,WACL,yBACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6VU,iBAAiB"}
|
package/dist/formatter.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
80
80
|
*
|
|
81
81
|
* @default `"rgb(100,116,139)"` (slate gray)
|
|
82
82
|
*/
|
|
83
|
-
timestampColor?: Color;
|
|
83
|
+
readonly timestampColor?: Color;
|
|
84
84
|
/**
|
|
85
85
|
* Visual style applied to timestamp text.
|
|
86
86
|
*
|
|
@@ -99,7 +99,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
99
99
|
*
|
|
100
100
|
* @default `"dim"`
|
|
101
101
|
*/
|
|
102
|
-
timestampStyle?: Style;
|
|
102
|
+
readonly timestampStyle?: Style;
|
|
103
103
|
/**
|
|
104
104
|
* Custom colors for each log level.
|
|
105
105
|
*
|
|
@@ -119,7 +119,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
119
119
|
*
|
|
120
120
|
* @default Built-in color scheme (purple trace, blue debug, green info, amber warning, red error, dark red fatal)
|
|
121
121
|
*/
|
|
122
|
-
levelColors?: Partial<Record<LogLevel, Color>>;
|
|
122
|
+
readonly levelColors?: Partial<Record<LogLevel, Color>>;
|
|
123
123
|
/**
|
|
124
124
|
* Visual style applied to log level text.
|
|
125
125
|
*
|
|
@@ -138,7 +138,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
138
138
|
*
|
|
139
139
|
* @default `null` (no additional styling)
|
|
140
140
|
*/
|
|
141
|
-
levelStyle?: Style;
|
|
141
|
+
readonly levelStyle?: Style;
|
|
142
142
|
/**
|
|
143
143
|
* Icon configuration for each log level.
|
|
144
144
|
*
|
|
@@ -162,7 +162,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
162
162
|
*
|
|
163
163
|
* @default `true` (use default emoji icons)
|
|
164
164
|
*/
|
|
165
|
-
icons?: boolean | Partial<Record<LogLevel, string>>;
|
|
165
|
+
readonly icons?: boolean | Partial<Record<LogLevel, string>>;
|
|
166
166
|
/**
|
|
167
167
|
* Character(s) used to separate category hierarchy levels.
|
|
168
168
|
*
|
|
@@ -180,7 +180,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
180
180
|
*
|
|
181
181
|
* @default `"·"` (interpunct)
|
|
182
182
|
*/
|
|
183
|
-
categorySeparator?: string;
|
|
183
|
+
readonly categorySeparator?: string;
|
|
184
184
|
/**
|
|
185
185
|
* Default color for category display.
|
|
186
186
|
*
|
|
@@ -197,7 +197,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
197
197
|
*
|
|
198
198
|
* @default `"rgb(100,116,139)"` (slate gray)
|
|
199
199
|
*/
|
|
200
|
-
categoryColor?: Color;
|
|
200
|
+
readonly categoryColor?: Color;
|
|
201
201
|
/**
|
|
202
202
|
* Category-specific color mapping based on prefixes.
|
|
203
203
|
*
|
|
@@ -215,7 +215,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
215
215
|
* ])
|
|
216
216
|
* ```
|
|
217
217
|
*/
|
|
218
|
-
categoryColorMap?: CategoryColorMap;
|
|
218
|
+
readonly categoryColorMap?: CategoryColorMap;
|
|
219
219
|
/**
|
|
220
220
|
* Visual style applied to category text.
|
|
221
221
|
*
|
|
@@ -234,7 +234,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
234
234
|
*
|
|
235
235
|
* @default `["dim", "italic"]` (dimmed for subtle appearance)
|
|
236
236
|
*/
|
|
237
|
-
categoryStyle?: Style;
|
|
237
|
+
readonly categoryStyle?: Style;
|
|
238
238
|
/**
|
|
239
239
|
* Maximum display width for category names.
|
|
240
240
|
*
|
|
@@ -253,7 +253,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
253
253
|
*
|
|
254
254
|
* @default `20` (20 character limit)
|
|
255
255
|
*/
|
|
256
|
-
categoryWidth?: number | "auto";
|
|
256
|
+
readonly categoryWidth?: number | "auto";
|
|
257
257
|
/**
|
|
258
258
|
* Strategy for truncating long category names.
|
|
259
259
|
*
|
|
@@ -273,7 +273,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
273
273
|
*
|
|
274
274
|
* @default `"middle"` (smart context-preserving truncation)
|
|
275
275
|
*/
|
|
276
|
-
categoryTruncate?: TruncationStrategy;
|
|
276
|
+
readonly categoryTruncate?: TruncationStrategy;
|
|
277
277
|
/**
|
|
278
278
|
* Color for log message text content.
|
|
279
279
|
*
|
|
@@ -290,7 +290,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
290
290
|
*
|
|
291
291
|
* @default `"rgb(148,163,184)"` (light slate gray)
|
|
292
292
|
*/
|
|
293
|
-
messageColor?: Color;
|
|
293
|
+
readonly messageColor?: Color;
|
|
294
294
|
/**
|
|
295
295
|
* Visual style applied to log message text.
|
|
296
296
|
*
|
|
@@ -309,7 +309,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
309
309
|
*
|
|
310
310
|
* @default `"dim"` (dimmed for subtle readability)
|
|
311
311
|
*/
|
|
312
|
-
messageStyle?: Style;
|
|
312
|
+
readonly messageStyle?: Style;
|
|
313
313
|
/**
|
|
314
314
|
* Global color control for the entire formatter.
|
|
315
315
|
*
|
|
@@ -325,7 +325,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
325
325
|
*
|
|
326
326
|
* @default `true` (colors enabled)
|
|
327
327
|
*/
|
|
328
|
-
colors?: boolean;
|
|
328
|
+
readonly colors?: boolean;
|
|
329
329
|
/**
|
|
330
330
|
* Column alignment for consistent visual layout.
|
|
331
331
|
*
|
|
@@ -341,7 +341,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
341
341
|
*
|
|
342
342
|
* @default `true` (alignment enabled)
|
|
343
343
|
*/
|
|
344
|
-
align?: boolean;
|
|
344
|
+
readonly align?: boolean;
|
|
345
345
|
/**
|
|
346
346
|
* Configuration for structured value inspection and rendering.
|
|
347
347
|
*
|
|
@@ -359,22 +359,22 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
359
359
|
*
|
|
360
360
|
* @default `{}` (use built-in defaults: depth=unlimited, colors=auto, compact=true)
|
|
361
361
|
*/
|
|
362
|
-
inspectOptions?: {
|
|
362
|
+
readonly inspectOptions?: {
|
|
363
363
|
/**
|
|
364
364
|
* Maximum depth to traverse when inspecting nested objects.
|
|
365
365
|
* @default Infinity (no depth limit)
|
|
366
366
|
*/
|
|
367
|
-
depth?: number;
|
|
367
|
+
readonly depth?: number;
|
|
368
368
|
/**
|
|
369
369
|
* Whether to use syntax highlighting colors for inspected values.
|
|
370
370
|
* @default Inherited from global `colors` setting
|
|
371
371
|
*/
|
|
372
|
-
colors?: boolean;
|
|
372
|
+
readonly colors?: boolean;
|
|
373
373
|
/**
|
|
374
374
|
* Whether to use compact formatting for objects and arrays.
|
|
375
375
|
* @default `true` (compact formatting)
|
|
376
376
|
*/
|
|
377
|
-
compact?: boolean;
|
|
377
|
+
readonly compact?: boolean;
|
|
378
378
|
};
|
|
379
379
|
/**
|
|
380
380
|
* Enable word wrapping for long messages.
|
|
@@ -399,10 +399,10 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
399
399
|
* wordWrap: false
|
|
400
400
|
* ```
|
|
401
401
|
*
|
|
402
|
-
* @default `
|
|
402
|
+
* @default `true` (auto-detect terminal width)
|
|
403
403
|
* @since 1.0.0
|
|
404
404
|
*/
|
|
405
|
-
wordWrap?: boolean | number;
|
|
405
|
+
readonly wordWrap?: boolean | number;
|
|
406
406
|
}
|
|
407
407
|
/**
|
|
408
408
|
* Creates a beautiful console formatter optimized for local development.
|
|
@@ -426,7 +426,7 @@ interface PrettyFormatterOptions extends Omit<TextFormatterOptions, "category" |
|
|
|
426
426
|
* @example
|
|
427
427
|
* ```typescript
|
|
428
428
|
* import { configure } from "@logtape/logtape";
|
|
429
|
-
* import { getConsoleSink } from "@logtape/logtape";
|
|
429
|
+
* import { getConsoleSink } from "@logtape/logtape/sink";
|
|
430
430
|
* import { getPrettyFormatter } from "@logtape/pretty";
|
|
431
431
|
*
|
|
432
432
|
* await configure({
|
|
@@ -468,7 +468,7 @@ declare function getPrettyFormatter(options?: PrettyFormatterOptions): TextForma
|
|
|
468
468
|
* @example
|
|
469
469
|
* ```typescript
|
|
470
470
|
* import { configure } from "@logtape/logtape";
|
|
471
|
-
* import { getConsoleSink } from "@logtape/logtape";
|
|
471
|
+
* import { getConsoleSink } from "@logtape/logtape/sink";
|
|
472
472
|
* import { prettyFormatter } from "@logtape/pretty";
|
|
473
473
|
*
|
|
474
474
|
* await configure({
|
package/dist/formatter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.d.ts","names":[],"sources":["../formatter.ts"],"sourcesContent":[],"mappings":";;;;;;;AAQ0E;AAiChE,cAPJ,MAqBI,EAAA;EAKE,SAAK,KAAA,EAAA,WACA;EAsBL,SAAA,IAAA,EAAA,WA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;6BAyBK,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAqCjB;;;;;;;;;;;;;;;;;;8BAmBG;;;;;;;;;;;;;;;;;;;2BAoBH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BAyCG;;;;;;;;;;;;;;;;;0BAkBJ;;;;;;;;;;;;;;;;;;;0BAoBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiJV,kBAAA,WACL,yBACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6VU,iBAAiB"}
|
package/dist/formatter.js
CHANGED
|
@@ -45,18 +45,20 @@ const ansiColors = {
|
|
|
45
45
|
cyan: "\x1B[36m",
|
|
46
46
|
white: "\x1B[37m"
|
|
47
47
|
};
|
|
48
|
+
const RGB_PATTERN = /^rgb\((\d+),(\d+),(\d+)\)$/;
|
|
49
|
+
const HEX_PATTERN = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
|
48
50
|
/**
|
|
49
51
|
* Helper function to convert color to ANSI escape code
|
|
50
52
|
*/
|
|
51
53
|
function colorToAnsi(color) {
|
|
52
54
|
if (color === null) return "";
|
|
53
55
|
if (color in ansiColors) return ansiColors[color];
|
|
54
|
-
const rgbMatch = color.match(
|
|
56
|
+
const rgbMatch = color.match(RGB_PATTERN);
|
|
55
57
|
if (rgbMatch) {
|
|
56
58
|
const [, r, g, b] = rgbMatch;
|
|
57
59
|
return `\x1b[38;2;${r};${g};${b}m`;
|
|
58
60
|
}
|
|
59
|
-
const hexMatch = color.match(
|
|
61
|
+
const hexMatch = color.match(HEX_PATTERN);
|
|
60
62
|
if (hexMatch) {
|
|
61
63
|
let hex = hexMatch[1];
|
|
62
64
|
if (hex.length === 3) hex = hex.split("").map((c) => c + c).join("");
|
|
@@ -125,14 +127,9 @@ const defaultIcons = {
|
|
|
125
127
|
* @returns A new icon map with consistent spacing
|
|
126
128
|
*/
|
|
127
129
|
function normalizeIconSpacing(iconMap) {
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
const currentWidth = getDisplayWidth(icon);
|
|
132
|
-
const spacesToAdd = maxWidth - currentWidth;
|
|
133
|
-
normalizedMap[level] = icon + " ".repeat(spacesToAdd);
|
|
134
|
-
}
|
|
135
|
-
return normalizedMap;
|
|
130
|
+
const entries = Object.entries(iconMap);
|
|
131
|
+
const maxWidth = Math.max(...entries.map(([, icon]) => getDisplayWidth(icon)));
|
|
132
|
+
return Object.fromEntries(entries.map(([level, icon]) => [level, icon + " ".repeat(maxWidth - getDisplayWidth(icon))]));
|
|
136
133
|
}
|
|
137
134
|
/**
|
|
138
135
|
* Platform-specific inspect function. Uses Node.js `util.inspect()` which
|
|
@@ -171,7 +168,7 @@ const inspect$1 = typeof document !== "undefined" || typeof navigator !== "undef
|
|
|
171
168
|
* @example
|
|
172
169
|
* ```typescript
|
|
173
170
|
* import { configure } from "@logtape/logtape";
|
|
174
|
-
* import { getConsoleSink } from "@logtape/logtape";
|
|
171
|
+
* import { getConsoleSink } from "@logtape/logtape/sink";
|
|
175
172
|
* import { getPrettyFormatter } from "@logtape/pretty";
|
|
176
173
|
*
|
|
177
174
|
* await configure({
|
|
@@ -193,7 +190,7 @@ const inspect$1 = typeof document !== "undefined" || typeof navigator !== "undef
|
|
|
193
190
|
* @since 1.0.0
|
|
194
191
|
*/
|
|
195
192
|
function getPrettyFormatter(options = {}) {
|
|
196
|
-
const { timestamp = "none", timestampColor = "rgb(100,116,139)", timestampStyle = "dim", level: levelFormat = "full", levelColors = {}, levelStyle = "underline", icons = true, categorySeparator = "·", categoryColor = "rgb(100,116,139)", categoryColorMap = /* @__PURE__ */ new Map(), categoryStyle = ["dim", "italic"], categoryWidth = 20, categoryTruncate = "middle", messageColor = "rgb(148,163,184)", messageStyle = "dim", colors: useColors = true, align = true, inspectOptions = {}, wordWrap =
|
|
193
|
+
const { timestamp = "none", timestampColor = "rgb(100,116,139)", timestampStyle = "dim", level: levelFormat = "full", levelColors = {}, levelStyle = "underline", icons = true, categorySeparator = "·", categoryColor = "rgb(100,116,139)", categoryColorMap = /* @__PURE__ */ new Map(), categoryStyle = ["dim", "italic"], categoryWidth = 20, categoryTruncate = "middle", messageColor = "rgb(148,163,184)", messageStyle = "dim", colors: useColors = true, align = true, inspectOptions = {}, wordWrap = true } = options;
|
|
197
194
|
const baseIconMap = icons === false ? {
|
|
198
195
|
trace: "",
|
|
199
196
|
debug: "",
|
|
@@ -215,81 +212,78 @@ function getPrettyFormatter(options = {}) {
|
|
|
215
212
|
fatal: defaultColors.fatal,
|
|
216
213
|
...levelColors
|
|
217
214
|
};
|
|
215
|
+
const levelMappings = {
|
|
216
|
+
"ABBR": {
|
|
217
|
+
trace: "TRC",
|
|
218
|
+
debug: "DBG",
|
|
219
|
+
info: "INF",
|
|
220
|
+
warning: "WRN",
|
|
221
|
+
error: "ERR",
|
|
222
|
+
fatal: "FTL"
|
|
223
|
+
},
|
|
224
|
+
"L": {
|
|
225
|
+
trace: "T",
|
|
226
|
+
debug: "D",
|
|
227
|
+
info: "I",
|
|
228
|
+
warning: "W",
|
|
229
|
+
error: "E",
|
|
230
|
+
fatal: "F"
|
|
231
|
+
},
|
|
232
|
+
"abbr": {
|
|
233
|
+
trace: "trc",
|
|
234
|
+
debug: "dbg",
|
|
235
|
+
info: "inf",
|
|
236
|
+
warning: "wrn",
|
|
237
|
+
error: "err",
|
|
238
|
+
fatal: "ftl"
|
|
239
|
+
},
|
|
240
|
+
"l": {
|
|
241
|
+
trace: "t",
|
|
242
|
+
debug: "d",
|
|
243
|
+
info: "i",
|
|
244
|
+
warning: "w",
|
|
245
|
+
error: "e",
|
|
246
|
+
fatal: "f"
|
|
247
|
+
}
|
|
248
|
+
};
|
|
218
249
|
const formatLevel = (level) => {
|
|
219
250
|
if (typeof levelFormat === "function") return levelFormat(level);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
warning: "w",
|
|
252
|
-
error: "e",
|
|
253
|
-
fatal: "f"
|
|
254
|
-
}[level];
|
|
255
|
-
default: return level;
|
|
256
|
-
}
|
|
251
|
+
if (levelFormat === "FULL") return level.toUpperCase();
|
|
252
|
+
if (levelFormat === "full") return level;
|
|
253
|
+
return levelMappings[levelFormat]?.[level] ?? level;
|
|
254
|
+
};
|
|
255
|
+
const timestampFormatters = {
|
|
256
|
+
"date-time-timezone": (ts) => {
|
|
257
|
+
const iso = new Date(ts).toISOString();
|
|
258
|
+
return iso.replace("T", " ").replace("Z", " +00:00");
|
|
259
|
+
},
|
|
260
|
+
"date-time-tz": (ts) => {
|
|
261
|
+
const iso = new Date(ts).toISOString();
|
|
262
|
+
return iso.replace("T", " ").replace("Z", " +00");
|
|
263
|
+
},
|
|
264
|
+
"date-time": (ts) => {
|
|
265
|
+
const iso = new Date(ts).toISOString();
|
|
266
|
+
return iso.replace("T", " ").replace("Z", "");
|
|
267
|
+
},
|
|
268
|
+
"time-timezone": (ts) => {
|
|
269
|
+
const iso = new Date(ts).toISOString();
|
|
270
|
+
return iso.replace(/.*T/, "").replace("Z", " +00:00");
|
|
271
|
+
},
|
|
272
|
+
"time-tz": (ts) => {
|
|
273
|
+
const iso = new Date(ts).toISOString();
|
|
274
|
+
return iso.replace(/.*T/, "").replace("Z", " +00");
|
|
275
|
+
},
|
|
276
|
+
"time": (ts) => {
|
|
277
|
+
const iso = new Date(ts).toISOString();
|
|
278
|
+
return iso.replace(/.*T/, "").replace("Z", "");
|
|
279
|
+
},
|
|
280
|
+
"date": (ts) => new Date(ts).toISOString().replace(/T.*/, ""),
|
|
281
|
+
"rfc3339": (ts) => new Date(ts).toISOString()
|
|
257
282
|
};
|
|
258
283
|
let timestampFn = null;
|
|
259
284
|
if (timestamp === "none" || timestamp === "disabled") timestampFn = null;
|
|
260
|
-
else if (timestamp === "date-time-timezone") timestampFn = (ts) => {
|
|
261
|
-
const date = new Date(ts);
|
|
262
|
-
return date.toISOString().replace("T", " ").replace("Z", " +00:00");
|
|
263
|
-
};
|
|
264
|
-
else if (timestamp === "date-time-tz") timestampFn = (ts) => {
|
|
265
|
-
const date = new Date(ts);
|
|
266
|
-
return date.toISOString().replace("T", " ").replace("Z", " +00");
|
|
267
|
-
};
|
|
268
|
-
else if (timestamp === "date-time") timestampFn = (ts) => {
|
|
269
|
-
const date = new Date(ts);
|
|
270
|
-
return date.toISOString().replace("T", " ").replace("Z", "");
|
|
271
|
-
};
|
|
272
|
-
else if (timestamp === "time-timezone") timestampFn = (ts) => {
|
|
273
|
-
const date = new Date(ts);
|
|
274
|
-
return date.toISOString().replace(/.*T/, "").replace("Z", " +00:00");
|
|
275
|
-
};
|
|
276
|
-
else if (timestamp === "time-tz") timestampFn = (ts) => {
|
|
277
|
-
const date = new Date(ts);
|
|
278
|
-
return date.toISOString().replace(/.*T/, "").replace("Z", " +00");
|
|
279
|
-
};
|
|
280
|
-
else if (timestamp === "time") timestampFn = (ts) => {
|
|
281
|
-
const date = new Date(ts);
|
|
282
|
-
return date.toISOString().replace(/.*T/, "").replace("Z", "");
|
|
283
|
-
};
|
|
284
|
-
else if (timestamp === "date") timestampFn = (ts) => {
|
|
285
|
-
const date = new Date(ts);
|
|
286
|
-
return date.toISOString().replace(/T.*/, "");
|
|
287
|
-
};
|
|
288
|
-
else if (timestamp === "rfc3339") timestampFn = (ts) => {
|
|
289
|
-
const date = new Date(ts);
|
|
290
|
-
return date.toISOString();
|
|
291
|
-
};
|
|
292
285
|
else if (typeof timestamp === "function") timestampFn = timestamp;
|
|
286
|
+
else timestampFn = timestampFormatters[timestamp] ?? null;
|
|
293
287
|
const wordWrapEnabled = wordWrap !== false;
|
|
294
288
|
let wordWrapWidth;
|
|
295
289
|
if (typeof wordWrap === "number") wordWrapWidth = wordWrap;
|
|
@@ -390,7 +384,7 @@ function getPrettyFormatter(options = {}) {
|
|
|
390
384
|
* @example
|
|
391
385
|
* ```typescript
|
|
392
386
|
* import { configure } from "@logtape/logtape";
|
|
393
|
-
* import { getConsoleSink } from "@logtape/logtape";
|
|
387
|
+
* import { getConsoleSink } from "@logtape/logtape/sink";
|
|
394
388
|
* import { prettyFormatter } from "@logtape/pretty";
|
|
395
389
|
*
|
|
396
390
|
* await configure({
|