Description
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
:
class Just {
[Symbol.for("nodejs.util.inspect.custom")](_, opts, inspect) {
return `Just(${inspect(this.__value, opts)})`;
}
}
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.