Quantum
Quantum13mo ago

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
Leokuma
Leokuma13mo ago
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()
cknight
cknight13mo ago
Try Deno.inspect(myObj) which returns a string in the same format as console.log(myObj)
Leokuma
Leokuma13mo ago
Oh I didn't know that one. Nice
Quantum
QuantumOP13mo ago
Oh my goodness, that is so incredibly awesome. Thank you so much!
jeff.hykin
jeff.hykin13mo ago
And if you want to make your own deno inspect use yourObj[Symbol.for("Deno.inspect")] = someFunc