@@ -12,6 +12,10 @@ import {
1212 PREVIOUS_VALUE_LABEL ,
1313} from './constants'
1414
15+ export function isObjectOrArray < T > ( value : T ) : boolean {
16+ return Array . isArray ( value ) || ( typeof value === 'object' && value !== null )
17+ }
18+
1519/* istanbul ignore next */
1620export function getCurrentTime ( ) : string {
1721 // No need in testing Date module
@@ -30,17 +34,17 @@ export function getMessage<T>(
3034 value : T ,
3135 label ?: string ,
3236 withCss ?: boolean ,
37+ inline = true ,
3338) : string {
3439 const printLabel = label
3540 ? `${ label . padStart ( DEFAULT_LABEL_SIZE , ' ' ) } : `
3641 : '' . padStart ( DEFAULT_LABEL_SIZE + 2 , ' ' )
3742
38- const printValue =
39- typeof value === 'object' && value !== null
40- ? JSON . stringify ( value )
41- : String ( value )
43+ const printValue = isObjectOrArray ( value )
44+ ? JSON . stringify ( value )
45+ : String ( value )
4246
43- return `${ printLabel } ${ stylePlaceholder ( withCss ) } ${ printValue } `
47+ return `${ printLabel } ${ stylePlaceholder ( withCss ) } ${ inline ? printValue : '' } `
4448}
4549
4650export function getGroupLabel (
@@ -127,6 +131,7 @@ export function print<T>({
127131 printer = { } ,
128132 logLevel = 'log' ,
129133 groupLabelRenderer,
134+ inline = true ,
130135} : _PrintConfig < T > ) : void {
131136 const getCurrentPrinter = (
132137 method : keyof _SupportedConsole ,
@@ -147,23 +152,34 @@ export function print<T>({
147152 )
148153 }
149154
150- const printAtLevel = (
151- label ?: string ,
152- printValue : T = value ,
153- css ?: string ,
154- ) : void => {
155+ const printAtLevel = ( printValue : T , label ?: string , css ?: string ) : void => {
155156 const printer = getCurrentPrinter ( logLevel )
156- const message = getMessage ( printValue , label , Boolean ( css ) )
157+ const message = getMessage ( printValue , label , Boolean ( css ) , inline )
157158
158159 if ( ! css ) printer ( message )
159160 if ( css ) printer ( message , css )
160161 }
161162
163+ const printArDirLevel = ( printValue : T ) : void => {
164+ const printer = getCurrentPrinter ( 'dir' )
165+ printer ( printValue )
166+ }
167+
162168 if ( 'prevValue' in arguments [ 0 ] ) {
163- printAtLevel ( PREVIOUS_VALUE_LABEL , arguments [ 0 ] . prevValue , subValueCSS )
164- printAtLevel ( CURRENT_VALUE_LABEL , value , changeCSS )
169+ printAtLevel ( arguments [ 0 ] . prevValue , PREVIOUS_VALUE_LABEL , subValueCSS )
170+ if ( ! inline ) {
171+ printArDirLevel ( arguments [ 0 ] . prevValue )
172+ }
173+
174+ printAtLevel ( value , CURRENT_VALUE_LABEL , changeCSS )
175+ if ( ! inline ) {
176+ printArDirLevel ( value )
177+ }
165178 } else {
166- printAtLevel ( getLabel ( type ) )
179+ printAtLevel ( value , getLabel ( type ) )
180+ if ( ! inline ) {
181+ printArDirLevel ( value )
182+ }
167183 }
168184
169185 if ( flags . isGrouped ) getCurrentPrinter ( 'groupEnd' ) ( )
0 commit comments