Skip to content

Commit 41c24aa

Browse files
committed
Move label to optional
1 parent c0b22ef commit 41c24aa

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export interface UseLogReturn {
7676
export interface _PrintConfig<T> {
7777
value: T
7878
prevValue?: T
79-
label: string
79+
label?: string
8080
type?: _PrintTypes
8181
styles?: Styles
8282
componentName: string

src/utils.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,14 @@ describe('utils', () => {
175175
expect(consoleWarn).toHaveBeenCalled()
176176
expect(consoleGroupEnd).toHaveBeenCalled()
177177
})
178+
179+
it('prints without label', () => {
180+
print({
181+
...printProps,
182+
label: undefined,
183+
})
184+
185+
expect(consoleLog).toHaveBeenCalledWith(' Test Value')
186+
})
178187
})
179188
})

src/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ export function print<T>({
6969
method: keyof _SupportedConsole,
7070
): _SupportedConsole[keyof _SupportedConsole] => getPrinter(printer, method)
7171

72-
const groupMethod = flags.isCollapsed ? 'groupCollapsed' : 'group'
73-
7472
if (flags.isGrouped) {
75-
getCurrentPrinter(groupMethod)(
73+
getCurrentPrinter(flags.isCollapsed ? 'groupCollapsed' : 'group')(
7674
getGroupLabel(type, componentName),
7775
componentCSS,
7876
subValueCSS,
@@ -86,7 +84,11 @@ export function print<T>({
8684
)
8785
getCurrentPrinter(logLevel)(` Current value: %c${String(value)}`, changeCSS)
8886
} else {
89-
getCurrentPrinter(logLevel)(`${label.padStart(14, ' ')}: ${String(value)}`)
87+
getCurrentPrinter(logLevel)(
88+
`${label ? `${label.padStart(14, ' ')}: ` : ''.padStart(16, ' ')}${String(
89+
value,
90+
)}`,
91+
)
9092
}
9193

9294
if (flags.isGrouped) getCurrentPrinter('groupEnd')()

0 commit comments

Comments
 (0)