|
1 | 1 | import { Printer, _PrintConfig, _PrintTypes, _SupportedConsole } from './types' |
2 | 2 |
|
| 3 | +export function getCurrentDate(): string { |
| 4 | + return new Date().toLocaleTimeString() |
| 5 | +} |
| 6 | + |
3 | 7 | export function getGroupLabel( |
4 | 8 | type: _PrintTypes, |
5 | 9 | componentName?: string, |
6 | 10 | ): string { |
7 | | - return `${String(type)} ${ |
8 | | - componentName ? 'in %c<' + String(componentName) + ' /> ' : '%c' |
9 | | - }%c@ ${new Date().toLocaleTimeString()}` |
| 11 | + const componentNameWrapper = componentName |
| 12 | + ? `in %c<${String(componentName)} /> ` |
| 13 | + : '%c' |
| 14 | + const typeWrapper = `${String(type)} ` |
| 15 | + const dateWrapper = `%c@ ${getCurrentDate()}` |
| 16 | + |
| 17 | + return `${typeWrapper}${componentNameWrapper}${dateWrapper}` |
10 | 18 | } |
11 | 19 |
|
12 | 20 | export function getComponentName(): string { |
@@ -57,20 +65,21 @@ export function print<T>({ |
57 | 65 | const getCurrentPrinter = ( |
58 | 66 | method: keyof _SupportedConsole, |
59 | 67 | ): _SupportedConsole[keyof _SupportedConsole] => getPrinter(printer, method) |
| 68 | + |
60 | 69 | const groupMethod = flags.isCollapsed ? 'groupCollapsed' : 'group' |
61 | 70 |
|
62 | 71 | if (flags.isGrouped) { |
63 | 72 | getCurrentPrinter(groupMethod)(group, componentCSS, subValueCSS) |
64 | 73 | } |
65 | 74 |
|
66 | | - if (!('prevValue' in arguments[0])) { |
67 | | - getCurrentPrinter('log')(`${label.padStart(14, ' ')}: ${String(value)}`) |
68 | | - } else { |
| 75 | + if ('prevValue' in arguments[0]) { |
69 | 76 | getCurrentPrinter('log')( |
70 | 77 | `Previous value: %c${String(arguments[0].prevValue)}`, |
71 | 78 | subValueCSS, |
72 | 79 | ) |
73 | 80 | getCurrentPrinter('log')(` Current value: %c${String(value)}`, changeCSS) |
| 81 | + } else { |
| 82 | + getCurrentPrinter('log')(`${label.padStart(14, ' ')}: ${String(value)}`) |
74 | 83 | } |
75 | 84 |
|
76 | 85 | if (flags.isGrouped) { |
|
0 commit comments