Skip to content

Commit d9dab87

Browse files
committed
Update code style in utils
1 parent 7bd3063 commit d9dab87

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/utils.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import { Printer, _PrintConfig, _PrintTypes, _SupportedConsole } from './types'
22

3+
export function getCurrentDate(): string {
4+
return new Date().toLocaleTimeString()
5+
}
6+
37
export function getGroupLabel(
48
type: _PrintTypes,
59
componentName?: string,
610
): 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}`
1018
}
1119

1220
export function getComponentName(): string {
@@ -57,20 +65,21 @@ export function print<T>({
5765
const getCurrentPrinter = (
5866
method: keyof _SupportedConsole,
5967
): _SupportedConsole[keyof _SupportedConsole] => getPrinter(printer, method)
68+
6069
const groupMethod = flags.isCollapsed ? 'groupCollapsed' : 'group'
6170

6271
if (flags.isGrouped) {
6372
getCurrentPrinter(groupMethod)(group, componentCSS, subValueCSS)
6473
}
6574

66-
if (!('prevValue' in arguments[0])) {
67-
getCurrentPrinter('log')(`${label.padStart(14, ' ')}: ${String(value)}`)
68-
} else {
75+
if ('prevValue' in arguments[0]) {
6976
getCurrentPrinter('log')(
7077
`Previous value: %c${String(arguments[0].prevValue)}`,
7178
subValueCSS,
7279
)
7380
getCurrentPrinter('log')(` Current value: %c${String(value)}`, changeCSS)
81+
} else {
82+
getCurrentPrinter('log')(`${label.padStart(14, ' ')}: ${String(value)}`)
7483
}
7584

7685
if (flags.isGrouped) {

0 commit comments

Comments
 (0)