Skip to content

util: add colorize functionality

The colorize object allows to format strings with ansi color codes so that the string is stylized on a terminal.

This is a utility function that should not yet be exposed to the users to allow some further polishing first. This should be exposed under a completely new formatter module instead of adding new functionality to util. Adding this functionality was discussed at the collaborator summit.

I played around with different builder APIs such as:

new Colorize().bold.green('bold green')
colorize().bold().green('bold green')
colorize.bold.green('bold green')

In the end I went with the latter, especially, due to chalk already using this.

Refs: https://github.com/nodejs/node/issues/43382

Signed-off-by: Ruben Bridgewater ruben@bridgewater.de

@nodejs/util @nodejs/tooling PTAL.

Merge request reports

Loading