You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
currently, the classes in this library expose a method called inspect(). this is fine, but it's not very useful because the thing that it's modeled after, node:util's inspect(), doesn't know how to use it. so if you plainly console.log(something) it will look very ugly. the way to fix this is by defining another method, [Symbol.for("nodejs.util.inspect.custom")]—see this example for Just:
as you can see, this method also harnesses the passed-down inspect function to get the sub-value(s) recursively pretty-printed inside the parentheses, which avoids boring white output and [object Object]. having defined this method, it's as simple as e.g. console.log(Just(new Date)) and you get pretty output for free!
this would only affect Node.js behavior; this symbol is not globally registered in the browser so nothing will happen there at all. i'm down to open a PR so just let me know.
The text was updated successfully, but these errors were encountered:
cAttte
changed the title
Better Node.js inspect() support
Better Node.js inspect() support [PR-ready]
Feb 6, 2025
currently, the classes in this library expose a method called
inspect()
. this is fine, but it's not very useful because the thing that it's modeled after,node:util
'sinspect()
, doesn't know how to use it. so if you plainlyconsole.log(something)
it will look very ugly. the way to fix this is by defining another method,[Symbol.for("nodejs.util.inspect.custom")]
—see this example forJust
:as you can see, this method also harnesses the passed-down
inspect
function to get the sub-value(s) recursively pretty-printed inside the parentheses, which avoids boring white output and[object Object]
. having defined this method, it's as simple as e.g.console.log(Just(new Date))
and you get pretty output for free!this would only affect Node.js behavior; this symbol is not globally registered in the browser so nothing will happen there at all. i'm down to open a PR so just let me know.
The text was updated successfully, but these errors were encountered: