7

An issue with Node.js' util.inspect function. I use it to colorize Node.js console output and to format objects. All works fine except that util.inspect prints all those \r\n characters too.

The example. Given a file:

// foo.js

console.log("css:\n", util.inspect(css, { depth: 5, colors: true }), '\n');

The output:

enter image description here

How to make util.inspect not to print all those \r\n characters?

Green
  • 28,742
  • 61
  • 158
  • 247

2 Answers2

4

Looks like the solution suggested in the docs is to manually remove the new line characters:

util.inspect(css, { depth: 5, colors: true }).replace(/\r?\n/g, '')
Jan Molak
  • 4,426
  • 2
  • 36
  • 32
3

According to the current documentation of util.inspect, all you need to do is to set breakLength to Infinity and compact to true.

In your case that would be

console.log("css:\n", util.inspect(css, {
  depth: 5,
  colors: true,
  breakLength: Infinity,
  compact: true,
}), '\n');
Diomidis Spinellis
  • 18,734
  • 5
  • 61
  • 83