Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup update documentation
  • Loading branch information
BridgeAR committed Jan 3, 2018
commit 3ca34ca06e365f05afb2b27257492d13fc23e352
33 changes: 24 additions & 9 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ stream.write('With ES6');
<!-- YAML
added: v0.3.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/17907
description: The `depth` default changed to Infinity.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/REPLACEME
description: The `compact` option is supported now.
Expand All @@ -349,9 +352,6 @@ changes:
* `options` {Object}
* `showHidden` {boolean} If `true`, the `object`'s non-enumerable symbols and
properties will be included in the formatted result. Defaults to `false`.
* `depth` {number} Specifies the number of times to recurse while formatting
the `object`. This is useful for inspecting large complicated objects.
Defaults to `2`. To make it recurse indefinitely pass `null`.
* `colors` {boolean} If `true`, the output will be styled with ANSI color
codes. Defaults to `false`. Colors are customizable, see
[Customizing `util.inspect` colors][].
Expand All @@ -362,8 +362,8 @@ changes:
objects. Defaults to `false`.
* `maxArrayLength` {number} Specifies the maximum number of array and
`TypedArray` elements to include when formatting. Defaults to `100`. Set to
`null` to show all array elements. Set to `0` or negative to show no array
elements.
`null` or `Infinity` to show all array elements. Set to `0` or negative to
show no array elements.
* `breakLength` {number} The length at which an object's keys are split
across multiple lines. Set to `Infinity` to format an object as a single
line. Defaults to 60 for legacy compatibility.
Expand All @@ -374,6 +374,10 @@ changes:
objects the same as arrays. Note that no text will be reduced below 16
characters, no matter the `breakLength` size. For more information, see the
example below. Defaults to `true`.
* `depth` {number} Specifies the number visible nested Objects in an `object`.
This is useful to minimize the inspection output for large complicated
objects. To make it recurse indefinitely pass `null` or `Infinity`. Defaults
to `null`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Infinity instead of null to match the changelog?


The `util.inspect()` method returns a string representation of `object` that is
intended for debugging. The output of `util.inspect` may change at any time
Expand All @@ -398,12 +402,23 @@ util.inspect(new Bar()); // 'Bar {}'
util.inspect(baz); // '[foo] {}'
```

The following example inspects all properties of the `util` object:
The following example limits the inspected output of the `paths` property:

```js
const util = require('util');

console.log(util.inspect(util, { showHidden: true, depth: null }));
console.log(util.inspect(module, { depth: 0 }));
// Instead of showing all entries in `paths` `[Array]` is used to limit the
// output for readability:

// Module {
// id: '<repl>',
// exports: {},
// parent: undefined,
// filename: null,
// loaded: false,
// children: [],
// paths: [Array] }
```

Values may supply their own custom `inspect(depth, opts)` functions, when
Expand All @@ -423,7 +438,7 @@ const o = {
'foo']], 4],
b: new Map([['za', 1], ['zb', 'test']])
};
console.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 }));
console.log(util.inspect(o, { compact: true, breakLength: 80 }));

// This will print

Expand All @@ -437,7 +452,7 @@ console.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 }));
// b: Map { 'za' => 1, 'zb' => 'test' } }

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

// {
// a: [
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/streams/BufferList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const { Buffer } = require('buffer');
const { customInspectSymbol } = require('internal/util');
const util = require('util');

function copyBuffer(src, target, offset) {
Expand Down Expand Up @@ -76,7 +75,7 @@ module.exports = class BufferList {
return ret;
}

[customInspectSymbol]() {
[util.inspect.custom]() {
const obj = util.inspect({ length: this.length });
return `${this.constructor.name} ${obj}`;
}
Expand Down