@@ -327,6 +327,9 @@ stream.write('With ES6');
327
327
<!-- YAML
328
328
added: v0.3.0
329
329
changes:
330
+ - version: REPLACEME
331
+ pr-url: https://github.com/nodejs/node/pull/17907
332
+ description: The `depth` default changed to Infinity.
330
333
- version: REPLACEME
331
334
pr-url: https://github.com/nodejs/node/pull/REPLACEME
332
335
description: The `compact` option is supported now.
@@ -349,9 +352,6 @@ changes:
349
352
* ` options ` {Object}
350
353
* ` showHidden ` {boolean} If ` true ` , the ` object ` 's non-enumerable symbols and
351
354
properties will be included in the formatted result. Defaults to ` false ` .
352
- * ` depth ` {number} Specifies the number of times to recurse while formatting
353
- the ` object ` . This is useful for inspecting large complicated objects.
354
- Defaults to ` 2 ` . To make it recurse indefinitely pass ` null ` .
355
355
* ` colors ` {boolean} If ` true ` , the output will be styled with ANSI color
356
356
codes. Defaults to ` false ` . Colors are customizable, see
357
357
[ Customizing ` util.inspect ` colors] [ ] .
@@ -362,8 +362,8 @@ changes:
362
362
objects. Defaults to ` false ` .
363
363
* ` maxArrayLength ` {number} Specifies the maximum number of array and
364
364
` TypedArray ` elements to include when formatting. Defaults to ` 100 ` . Set to
365
- ` null ` to show all array elements. Set to ` 0 ` or negative to show no array
366
- elements.
365
+ ` null ` or ` Infinity ` to show all array elements. Set to ` 0 ` or negative to
366
+ show no array elements.
367
367
* ` breakLength ` {number} The length at which an object's keys are split
368
368
across multiple lines. Set to ` Infinity ` to format an object as a single
369
369
line. Defaults to 60 for legacy compatibility.
@@ -374,6 +374,10 @@ changes:
374
374
objects the same as arrays. Note that no text will be reduced below 16
375
375
characters, no matter the ` breakLength ` size. For more information, see the
376
376
example below. Defaults to ` true ` .
377
+ * ` depth ` {number} Specifies the number visible nested Objects in an ` object ` .
378
+ This is useful to minimize the inspection output for large complicated
379
+ objects. To make it recurse indefinitely pass ` null ` or ` Infinity ` . Defaults
380
+ to ` Infinity ` .
377
381
378
382
The ` util.inspect() ` method returns a string representation of ` object ` that is
379
383
intended for debugging. The output of ` util.inspect ` may change at any time
@@ -398,12 +402,23 @@ util.inspect(new Bar()); // 'Bar {}'
398
402
util .inspect (baz); // '[foo] {}'
399
403
```
400
404
401
- The following example inspects all properties of the ` util ` object :
405
+ The following example limits the inspected output of the ` paths ` property :
402
406
403
407
``` js
404
408
const util = require (' util' );
405
409
406
- console .log (util .inspect (util, { showHidden: true , depth: null }));
410
+ console .log (util .inspect (module , { depth: 0 }));
411
+ // Instead of showing all entries in `paths` `[Array]` is used to limit the
412
+ // output for readability:
413
+
414
+ // Module {
415
+ // id: '<repl>',
416
+ // exports: {},
417
+ // parent: undefined,
418
+ // filename: null,
419
+ // loaded: false,
420
+ // children: [],
421
+ // paths: [Array] }
407
422
```
408
423
409
424
Values may supply their own custom ` inspect(depth, opts) ` functions, when
@@ -423,7 +438,7 @@ const o = {
423
438
' foo' ]], 4 ],
424
439
b: new Map ([[' za' , 1 ], [' zb' , ' test' ]])
425
440
};
426
- console .log (util .inspect (o, { compact: true , depth : 5 , breakLength: 80 }));
441
+ console .log (util .inspect (o, { compact: true , breakLength: 80 }));
427
442
428
443
// This will print
429
444
@@ -437,7 +452,7 @@ console.log(util.inspect(o, { compact: true, depth: 5, breakLength: 80 }));
437
452
// b: Map { 'za' => 1, 'zb' => 'test' } }
438
453
439
454
// Setting `compact` to false changes the output to be more reader friendly.
440
- console .log (util .inspect (o, { compact: false , depth : 5 , breakLength: 80 }));
455
+ console .log (util .inspect (o, { compact: false , breakLength: 80 }));
441
456
442
457
// {
443
458
// a: [
0 commit comments