@@ -19,12 +19,13 @@ const util = require('util');
19
19
The ` util.debuglog() ` method is used to create a function that conditionally
20
20
writes debug messages to ` stderr ` based on the existence of the ` NODE_DEBUG `
21
21
environment variable. If the ` section ` name appears within the value of that
22
- environment variable, then the returned function operate similar to
22
+ environment variable, then the returned function operates similar to
23
23
` console.error() ` . If not, then the returned function is a no-op.
24
24
25
25
For example:
26
26
27
27
``` js
28
+ const util = require (' util' );
28
29
const debuglog = util .debuglog (' foo' );
29
30
30
31
debuglog (' hello from foo [%d]' , 123 );
@@ -46,7 +47,7 @@ environment variable. For example: `NODE_DEBUG=fs,net,tls`.
46
47
## util.deprecate(function, string)
47
48
48
49
The ` util.deprecate() ` method wraps the given ` function ` in such a way that
49
- marks it as being deprecated.
50
+ it is marked as deprecated.
50
51
51
52
``` js
52
53
const util = require (' util' );
@@ -58,10 +59,10 @@ exports.puts = util.deprecate(() => {
58
59
}, ' util.puts: Use console.log instead' );
59
60
```
60
61
61
- When called, ` util.deprecated () ` will return a function that will emit a
62
+ When called, ` util.deprecate () ` will return a function that will emit a
62
63
` DeprecationWarning ` using the ` process.on('warning') ` event. By default,
63
- this warning will be emitted and printed to ` stderr ` exactly once the first
64
- time that it is called. After the warning is emitted, the wrapped ` function `
64
+ this warning will be emitted and printed to ` stderr ` exactly once, the first
65
+ time it is called. After the warning is emitted, the wrapped ` function `
65
66
is called.
66
67
67
68
If either the ` --no-deprecation ` or ` --no-warnings ` command line flags are
@@ -106,10 +107,10 @@ util.format('%s:%s', 'foo');
106
107
// Returns 'foo:%s'
107
108
```
108
109
109
- If there are more arguments passed to the ` util.format() ` method than there are
110
- placeholders, the extra arguments are coerced into strings (for objects and
111
- symbols, ` util.inspect() ` is used) then concatenated to the returned string,
112
- delimited by a space.
110
+ If there are more arguments passed to the ` util.format() ` method than the
111
+ number of placeholders, the extra arguments are coerced into strings (for
112
+ objects and symbols, ` util.inspect() ` is used) then concatenated to the
113
+ returned string, each delimited by a space.
113
114
114
115
``` js
115
116
util .format (' %s:%s' , ' foo' , ' bar' , ' baz' ); // 'foo:bar baz'
@@ -125,7 +126,7 @@ util.format(1, 2, 3); // '1 2 3'
125
126
126
127
## util.inherits(constructor, superConstructor)
127
128
128
- _ Note: usage of util.inherits() is discouraged. Please use the ES6 ` class ` and
129
+ _ Note: usage of ` util.inherits() ` is discouraged. Please use the ES6 ` class ` and
129
130
` extends ` keywords to get language level inheritance support. Also note that
130
131
the two styles are [ semantically incompatible] [ ] ._
131
132
@@ -153,7 +154,7 @@ MyStream.prototype.write = function(data) {
153
154
this .emit (' data' , data);
154
155
}
155
156
156
- var stream = new MyStream ();
157
+ const stream = new MyStream ();
157
158
158
159
console .log (stream instanceof EventEmitter); // true
159
160
console .log (MyStream .super_ === EventEmitter); // true
@@ -168,20 +169,19 @@ stream.write('It works!'); // Received data: "It works!"
168
169
169
170
* ` object ` {any} Any JavaScript primitive or Object.
170
171
* ` options ` {Object}
171
- * ` showHidden ` {boolean} If ` true ` , the ` object ` 's non-enumerable and
172
- symbol properties will be included in the formatted result. Defaults to
173
- ` false ` .
174
- * ` depth ` (number) Specifies how many times to recurse while formatting the
175
- ` object ` . This is useful for inspecting large complicated objects. Defaults
176
- to ` 2 ` . To make it recurse indefinitely pass ` null ` .
172
+ * ` showHidden ` {boolean} If ` true ` , the ` object ` 's non-enumerable symbols and
173
+ properties will be included in the formatted result. Defaults to ` false ` .
174
+ * ` depth ` {number} Specifies the number of times to recurse while formatting
175
+ the ` object ` . This is useful for inspecting large complicated objects.
176
+ Defaults to ` 2 ` . To make it recurse indefinitely pass ` null ` .
177
177
* ` colors ` {boolean} If ` true ` , the output will be styled with ANSI color
178
178
codes. Defaults to ` false ` . Colors are customizable, see
179
179
[ Customizing ` util.inspect ` colors] [ ] .
180
180
* ` customInspect ` {boolean} If ` false ` , then custom ` inspect(depth, opts) `
181
181
functions exported on the ` object ` being inspected will not be called.
182
182
Defaults to ` true ` .
183
183
* ` showProxy ` {boolean} If ` true ` , then objects and functions that are
184
- ` Proxy ` objects will be introspected to show their ` target ` and ` hander `
184
+ ` Proxy ` objects will be introspected to show their ` target ` and ` handler `
185
185
objects. Defaults to ` false ` .
186
186
* ` maxArrayLength ` {number} Specifies the maximum number of array and
187
187
` TypedArray ` elements to include when formatting. Defaults to ` 100 ` . Set to
@@ -243,7 +243,7 @@ Objects may also define their own `inspect(depth, opts)` function that
243
243
``` js
244
244
const util = require (' util' );
245
245
246
- var obj = { name: ' nate' };
246
+ const obj = { name: ' nate' };
247
247
obj .inspect = function (depth ) {
248
248
return ` {${ this .name } }` ;
249
249
};
@@ -257,7 +257,9 @@ return a value of any type that will be formatted accordingly by
257
257
` util.inspect() ` .
258
258
259
259
``` js
260
- var obj = { foo: ' this will not show up in the inspect() output' };
260
+ const util = require (' util' );
261
+
262
+ const obj = { foo: ' this will not show up in the inspect() output' };
261
263
obj .inspect = function (depth ) {
262
264
return { bar: ' baz' };
263
265
};
@@ -300,11 +302,11 @@ Returns `true` if the given `object` is an `Array`. Otherwise, returns `false`.
300
302
``` js
301
303
const util = require (' util' );
302
304
303
- util .isArray ([])
305
+ util .isArray ([]);
304
306
// true
305
- util .isArray (new Array )
307
+ util .isArray (new Array );
306
308
// true
307
- util .isArray ({})
309
+ util .isArray ({});
308
310
// false
309
311
```
310
312
@@ -319,11 +321,11 @@ Returns `true` if the given `object` is a `Boolean`. Otherwise, returns `false`.
319
321
``` js
320
322
const util = require (' util' );
321
323
322
- util .isBoolean (1 )
324
+ util .isBoolean (1 );
323
325
// false
324
- util .isBoolean (0 )
326
+ util .isBoolean (0 );
325
327
// false
326
- util .isBoolean (false )
328
+ util .isBoolean (false );
327
329
// true
328
330
```
329
331
@@ -338,11 +340,11 @@ Returns `true` if the given `object` is a `Buffer`. Otherwise, returns `false`.
338
340
``` js
339
341
const util = require (' util' );
340
342
341
- util .isBuffer ({ length: 0 })
343
+ util .isBuffer ({ length: 0 });
342
344
// false
343
- util .isBuffer ([])
345
+ util .isBuffer ([]);
344
346
// false
345
- util .isBuffer (Buffer .from (' hello world' ))
347
+ util .isBuffer (Buffer .from (' hello world' ));
346
348
// true
347
349
```
348
350
@@ -357,11 +359,11 @@ Returns `true` if the given `object` is a `Date`. Otherwise, returns `false`.
357
359
``` js
358
360
const util = require (' util' );
359
361
360
- util .isDate (new Date ())
362
+ util .isDate (new Date ());
361
363
// true
362
- util .isDate (Date ())
364
+ util .isDate (Date ());
363
365
// false (without 'new' returns a String)
364
- util .isDate ({})
366
+ util .isDate ({});
365
367
// false
366
368
```
367
369
@@ -377,11 +379,11 @@ Returns `true` if the given `object` is an [`Error`][]. Otherwise, returns
377
379
``` js
378
380
const util = require (' util' );
379
381
380
- util .isError (new Error ())
382
+ util .isError (new Error ());
381
383
// true
382
- util .isError (new TypeError ())
384
+ util .isError (new TypeError ());
383
385
// true
384
- util .isError ({ name: ' Error' , message: ' an error occurred' })
386
+ util .isError ({ name: ' Error' , message: ' an error occurred' });
385
387
// false
386
388
```
387
389
@@ -413,13 +415,13 @@ Returns `true` if the given `object` is a `Function`. Otherwise, returns
413
415
const util = require (' util' );
414
416
415
417
function Foo () {}
416
- var Bar = function () {};
418
+ const Bar = function () {};
417
419
418
- util .isFunction ({})
420
+ util .isFunction ({});
419
421
// false
420
- util .isFunction (Foo)
422
+ util .isFunction (Foo);
421
423
// true
422
- util .isFunction (Bar)
424
+ util .isFunction (Bar);
423
425
// true
424
426
```
425
427
@@ -435,11 +437,11 @@ Returns `true` if the given `object` is strictly `null`. Otherwise, returns
435
437
``` js
436
438
const util = require (' util' );
437
439
438
- util .isNull (0 )
440
+ util .isNull (0 );
439
441
// false
440
- util .isNull (undefined )
442
+ util .isNull (undefined );
441
443
// false
442
- util .isNull (null )
444
+ util .isNull (null );
443
445
// true
444
446
```
445
447
@@ -455,11 +457,11 @@ returns `false`.
455
457
``` js
456
458
const util = require (' util' );
457
459
458
- util .isNullOrUndefined (0 )
460
+ util .isNullOrUndefined (0 );
459
461
// false
460
- util .isNullOrUndefined (undefined )
462
+ util .isNullOrUndefined (undefined );
461
463
// true
462
- util .isNullOrUndefined (null )
464
+ util .isNullOrUndefined (null );
463
465
// true
464
466
```
465
467
@@ -474,13 +476,13 @@ Returns `true` if the given `object` is a `Number`. Otherwise, returns `false`.
474
476
``` js
475
477
const util = require (' util' );
476
478
477
- util .isNumber (false )
479
+ util .isNumber (false );
478
480
// false
479
- util .isNumber (Infinity )
481
+ util .isNumber (Infinity );
480
482
// true
481
- util .isNumber (0 )
483
+ util .isNumber (0 );
482
484
// true
483
- util .isNumber (NaN )
485
+ util .isNumber (NaN );
484
486
// true
485
487
```
486
488
@@ -496,13 +498,13 @@ Returns `true` if the given `object` is strictly an `Object` __and__ not a
496
498
``` js
497
499
const util = require (' util' );
498
500
499
- util .isObject (5 )
501
+ util .isObject (5 );
500
502
// false
501
- util .isObject (null )
503
+ util .isObject (null );
502
504
// false
503
- util .isObject ({})
505
+ util .isObject ({});
504
506
// true
505
- util .isObject (function (){})
507
+ util .isObject (function (){});
506
508
// false
507
509
```
508
510
@@ -518,23 +520,23 @@ Returns `true` if the given `object` is a primitive type. Otherwise, returns
518
520
``` js
519
521
const util = require (' util' );
520
522
521
- util .isPrimitive (5 )
523
+ util .isPrimitive (5 );
522
524
// true
523
- util .isPrimitive (' foo' )
525
+ util .isPrimitive (' foo' );
524
526
// true
525
- util .isPrimitive (false )
527
+ util .isPrimitive (false );
526
528
// true
527
- util .isPrimitive (null )
529
+ util .isPrimitive (null );
528
530
// true
529
- util .isPrimitive (undefined )
531
+ util .isPrimitive (undefined );
530
532
// true
531
- util .isPrimitive ({})
533
+ util .isPrimitive ({});
532
534
// false
533
- util .isPrimitive (function () {})
535
+ util .isPrimitive (function () {});
534
536
// false
535
- util .isPrimitive (/ ^$ / )
537
+ util .isPrimitive (/ ^$ / );
536
538
// false
537
- util .isPrimitive (new Date ())
539
+ util .isPrimitive (new Date ());
538
540
// false
539
541
```
540
542
@@ -549,11 +551,11 @@ Returns `true` if the given `object` is a `RegExp`. Otherwise, returns `false`.
549
551
``` js
550
552
const util = require (' util' );
551
553
552
- util .isRegExp (/ some regexp/ )
554
+ util .isRegExp (/ some regexp/ );
553
555
// true
554
- util .isRegExp (new RegExp (' another regexp' ))
556
+ util .isRegExp (new RegExp (' another regexp' ));
555
557
// true
556
- util .isRegExp ({})
558
+ util .isRegExp ({});
557
559
// false
558
560
```
559
561
@@ -568,13 +570,13 @@ Returns `true` if the given `object` is a `string`. Otherwise, returns `false`.
568
570
``` js
569
571
const util = require (' util' );
570
572
571
- util .isString (' ' )
573
+ util .isString (' ' );
572
574
// true
573
- util .isString (' foo' )
575
+ util .isString (' foo' );
574
576
// true
575
- util .isString (String (' foo' ))
577
+ util .isString (String (' foo' ));
576
578
// true
577
- util .isString (5 )
579
+ util .isString (5 );
578
580
// false
579
581
```
580
582
@@ -589,11 +591,11 @@ Returns `true` if the given `object` is a `Symbol`. Otherwise, returns `false`.
589
591
``` js
590
592
const util = require (' util' );
591
593
592
- util .isSymbol (5 )
594
+ util .isSymbol (5 );
593
595
// false
594
- util .isSymbol (' foo' )
596
+ util .isSymbol (' foo' );
595
597
// false
596
- util .isSymbol (Symbol (' foo' ))
598
+ util .isSymbol (Symbol (' foo' ));
597
599
// true
598
600
```
599
601
@@ -608,12 +610,12 @@ Returns `true` if the given `object` is `undefined`. Otherwise, returns `false`.
608
610
``` js
609
611
const util = require (' util' );
610
612
611
- var foo;
612
- util .isUndefined (5 )
613
+ const foo = undefined ;
614
+ util .isUndefined (5 );
613
615
// false
614
- util .isUndefined (foo)
616
+ util .isUndefined (foo);
615
617
// true
616
- util .isUndefined (null )
618
+ util .isUndefined (null );
617
619
// false
618
620
```
619
621
@@ -627,7 +629,7 @@ The `util.log()` method prints the given `string` to `stdout` with an included
627
629
timestamp.
628
630
629
631
``` js
630
- const util = require (' util' )
632
+ const util = require (' util' );
631
633
632
634
util .log (' Timestamped message.' );
633
635
```
0 commit comments