How to get the nice Deno console.log format into a string?
When I do a console.log on an instantiated class object, I get a beautiful format in the terminal, thanks to Deno. How would I get that same nice Deno format into a string? When I do obj.toString(), I just get the standard Javascript [object Object].
5 Replies
I'm not sure if that formatting is exposed to us. Maybe it's internal to Deno
What you can do is
JSON.stringify(obj)
. Not the same output as console.log
, but better than .toString()
Try
Deno.inspect(myObj)
which returns a string in the same format as console.log(myObj)
Oh I didn't know that one. Nice
Oh my goodness, that is so incredibly awesome. Thank you so much!
And if you want to make your own deno inspect use
yourObj[Symbol.for("Deno.inspect")] = someFunc