summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-12-28 23:40:30 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-10-02 22:43:09 +0200
commitac7450a09a4c167cd43c14d7c88721d22f077529 (patch)
tree296de2457293a1eab58de5fa997d0302794a87d5 /doc
parent83d0404971471b3d4f711ba9690394e9df54eb5f (diff)
downloadandroid-node-v8-ac7450a09a4c167cd43c14d7c88721d22f077529.tar.gz
android-node-v8-ac7450a09a4c167cd43c14d7c88721d22f077529.tar.bz2
android-node-v8-ac7450a09a4c167cd43c14d7c88721d22f077529.zip
util: change util.inspect depth default
The current default is not ideal in most use cases. Therefore it is changed to inspect objects to a maximum depth of 20 in case util.inspect is called with it's defaults. The default is kept at 2 when using console.log() and similar in the repl. PR-URL: https://github.com/nodejs/node/pull/17907 Refs: https://github.com/nodejs/node/issues/12693 PR-URL: https://github.com/nodejs/node/pull/22846 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/util.md24
1 files changed, 19 insertions, 5 deletions
diff --git a/doc/api/util.md b/doc/api/util.md
index 29ba65b760..00604813c3 100644
--- a/doc/api/util.md
+++ b/doc/api/util.md
@@ -361,6 +361,9 @@ stream.write('With ES6');
added: v0.3.0
changes:
- version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/22846
+ description: The `depth` default changed to `20`.
+ - version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/22788
description: The `sorted` option is supported now.
- version: REPLACEME
@@ -401,7 +404,7 @@ changes:
* `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 up to the maximum call stack size pass `Infinity` or `null`.
- **Default:** `2`.
+ **Default:** `20`.
* `colors` {boolean} If `true`, the output will be styled with ANSI color
codes. Colors are customizable, see [Customizing `util.inspect` colors][].
**Default:** `false`.
@@ -458,12 +461,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] }
```
The following example highlights the difference with the `compact` option:
@@ -479,7 +493,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
@@ -493,7 +507,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: [