Skip to content

Commit

Permalink
doc: fix outdated util inspect documentation and layout example
Browse files Browse the repository at this point in the history
The documentation and layout example was not up to date with the
latest changes.

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

PR-URL: #37079
Fixes: #37054
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
BridgeAR authored and jasnell committed Apr 30, 2021
1 parent 942b76d commit 5bfb6f0
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,11 @@ changes:
(in combination with `compact` set to `true` or any number >= `1`).
**Default:** `80`.
* `compact` {boolean|integer} Setting this to `false` causes each object key
to be displayed on a new line. It will also add new lines to text that is
to be displayed on a new line. It will break on new lines in text that is
longer than `breakLength`. If set to a number, the most `n` inner elements
are united on a single line as long as all properties fit into
`breakLength`. Short array elements are also grouped together. No
text will be reduced below 16 characters, no matter the `breakLength` size.
For more information, see the example below. **Default:** `3`.
`breakLength`. Short array elements are also grouped together. For more
information, see the example below. **Default:** `3`.
* `sorted` {boolean|Function} If set to `true` or a function, all properties
of an object, and `Set` and `Map` entries are sorted in the resulting
string. If set to `true` the [default sort][] is used. If set to a function,
Expand Down Expand Up @@ -649,8 +648,8 @@ const util = require('util');

const o = {
a: [1, 2, [[
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do ' +
'eiusmod tempor incididunt ut labore et dolore magna aliqua.',
'Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit, sed do ' +
'eiusmod \ntempor incididunt ut labore et dolore magna aliqua.',
'test',
'foo']], 4],
b: new Map([['za', 1], ['zb', 'test']])
Expand All @@ -660,13 +659,13 @@ console.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 }));
// { a:
// [ 1,
// 2,
// [ [ 'Lorem ipsum dolor sit amet, consectetur [...]', // A long line
// [ [ 'Lorem ipsum dolor sit amet,\nconsectetur [...]', // A long line
// 'test',
// 'foo' ] ],
// 4 ],
// b: Map(2) { 'za' => 1, 'zb' => 'test' } }

// Setting `compact` to false changes the output to be more reader friendly.
// Setting `compact` to false or an integer creates more reader friendly output.
console.log(util.inspect(o, { compact: false, depth: 5, breakLength: 80 }));

// {
Expand All @@ -675,10 +674,9 @@ console.log(util.inspect(o, { compact: false, depth: 5, breakLength: 80 }));
// 2,
// [
// [
// 'Lorem ipsum dolor sit amet, consectetur ' +
// 'adipiscing elit, sed do eiusmod tempor ' +
// 'incididunt ut labore et dolore magna ' +
// 'aliqua.,
// 'Lorem ipsum dolor sit amet,\n' +
// 'consectetur adipiscing elit, sed do eiusmod \n' +
// 'tempor incididunt ut labore et dolore magna aliqua.',
// 'test',
// 'foo'
// ]
Expand All @@ -693,8 +691,6 @@ console.log(util.inspect(o, { compact: false, depth: 5, breakLength: 80 }));

// Setting `breakLength` to e.g. 150 will print the "Lorem ipsum" text in a
// single line.
// Reducing the `breakLength` will split the "Lorem ipsum" text in smaller
// chunks.
```

The `showHidden` option allows [`WeakMap`][] and [`WeakSet`][] entries to be
Expand Down

0 comments on commit 5bfb6f0

Please sign in to comment.