@@ -80,11 +80,25 @@ export function stringify(
8080
8181export const formatRegExp : RegExp = / % [ s d j i f o O c % ] / g
8282
83- export function format ( ...args : unknown [ ] ) : string {
83+ interface FormatOptions {
84+ prettifyObject ?: boolean
85+ }
86+
87+ function baseFormat ( args : unknown [ ] , options : FormatOptions = { } ) : string {
88+ const formatArg = ( item : unknown , inspecOptions ?: LoupeOptions ) => {
89+ if ( options . prettifyObject ) {
90+ return stringify ( item , undefined , {
91+ printBasicPrototype : false ,
92+ escapeString : false ,
93+ } )
94+ }
95+ return inspect ( item , inspecOptions )
96+ }
97+
8498 if ( typeof args [ 0 ] !== 'string' ) {
8599 const objects = [ ]
86100 for ( let i = 0 ; i < args . length ; i ++ ) {
87- objects . push ( inspect ( args [ i ] , { depth : 0 , colors : false } ) )
101+ objects . push ( formatArg ( args [ i ] , { depth : 0 , colors : false } ) )
88102 }
89103 return objects . join ( ' ' )
90104 }
@@ -112,7 +126,7 @@ export function format(...args: unknown[]): string {
112126 if ( typeof value . toString === 'function' && value . toString !== Object . prototype . toString ) {
113127 return value . toString ( )
114128 }
115- return inspect ( value , { depth : 0 , colors : false } )
129+ return formatArg ( value , { depth : 0 , colors : false } )
116130 }
117131 return String ( value )
118132 }
@@ -133,9 +147,9 @@ export function format(...args: unknown[]): string {
133147 case '%f' :
134148 return Number . parseFloat ( String ( args [ i ++ ] ) ) . toString ( )
135149 case '%o' :
136- return inspect ( args [ i ++ ] , { showHidden : true , showProxy : true } )
150+ return formatArg ( args [ i ++ ] , { showHidden : true , showProxy : true } )
137151 case '%O' :
138- return inspect ( args [ i ++ ] )
152+ return formatArg ( args [ i ++ ] )
139153 case '%c' : {
140154 i ++
141155 return ''
@@ -168,12 +182,20 @@ export function format(...args: unknown[]): string {
168182 str += ` ${ x } `
169183 }
170184 else {
171- str += ` ${ inspect ( x ) } `
185+ str += ` ${ formatArg ( x ) } `
172186 }
173187 }
174188 return str
175189}
176190
191+ export function format ( ...args : unknown [ ] ) : string {
192+ return baseFormat ( args )
193+ }
194+
195+ export function browserFormat ( ...args : unknown [ ] ) : string {
196+ return baseFormat ( args , { prettifyObject : true } )
197+ }
198+
177199export function inspect ( obj : unknown , options : LoupeOptions = { } ) : string {
178200 if ( options . truncate === 0 ) {
179201 options . truncate = Number . POSITIVE_INFINITY
0 commit comments