Skip to content

Commit

Permalink
doc: modernize and fix code examples in util.md
Browse files Browse the repository at this point in the history
* Remove useless constructor.

* Use template literals.

* Update code example.
  Now all arrays with just holes are outputted the same way.
  In the fixed example, it was `[ <101 empty items> ]` twice.

PR-URL: #13298
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
vsemozhetbyt authored and jasnell committed Jun 5, 2017
1 parent 830049f commit 561c14b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ ES6 example using `class` and `extends`
const EventEmitter = require('events');

class MyStream extends EventEmitter {
constructor() {
super();
}
write(data) {
this.emit('data', data);
}
Expand Down Expand Up @@ -329,8 +326,8 @@ class Box {
// Five space padding because that's the size of "Box< ".
const padding = ' '.repeat(5);
const inner = util.inspect(this.value, newOptions)
.replace(/\n/g, '\n' + padding);
return options.stylize('Box', 'special') + '< ' + inner + ' >';
.replace(/\n/g, `\n${padding}`);
return `${options.stylize('Box', 'special')}< ${inner} >`;
}
}

Expand Down Expand Up @@ -392,7 +389,7 @@ option properties directly is also supported.

```js
const util = require('util');
const arr = Array(101);
const arr = Array(101).fill(0);

console.log(arr); // logs the truncated array
util.inspect.defaultOptions.maxArrayLength = null;
Expand Down

0 comments on commit 561c14b

Please sign in to comment.