unist-util-inspect
unist-util-inspect copied to clipboard
add optional `colors: boolean` flag to `Options`
Initial checklist
- [x] I read the support docs
- [x] I read the contributing guide
- [x] I agree to follow the code of conduct
- [x] I searched issues and couldn’t find anything (or linked relevant results below)
- [x] If applicable, I’ve added docs and tests
Description of changes
Previously, inspect() would always add ANSI color sequences when on Node and always omit them otherwise. inspectNoColor() and inspectColor() were exported to override this, but that was a little bit clunky. This adds an optional colors: boolean flag to Options. (Note that this is the same flag name as in node:util's inspect).
The default behaviour is unchanged: this feature is purely additive.
Internally, this also introduces the colorization/stylization functions to State, allowing the no-color path to simply omit colorization, rather than stripping ANSI sequences after the fact.
Rebased to resolve the trivial import-name conflict.
Thanks! It's not urgent, just some tinkering I felt might be useful to contribute.
For a little context where I was going with this before getting distracted-from-distractions, was to add a "depth" parameter and then use inspect from node:util instead of JSON.stringify in that environment. That would have been impossible or at least brittle with the post-format color erasure.
Thanks for your patience!
but that was a little bit clunky
If we’re getting more options, sure.
For a little context where I was going with this before getting distracted-from-distractions, was to add a "depth" parameter and then use inspect from node:util instead of JSON.stringify in that environment. That would have been impossible or at least brittle with the post-format color erasure.
Oh nice!
Hmm, I also feel the plural colors is not needed, color: boolean is what we use everywhere.
unifiedjs/unified-engine, vfile/vfile-reporter.
There’s something to say for consistency with node:util, but I’d prefer consistency with our stuff.
This needs docs!
Hi! This was closed. Team: If this was merged, please describe when this is likely to be released. Otherwise, please add one of the no/* labels.