@@ -150,7 +150,7 @@ function formatError(value: Error): string {
150150}
151151
152152// eslint-disable-next-line @typescript-eslint/no-explicit-any
153- function formatValue ( ctx : ICtx , value : any , recurseTimes = 0 ) : string {
153+ export function formatValue ( ctx : ICtx , value : any , recurseTimes = 0 ) : string {
154154 // Provide a hook for user-specified inspect functions.
155155 // Check that value is an object with an inspect function on it
156156 if (
@@ -162,6 +162,9 @@ function formatValue(ctx: ICtx, value: any, recurseTimes = 0): string {
162162 // Also filter out any prototype objects using the circular check.
163163 ! ( value ?. constructor && value ?. constructor . prototype === value )
164164 ) {
165+ if ( typeof value . inspect !== "function" && value . toString != null ) {
166+ return value . toString ( ) ;
167+ }
165168 let ret = value ?. inspect ( recurseTimes , ctx ) ;
166169 if ( ! isString ( ret ) ) {
167170 ret = formatValue ( ctx , ret , recurseTimes ) ;
@@ -194,18 +197,22 @@ function formatValue(ctx: ICtx, value: any, recurseTimes = 0): string {
194197
195198 // Some type of object without properties can be shortcutted.
196199 if ( keys . length === 0 ) {
197- if ( isFunction ( value ) ) {
198- const name = value . name ? ": " + value . name : "" ;
199- return ctx . stylize ( "[Function" + name + "]" , "special" ) ;
200- }
201- if ( isRegExp ( value ) ) {
202- return ctx . stylize ( RegExp . prototype . toString . call ( value ) , "regexp" ) ;
203- }
204- if ( isDate ( value ) ) {
205- return ctx . stylize ( Date . prototype . toString . call ( value ) , "date" ) ;
206- }
207- if ( isError ( value ) ) {
208- return formatError ( value as Error ) ;
200+ if ( isFunction ( ctx . stylize ) ) {
201+ if ( isFunction ( value ) ) {
202+ const name = value . name ? ": " + value . name : "" ;
203+ return ctx . stylize ( "[Function" + name + "]" , "special" ) ;
204+ }
205+ if ( isRegExp ( value ) ) {
206+ return ctx . stylize ( RegExp . prototype . toString . call ( value ) , "regexp" ) ;
207+ }
208+ if ( isDate ( value ) ) {
209+ return ctx . stylize ( Date . prototype . toString . call ( value ) , "date" ) ;
210+ }
211+ if ( isError ( value ) ) {
212+ return formatError ( value as Error ) ;
213+ }
214+ } else {
215+ return value ;
209216 }
210217 }
211218
0 commit comments