11import * as utils from './utils'
22import { Printer , _PrintConfig , _PrintTypes , _SupportedConsole } from './types'
3+ import { DEFAULT_LABEL_SIZE } from './constants'
34
45/* istanbul ignore next */
56export function getCurrentTime ( ) : string {
67 // No need in testing Date module
78 return new Date ( ) . toLocaleTimeString ( )
89}
910
11+ export function stylePlaceholder ( withCss ?: boolean ) : string {
12+ return withCss ? '%c' : ''
13+ }
14+
15+ export function getMessageLabel < T > (
16+ value : T ,
17+ label ?: string ,
18+ withCss ?: boolean ,
19+ ) : string {
20+ const printLabel = label
21+ ? `${ label . padStart ( DEFAULT_LABEL_SIZE , ' ' ) } : `
22+ : '' . padStart ( DEFAULT_LABEL_SIZE + 2 , ' ' )
23+
24+ return `${ printLabel } ${ stylePlaceholder ( withCss ) } ${ String ( value ) } `
25+ }
26+
1027export function getGroupLabel (
1128 type : _PrintTypes ,
1229 componentName ?: string ,
30+ withComponentCSS ?: boolean ,
31+ withSubValueCSS ?: boolean ,
1332) : string {
33+ const componentCssPlaceholder = stylePlaceholder ( withComponentCSS )
34+ const subValueCssPlaceholder = stylePlaceholder ( withComponentCSS )
35+
1436 const componentNameWrapper = componentName
15- ? `in %c <${ String ( componentName ) } /> `
16- : '%c'
37+ ? `in ${ componentCssPlaceholder } <${ String ( componentName ) } /> `
38+ : ` ${ componentCssPlaceholder } `
1739 const typeWrapper = `${ String ( type ) } `
18- const timeWrapper = `%c @ ${ utils . getCurrentTime ( ) } `
40+ const timeWrapper = `${ subValueCssPlaceholder } @ ${ utils . getCurrentTime ( ) } `
1941
2042 return `${ typeWrapper } ${ componentNameWrapper } ${ timeWrapper } `
2143}
@@ -71,7 +93,12 @@ export function print<T>({
7193
7294 if ( flags . isGrouped ) {
7395 getCurrentPrinter ( flags . isCollapsed ? 'groupCollapsed' : 'group' ) (
74- getGroupLabel ( type , componentName ) ,
96+ getGroupLabel (
97+ type ,
98+ componentName ,
99+ Boolean ( componentCSS ) ,
100+ Boolean ( subValueCSS ) ,
101+ ) ,
75102 componentCSS ,
76103 subValueCSS ,
77104 )
@@ -83,9 +110,7 @@ export function print<T>({
83110 css ?: string ,
84111 ) : void => {
85112 const printer = getCurrentPrinter ( logLevel )
86- const message = `${
87- label ? `${ label . padStart ( 14 , ' ' ) } : ` : '' . padStart ( 16 , ' ' )
88- } ${ css ? '%c' : '' } ${ String ( printValue ) } `
113+ const message = getMessageLabel ( printValue , label , Boolean ( css ) )
89114
90115 if ( ! css ) printer ( message )
91116 if ( css ) printer ( message , css )
0 commit comments