summaryrefslogtreecommitdiff
path: root/doc/api/util.md
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-12-28 23:40:30 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-01-16 15:34:03 +0100
commitb994b8eff6018433a56bb10dbc473cefa0dd9370 (patch)
tree018ee50d8c636219348747431053d7cd2a1405ca /doc/api/util.md
parent9d3958102ec28f2bb468b2c532b7b34cabd61f1b (diff)
downloadandroid-node-v8-b994b8eff6018433a56bb10dbc473cefa0dd9370.tar.gz
android-node-v8-b994b8eff6018433a56bb10dbc473cefa0dd9370.tar.bz2
android-node-v8-b994b8eff6018433a56bb10dbc473cefa0dd9370.zip
util: change util.inspect depth default
The current default is not ideal in most use cases. Therefore it is changed to showing unlimited depth in case util.inspect is called directly. The default is kept as before for console.log and similar. Using console.dir will now show a depth of up to five and console.assert / console.trace will show a unlimited depth. PR-URL: https://github.com/nodejs/node/pull/17907 Refs: https://github.com/nodejs/node/issues/12693 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'doc/api/util.md')
-rw-r--r--doc/api/util.md33
1 files changed, 24 insertions, 9 deletions
diff --git a/doc/api/util.md b/doc/api/util.md
index a2d3c71bb6..ae4cec72e1 100644
--- a/doc/api/util.md
+++ b/doc/api/util.md
@@ -328,6 +328,9 @@ stream.write('With ES6');
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.
- version: v6.6.0
@@ -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][].
@@ -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.
@@ -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 `Infinity`.
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
@@ -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
@@ -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
@@ -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: [