Custom console.log formatting for a class/object
Is there a way to change the way an object/class is printed in the console?
For example, instead of
, I want the particular object to be printed as
5 Replies
you can specify some options for how you want the object to be displayed https://deno.land/api@v1.35.1?s=Deno.InspectOptions
Deno
Deno.InspectOptions | Runtime APIs | Deno
Option which can be specified when performing {@linkcode Deno.inspect}.
if you want to have a more specific way of displaying your object, you can use the
Deno.customInspect
symbol to implement your own way of inspecting the object https://deno.land/manual@v1.35.1/basics/testing/snapshot_testing#serialization-with--denocustominspectDeno
Snapshots | Manual | Deno
The Deno standard library comes with a
snapshot module, which
enables developers to write tests which assert a value against a reference
snap
Here's a little example it showing off
stdout
you can also define it for specific object classes as well if you want, or implement the symbol in your own class
Ooh thank you
I'll take a look into it