diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-04-13 21:40:28 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-05-11 17:46:56 +0200 |
commit | 849aaaeeb045965f3f8085c7cb65c3c830bd724c (patch) | |
tree | 0beefed2ec9fe936e2de381627f66b4dd3860896 /doc/api/util.md | |
parent | 85373aeb4c79dd16bf22549559cf09df17d78e5a (diff) | |
download | android-node-v8-849aaaeeb045965f3f8085c7cb65c3c830bd724c.tar.gz android-node-v8-849aaaeeb045965f3f8085c7cb65c3c830bd724c.tar.bz2 android-node-v8-849aaaeeb045965f3f8085c7cb65c3c830bd724c.zip |
Revert "util: change util.inspect depth default"
This reverts commit b994b8eff6018433a56bb10dbc473cefa0dd9370.
This caused regressions in ecosystem code. While the change originally
was semver-major and could be postponed until after Node.js 10,
I think reverting it is a good choice at this point.
Also, I personally do not think defaulting to a shallow inspect
is a bad thing at all – quite the opposite: It makes `util.inspect()`
give an overview of an object, rather than providing a full
display of its contents. Changing the `depth` default to infinity
fundamentally changed the role that `util.inspect()` plays,
and makes output much more verbose and thus at times unusable
for `console.log()`-style debugging.
PR-URL: https://github.com/nodejs/node/pull/20017
Fixes: https://github.com/nodejs/node/issues/19405
Refs: https://github.com/nodejs/node/pull/17907
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'doc/api/util.md')
-rw-r--r-- | doc/api/util.md | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/doc/api/util.md b/doc/api/util.md index 1f2b2887da..bec24e6410 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -364,9 +364,6 @@ changes: pr-url: https://github.com/nodejs/node/pull/19259 description: The `WeakMap` and `WeakSet` entries can now be inspected as well. - - version: REPLACEME - pr-url: https://github.com/nodejs/node/pull/17907 - description: The `depth` default changed to `Infinity`. - version: v9.9.0 pr-url: https://github.com/nodejs/node/pull/17576 description: The `compact` option is supported now. @@ -390,6 +387,9 @@ changes: * `showHidden` {boolean} If `true`, the `object`'s non-enumerable symbols and properties will be included in the formatted result as well as [`WeakMap`][] and [`WeakSet`][] entries. **Default:** `false`. + * `depth` {number} Specifies the number of times to recurse while formatting + the `object`. This is useful for inspecting large complicated objects. + To make it recurse indefinitely pass `null`. **Default:** `2`. * `colors` {boolean} If `true`, the output will be styled with ANSI color codes. Colors are customizable, see [Customizing `util.inspect` colors][]. **Default:** `false`. @@ -416,10 +416,7 @@ 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. **Default:** `true`. - * `depth` {number} Specifies the number of visible nested `Object`s in an - `object`. This is useful to minimize the inspection output for large - complicated objects. To make it recurse indefinitely pass `null` or - `Infinity`. **Default:** `Infinity`. + * Returns: {string} The representation of passed object The `util.inspect()` method returns a string representation of `object` that is @@ -445,23 +442,12 @@ util.inspect(new Bar()); // 'Bar {}' util.inspect(baz); // '[foo] {}' ``` -The following example limits the inspected output of the `paths` property: +The following example inspects all properties of the `util` object: ```js const util = require('util'); -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] } +console.log(util.inspect(util, { showHidden: true, depth: null })); ``` Values may supply their own custom `inspect(depth, opts)` functions, when @@ -481,7 +467,7 @@ const o = { 'foo']], 4], b: new Map([['za', 1], ['zb', 'test']]) }; -console.log(util.inspect(o, { compact: true, breakLength: 80 })); +console.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 })); // This will print @@ -495,7 +481,7 @@ console.log(util.inspect(o, { compact: true, 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, breakLength: 80 })); +console.log(util.inspect(o, { compact: false, depth: 5, breakLength: 80 })); // { // a: [ |