doc: make comment indentation consistent
Currently, some of the docs use different indentation for comments in the code examples. This commit makes the indentation consistent by putting the comments at the beginning of the line (really no indentation that is). PR-URL: https://github.com/nodejs/node/pull/9518 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
5242114d89
commit
367065be4b
@ -140,7 +140,8 @@ Once built, the binary Addon can be used from within Node.js by pointing
|
||||
// hello.js
|
||||
const addon = require('./build/Release/addon');
|
||||
|
||||
console.log(addon.hello()); // 'world'
|
||||
console.log(addon.hello());
|
||||
// Prints: 'world'
|
||||
```
|
||||
|
||||
Please see the examples below for further information or
|
||||
@ -372,7 +373,8 @@ To test it, run the following JavaScript:
|
||||
const addon = require('./build/Release/addon');
|
||||
|
||||
addon((msg) => {
|
||||
console.log(msg); // 'hello world'
|
||||
console.log(msg);
|
||||
// Prints: 'hello world'
|
||||
});
|
||||
```
|
||||
|
||||
@ -423,7 +425,8 @@ const addon = require('./build/Release/addon');
|
||||
|
||||
var obj1 = addon('hello');
|
||||
var obj2 = addon('world');
|
||||
console.log(obj1.msg, obj2.msg); // 'hello world'
|
||||
console.log(obj1.msg, obj2.msg);
|
||||
// Prints: 'hello world'
|
||||
```
|
||||
|
||||
|
||||
@ -480,7 +483,8 @@ To test:
|
||||
const addon = require('./build/Release/addon');
|
||||
|
||||
var fn = addon();
|
||||
console.log(fn()); // 'hello world'
|
||||
console.log(fn());
|
||||
// Prints: 'hello world'
|
||||
```
|
||||
|
||||
|
||||
@ -642,9 +646,12 @@ Test it with:
|
||||
const addon = require('./build/Release/addon');
|
||||
|
||||
var obj = new addon.MyObject(10);
|
||||
console.log(obj.plusOne()); // 11
|
||||
console.log(obj.plusOne()); // 12
|
||||
console.log(obj.plusOne()); // 13
|
||||
console.log(obj.plusOne());
|
||||
// Prints: 11
|
||||
console.log(obj.plusOne());
|
||||
// Prints: 12
|
||||
console.log(obj.plusOne());
|
||||
// Prints: 13
|
||||
```
|
||||
|
||||
### Factory of wrapped objects
|
||||
@ -834,14 +841,20 @@ Test it with:
|
||||
const createObject = require('./build/Release/addon');
|
||||
|
||||
var obj = createObject(10);
|
||||
console.log(obj.plusOne()); // 11
|
||||
console.log(obj.plusOne()); // 12
|
||||
console.log(obj.plusOne()); // 13
|
||||
console.log(obj.plusOne());
|
||||
// Prints: 11
|
||||
console.log(obj.plusOne());
|
||||
// Prints: 12
|
||||
console.log(obj.plusOne());
|
||||
// Prints: 13
|
||||
|
||||
var obj2 = createObject(20);
|
||||
console.log(obj2.plusOne()); // 21
|
||||
console.log(obj2.plusOne()); // 22
|
||||
console.log(obj2.plusOne()); // 23
|
||||
console.log(obj2.plusOne());
|
||||
// Prints: 21
|
||||
console.log(obj2.plusOne());
|
||||
// Prints: 22
|
||||
console.log(obj2.plusOne());
|
||||
// Prints: 23
|
||||
```
|
||||
|
||||
|
||||
@ -1013,7 +1026,8 @@ var obj1 = addon.createObject(10);
|
||||
var obj2 = addon.createObject(20);
|
||||
var result = addon.add(obj1, obj2);
|
||||
|
||||
console.log(result); // 30
|
||||
console.log(result);
|
||||
// Prints: 30
|
||||
```
|
||||
|
||||
### AtExit hooks
|
||||
|
@ -22,8 +22,10 @@ An alias of [`assert.ok()`][] .
|
||||
```js
|
||||
const assert = require('assert');
|
||||
|
||||
assert(true); // OK
|
||||
assert(1); // OK
|
||||
assert(true);
|
||||
// OK
|
||||
assert(1);
|
||||
// OK
|
||||
assert(false);
|
||||
// throws "AssertionError: false == true"
|
||||
assert(0);
|
||||
@ -228,10 +230,14 @@ argument in callbacks.
|
||||
```js
|
||||
const assert = require('assert');
|
||||
|
||||
assert.ifError(0); // OK
|
||||
assert.ifError(1); // Throws 1
|
||||
assert.ifError('error'); // Throws 'error'
|
||||
assert.ifError(new Error()); // Throws Error
|
||||
assert.ifError(0);
|
||||
// OK
|
||||
assert.ifError(1);
|
||||
// Throws 1
|
||||
assert.ifError('error');
|
||||
// Throws 'error'
|
||||
assert.ifError(new Error());
|
||||
// Throws Error
|
||||
```
|
||||
|
||||
## assert.notDeepEqual(actual, expected[, message])
|
||||
@ -271,7 +277,7 @@ assert.notDeepEqual(obj1, obj3);
|
||||
// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }
|
||||
|
||||
assert.notDeepEqual(obj1, obj4);
|
||||
// OK, obj1 and obj4 are not deeply equal
|
||||
// OK, obj1 and obj2 are not deeply equal
|
||||
```
|
||||
|
||||
If the values are deeply equal, an `AssertionError` is thrown with a `message`
|
||||
@ -364,8 +370,10 @@ parameter is `undefined`, a default error message is assigned.
|
||||
```js
|
||||
const assert = require('assert');
|
||||
|
||||
assert.ok(true); // OK
|
||||
assert.ok(1); // OK
|
||||
assert.ok(true);
|
||||
// OK
|
||||
assert.ok(1);
|
||||
// OK
|
||||
assert.ok(false);
|
||||
// throws "AssertionError: false == true"
|
||||
assert.ok(0);
|
||||
|
@ -406,7 +406,7 @@ Example:
|
||||
```js
|
||||
const buf = new Buffer(5);
|
||||
|
||||
// Prints (contents may vary): <Buffer 78 e0 82 02 01>
|
||||
// Prints: (contents may vary): <Buffer 78 e0 82 02 01>
|
||||
console.log(buf);
|
||||
|
||||
buf.fill(0);
|
||||
@ -525,7 +525,7 @@ Example:
|
||||
```js
|
||||
const buf = Buffer.allocUnsafe(5);
|
||||
|
||||
// Prints (contents may vary): <Buffer 78 e0 82 02 01>
|
||||
// Prints: (contents may vary): <Buffer 78 e0 82 02 01>
|
||||
console.log(buf);
|
||||
|
||||
buf.fill(0);
|
||||
@ -1755,12 +1755,12 @@ Examples:
|
||||
```js
|
||||
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
|
||||
|
||||
// Prints <Buffer 01 02 03 04 05 06 07 08>
|
||||
// Prints: <Buffer 01 02 03 04 05 06 07 08>
|
||||
console.log(buf1);
|
||||
|
||||
buf1.swap32();
|
||||
|
||||
// Prints <Buffer 04 03 02 01 08 07 06 05>
|
||||
// Prints: <Buffer 04 03 02 01 08 07 06 05>
|
||||
console.log(buf1);
|
||||
|
||||
|
||||
@ -1785,12 +1785,12 @@ Examples:
|
||||
```js
|
||||
const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
|
||||
|
||||
// Prints <Buffer 01 02 03 04 05 06 07 08>
|
||||
// Prints: <Buffer 01 02 03 04 05 06 07 08>
|
||||
console.log(buf1);
|
||||
|
||||
buf1.swap64();
|
||||
|
||||
// Prints <Buffer 08 07 06 05 04 03 02 01>
|
||||
// Prints: <Buffer 08 07 06 05 04 03 02 01>
|
||||
console.log(buf1);
|
||||
|
||||
|
||||
@ -2327,7 +2327,7 @@ sequence cannot be adequately represented in the target encoding. For instance:
|
||||
```js
|
||||
const newBuf = buffer.transcode(Buffer.from('€'), 'utf8', 'ascii');
|
||||
console.log(newBuf.toString('ascii'));
|
||||
// prints '?'
|
||||
// Prints: '?'
|
||||
```
|
||||
|
||||
Because the Euro (`€`) sign is not representable in US-ASCII, it is replaced
|
||||
@ -2397,7 +2397,7 @@ const SlowBuffer = require('buffer').SlowBuffer;
|
||||
|
||||
const buf = new SlowBuffer(5);
|
||||
|
||||
// Prints (contents may vary): <Buffer 78 e0 82 02 01>
|
||||
// Prints: (contents may vary): <Buffer 78 e0 82 02 01>
|
||||
console.log(buf);
|
||||
|
||||
buf.fill(0);
|
||||
|
@ -73,7 +73,7 @@ const cert = require('crypto').Certificate();
|
||||
const spkac = getSpkacSomehow();
|
||||
const challenge = cert.exportChallenge(spkac);
|
||||
console.log(challenge.toString('utf8'));
|
||||
// Prints the challenge as a UTF8 string
|
||||
// Prints: the challenge as a UTF8 string
|
||||
```
|
||||
|
||||
### certificate.exportPublicKey(spkac)
|
||||
@ -91,7 +91,7 @@ const cert = require('crypto').Certificate();
|
||||
const spkac = getSpkacSomehow();
|
||||
const publicKey = cert.exportPublicKey(spkac);
|
||||
console.log(publicKey);
|
||||
// Prints the public key as <Buffer ...>
|
||||
// Prints: the public key as <Buffer ...>
|
||||
```
|
||||
|
||||
### certificate.verifySpkac(spkac)
|
||||
@ -106,7 +106,7 @@ The `spkac` argument must be a Node.js [`Buffer`][].
|
||||
const cert = require('crypto').Certificate();
|
||||
const spkac = getSpkacSomehow();
|
||||
console.log(cert.verifySpkac(Buffer.from(spkac)));
|
||||
// Prints true or false
|
||||
// Prints: true or false
|
||||
```
|
||||
|
||||
## Class: Cipher
|
||||
@ -839,7 +839,7 @@ sign.end();
|
||||
|
||||
const private_key = getPrivateKeySomehow();
|
||||
console.log(sign.sign(private_key, 'hex'));
|
||||
// Prints the calculated signature
|
||||
// Prints: the calculated signature
|
||||
```
|
||||
|
||||
Example: Using the [`sign.update()`][] and [`sign.sign()`][] methods:
|
||||
@ -852,7 +852,7 @@ sign.update('some data to sign');
|
||||
|
||||
const private_key = getPrivateKeySomehow();
|
||||
console.log(sign.sign(private_key, 'hex'));
|
||||
// Prints the calculated signature
|
||||
// Prints: the calculated signature
|
||||
```
|
||||
|
||||
A `Sign` instance can also be created by just passing in the digest
|
||||
@ -940,7 +940,7 @@ verify.end();
|
||||
const public_key = getPublicKeySomehow();
|
||||
const signature = getSignatureToVerify();
|
||||
console.log(verify.verify(public_key, signature));
|
||||
// Prints true or false
|
||||
// Prints: true or false
|
||||
```
|
||||
|
||||
Example: Using the [`verify.update()`][] and [`verify.verify()`][] methods:
|
||||
@ -954,7 +954,7 @@ verify.update('some data to sign');
|
||||
const public_key = getPublicKeySomehow();
|
||||
const signature = getSignatureToVerify();
|
||||
console.log(verify.verify(public_key, signature));
|
||||
// Prints true or false
|
||||
// Prints: true or false
|
||||
```
|
||||
|
||||
### verifier.update(data[, input_encoding])
|
||||
|
@ -323,7 +323,7 @@ const sym = Symbol('symbol');
|
||||
myEE.on(sym, () => {});
|
||||
|
||||
console.log(myEE.eventNames());
|
||||
// Prints [ 'foo', 'bar', Symbol(symbol) ]
|
||||
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
|
||||
```
|
||||
|
||||
### emitter.getMaxListeners()
|
||||
|
@ -918,7 +918,7 @@ For example, the following program retains only the first four bytes of the file
|
||||
|
||||
```js
|
||||
console.log(fs.readFileSync('temp.txt', 'utf8'));
|
||||
// prints Node.js
|
||||
// Prints: Node.js
|
||||
|
||||
// get the file descriptor of the file to be truncated
|
||||
const fd = fs.openSync('temp.txt', 'r+');
|
||||
@ -928,7 +928,7 @@ fs.ftruncate(fd, 4, (err) => {
|
||||
assert.ifError(err);
|
||||
console.log(fs.readFileSync('temp.txt', 'utf8'));
|
||||
});
|
||||
// prints Node
|
||||
// Prints: Node
|
||||
```
|
||||
|
||||
If the file previously was shorter than `len` bytes, it is extended, and the
|
||||
@ -936,7 +936,7 @@ extended part is filled with null bytes ('\0'). For example,
|
||||
|
||||
```js
|
||||
console.log(fs.readFileSync('temp.txt', 'utf-8'));
|
||||
// prints Node.js
|
||||
// Prints: Node.js
|
||||
|
||||
// get the file descriptor of the file to be truncated
|
||||
const fd = fs.openSync('temp.txt', 'r+');
|
||||
@ -946,7 +946,7 @@ fs.ftruncate(fd, 10, (err) => {
|
||||
assert.ifError(!err);
|
||||
console.log(fs.readFileSync('temp.txt'));
|
||||
});
|
||||
// prints <Buffer 4e 6f 64 65 2e 6a 73 00 00 00>
|
||||
// Prints: <Buffer 4e 6f 64 65 2e 6a 73 00 00 00>
|
||||
// ('Node.js\0\0\0' in UTF8)
|
||||
```
|
||||
|
||||
|
@ -35,7 +35,7 @@ Example: running `node example.js` from `/Users/mjr`
|
||||
|
||||
```js
|
||||
console.log(__dirname);
|
||||
// /Users/mjr
|
||||
// Prints: /Users/mjr
|
||||
```
|
||||
|
||||
`__dirname` isn't actually a global but rather local to each module.
|
||||
@ -68,7 +68,7 @@ Example: running `node example.js` from `/Users/mjr`
|
||||
|
||||
```js
|
||||
console.log(__filename);
|
||||
// /Users/mjr/example.js
|
||||
// Prints: /Users/mjr/example.js
|
||||
```
|
||||
|
||||
`__filename` isn't actually a global but rather local to each module.
|
||||
|
@ -24,14 +24,14 @@ On POSIX:
|
||||
|
||||
```js
|
||||
path.basename('C:\\temp\\myfile.html');
|
||||
// returns 'C:\temp\myfile.html'
|
||||
// Returns: 'C:\temp\myfile.html'
|
||||
```
|
||||
|
||||
On Windows:
|
||||
|
||||
```js
|
||||
path.basename('C:\\temp\\myfile.html');
|
||||
// returns 'myfile.html'
|
||||
// Returns: 'myfile.html'
|
||||
```
|
||||
|
||||
To achieve consistent results when working with Windows file paths on any
|
||||
@ -41,7 +41,7 @@ On POSIX and Windows:
|
||||
|
||||
```js
|
||||
path.win32.basename('C:\\temp\\myfile.html');
|
||||
// returns 'myfile.html'
|
||||
// Returns: 'myfile.html'
|
||||
```
|
||||
|
||||
To achieve consistent results when working with POSIX file paths on any
|
||||
@ -51,7 +51,7 @@ On POSIX and Windows:
|
||||
|
||||
```js
|
||||
path.posix.basename('/tmp/myfile.html');
|
||||
// returns 'myfile.html'
|
||||
// Returns: 'myfile.html'
|
||||
```
|
||||
|
||||
## path.basename(path[, ext])
|
||||
@ -70,10 +70,10 @@ For example:
|
||||
|
||||
```js
|
||||
path.basename('/foo/bar/baz/asdf/quux.html')
|
||||
// returns 'quux.html'
|
||||
// Returns: 'quux.html'
|
||||
|
||||
path.basename('/foo/bar/baz/asdf/quux.html', '.html')
|
||||
// returns 'quux'
|
||||
// Returns: 'quux'
|
||||
```
|
||||
|
||||
A [`TypeError`][] is thrown if `path` is not a string or if `ext` is given
|
||||
@ -95,20 +95,20 @@ For example, on POSIX:
|
||||
|
||||
```js
|
||||
console.log(process.env.PATH)
|
||||
// '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'
|
||||
// Prints: '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'
|
||||
|
||||
process.env.PATH.split(path.delimiter)
|
||||
// returns ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']
|
||||
// Returns: ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']
|
||||
```
|
||||
|
||||
On Windows:
|
||||
|
||||
```js
|
||||
console.log(process.env.PATH)
|
||||
// 'C:\Windows\system32;C:\Windows;C:\Program Files\node\'
|
||||
// Prints: 'C:\Windows\system32;C:\Windows;C:\Program Files\node\'
|
||||
|
||||
process.env.PATH.split(path.delimiter)
|
||||
// returns ['C:\\Windows\\system32', 'C:\\Windows', 'C:\\Program Files\\node\\']
|
||||
// Returns: ['C:\\Windows\\system32', 'C:\\Windows', 'C:\\Program Files\\node\\']
|
||||
```
|
||||
|
||||
## path.dirname(path)
|
||||
@ -126,7 +126,7 @@ For example:
|
||||
|
||||
```js
|
||||
path.dirname('/foo/bar/baz/asdf/quux')
|
||||
// returns '/foo/bar/baz/asdf'
|
||||
// Returns: '/foo/bar/baz/asdf'
|
||||
```
|
||||
|
||||
A [`TypeError`][] is thrown if `path` is not a string.
|
||||
@ -149,19 +149,19 @@ For example:
|
||||
|
||||
```js
|
||||
path.extname('index.html')
|
||||
// returns '.html'
|
||||
// Returns: '.html'
|
||||
|
||||
path.extname('index.coffee.md')
|
||||
// returns '.md'
|
||||
// Returns: '.md'
|
||||
|
||||
path.extname('index.')
|
||||
// returns '.'
|
||||
// Returns: '.'
|
||||
|
||||
path.extname('index')
|
||||
// returns ''
|
||||
// Returns: ''
|
||||
|
||||
path.extname('.index')
|
||||
// returns ''
|
||||
// Returns: ''
|
||||
```
|
||||
|
||||
A [`TypeError`][] is thrown if `path` is not a string.
|
||||
@ -205,7 +205,7 @@ path.format({
|
||||
dir: '/home/user/dir',
|
||||
base: 'file.txt'
|
||||
});
|
||||
// returns '/home/user/dir/file.txt'
|
||||
// Returns: '/home/user/dir/file.txt'
|
||||
|
||||
// `root` will be used if `dir` is not specified.
|
||||
// If only `root` is provided or `dir` is equal to `root` then the
|
||||
@ -214,7 +214,7 @@ path.format({
|
||||
root: '/',
|
||||
base: 'file.txt'
|
||||
});
|
||||
// returns '/file.txt'
|
||||
// Returns: '/file.txt'
|
||||
|
||||
// `name` + `ext` will be used if `base` is not specified.
|
||||
path.format({
|
||||
@ -222,13 +222,13 @@ path.format({
|
||||
name: 'file',
|
||||
ext: '.txt'
|
||||
});
|
||||
// returns '/file.txt'
|
||||
// Returns: '/file.txt'
|
||||
|
||||
// `base` will be returned if `dir` or `root` are not provided.
|
||||
path.format({
|
||||
base: 'file.txt'
|
||||
});
|
||||
// returns 'file.txt'
|
||||
// Returns: 'file.txt'
|
||||
```
|
||||
|
||||
On Windows:
|
||||
@ -241,7 +241,7 @@ path.format({
|
||||
ext : ".txt",
|
||||
name : "file"
|
||||
});
|
||||
// returns 'C:\\path\\dir\\file.txt'
|
||||
// Returns: 'C:\\path\\dir\\file.txt'
|
||||
```
|
||||
|
||||
## path.isAbsolute(path)
|
||||
@ -298,7 +298,7 @@ For example:
|
||||
|
||||
```js
|
||||
path.join('/foo', 'bar', 'baz/asdf', 'quux', '..')
|
||||
// returns '/foo/bar/baz/asdf'
|
||||
// Returns: '/foo/bar/baz/asdf'
|
||||
|
||||
path.join('foo', {}, 'bar')
|
||||
// throws TypeError: Arguments to path.join must be strings
|
||||
@ -328,14 +328,14 @@ For example on POSIX:
|
||||
|
||||
```js
|
||||
path.normalize('/foo/bar//baz/asdf/quux/..')
|
||||
// returns '/foo/bar/baz/asdf'
|
||||
// Returns: '/foo/bar/baz/asdf'
|
||||
```
|
||||
|
||||
On Windows:
|
||||
|
||||
```js
|
||||
path.normalize('C:\\temp\\\\foo\\bar\\..\\');
|
||||
// returns 'C:\\temp\\foo\\'
|
||||
// Returns: 'C:\\temp\\foo\\'
|
||||
```
|
||||
|
||||
A [`TypeError`][] is thrown if `path` is not a string.
|
||||
@ -363,7 +363,7 @@ For example on POSIX:
|
||||
|
||||
```js
|
||||
path.parse('/home/user/dir/file.txt')
|
||||
// returns
|
||||
// Returns:
|
||||
// {
|
||||
// root : "/",
|
||||
// dir : "/home/user/dir",
|
||||
@ -387,7 +387,7 @@ On Windows:
|
||||
|
||||
```js
|
||||
path.parse('C:\\path\\dir\\file.txt')
|
||||
// returns
|
||||
// Returns:
|
||||
// {
|
||||
// root : "C:\\",
|
||||
// dir : "C:\\path\\dir",
|
||||
@ -439,14 +439,14 @@ For example on POSIX:
|
||||
|
||||
```js
|
||||
path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb')
|
||||
// returns '../../impl/bbb'
|
||||
// Returns: '../../impl/bbb'
|
||||
```
|
||||
|
||||
On Windows:
|
||||
|
||||
```js
|
||||
path.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb')
|
||||
// returns '..\\..\\impl\\bbb'
|
||||
// Returns: '..\\..\\impl\\bbb'
|
||||
```
|
||||
|
||||
A [`TypeError`][] is thrown if neither `from` nor `to` is a string.
|
||||
@ -482,10 +482,10 @@ For example:
|
||||
|
||||
```js
|
||||
path.resolve('/foo/bar', './baz')
|
||||
// returns '/foo/bar/baz'
|
||||
// Returns: '/foo/bar/baz'
|
||||
|
||||
path.resolve('/foo/bar', '/tmp/file/')
|
||||
// returns '/tmp/file'
|
||||
// Returns: '/tmp/file'
|
||||
|
||||
path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif')
|
||||
// if the current working directory is /home/myself/node,
|
||||
@ -510,14 +510,14 @@ For example on POSIX:
|
||||
|
||||
```js
|
||||
'foo/bar/baz'.split(path.sep)
|
||||
// returns ['foo', 'bar', 'baz']
|
||||
// Returns: ['foo', 'bar', 'baz']
|
||||
```
|
||||
|
||||
On Windows:
|
||||
|
||||
```js
|
||||
'foo\\bar\\baz'.split(path.sep)
|
||||
// returns ['foo', 'bar', 'baz']
|
||||
// Returns: ['foo', 'bar', 'baz']
|
||||
```
|
||||
|
||||
## path.win32
|
||||
|
118
doc/api/util.md
118
doc/api/util.md
@ -113,7 +113,7 @@ not replaced.
|
||||
|
||||
```js
|
||||
util.format('%s:%s', 'foo');
|
||||
// Returns 'foo:%s'
|
||||
// Returns: 'foo:%s'
|
||||
```
|
||||
|
||||
If there are more arguments passed to the `util.format()` method than the
|
||||
@ -310,7 +310,7 @@ class Box {
|
||||
const box = new Box(true);
|
||||
|
||||
util.inspect(box);
|
||||
// "Box< true >"
|
||||
// Returns: "Box< true >"
|
||||
```
|
||||
|
||||
Custom `[util.inspect.custom](depth, opts)` functions typically return a string
|
||||
@ -326,7 +326,7 @@ obj[util.inspect.custom] = function(depth) {
|
||||
};
|
||||
|
||||
util.inspect(obj);
|
||||
// "{ bar: 'baz' }"
|
||||
// Returns: "{ bar: 'baz' }"
|
||||
```
|
||||
|
||||
A custom inspection method can alternatively be provided by exposing
|
||||
@ -341,7 +341,7 @@ obj.inspect = function(depth) {
|
||||
};
|
||||
|
||||
util.inspect(obj);
|
||||
// "{ bar: 'baz' }"
|
||||
// Returns: "{ bar: 'baz' }"
|
||||
```
|
||||
|
||||
### util.inspect.defaultOptions
|
||||
@ -419,11 +419,11 @@ Returns `true` if the given `object` is an `Array`. Otherwise, returns `false`.
|
||||
const util = require('util');
|
||||
|
||||
util.isArray([]);
|
||||
// true
|
||||
// Returns: true
|
||||
util.isArray(new Array);
|
||||
// true
|
||||
// Returns: true
|
||||
util.isArray({});
|
||||
// false
|
||||
// Returns: false
|
||||
```
|
||||
|
||||
### util.isBoolean(object)
|
||||
@ -442,11 +442,11 @@ Returns `true` if the given `object` is a `Boolean`. Otherwise, returns `false`.
|
||||
const util = require('util');
|
||||
|
||||
util.isBoolean(1);
|
||||
// false
|
||||
// Returns: false
|
||||
util.isBoolean(0);
|
||||
// false
|
||||
// Returns: false
|
||||
util.isBoolean(false);
|
||||
// true
|
||||
// Returns: true
|
||||
```
|
||||
|
||||
### util.isBuffer(object)
|
||||
@ -465,11 +465,11 @@ Returns `true` if the given `object` is a `Buffer`. Otherwise, returns `false`.
|
||||
const util = require('util');
|
||||
|
||||
util.isBuffer({ length: 0 });
|
||||
// false
|
||||
// Returns: false
|
||||
util.isBuffer([]);
|
||||
// false
|
||||
// Returns: false
|
||||
util.isBuffer(Buffer.from('hello world'));
|
||||
// true
|
||||
// Returns: true
|
||||
```
|
||||
|
||||
### util.isDate(object)
|
||||
@ -488,11 +488,11 @@ Returns `true` if the given `object` is a `Date`. Otherwise, returns `false`.
|
||||
const util = require('util');
|
||||
|
||||
util.isDate(new Date());
|
||||
// true
|
||||
// Returns: true
|
||||
util.isDate(Date());
|
||||
// false (without 'new' returns a String)
|
||||
util.isDate({});
|
||||
// false
|
||||
// Returns: false
|
||||
```
|
||||
|
||||
### util.isError(object)
|
||||
@ -512,11 +512,11 @@ Returns `true` if the given `object` is an [`Error`][]. Otherwise, returns
|
||||
const util = require('util');
|
||||
|
||||
util.isError(new Error());
|
||||
// true
|
||||
// Returns: true
|
||||
util.isError(new TypeError());
|
||||
// true
|
||||
// Returns: true
|
||||
util.isError({ name: 'Error', message: 'an error occurred' });
|
||||
// false
|
||||
// Returns: false
|
||||
```
|
||||
|
||||
Note that this method relies on `Object.prototype.toString()` behavior. It is
|
||||
@ -528,10 +528,10 @@ const util = require('util');
|
||||
const obj = { name: 'Error', message: 'an error occurred' };
|
||||
|
||||
util.isError(obj);
|
||||
// false
|
||||
// Returns: false
|
||||
obj[Symbol.toStringTag] = 'Error';
|
||||
util.isError(obj);
|
||||
// true
|
||||
// Returns: true
|
||||
```
|
||||
|
||||
### util.isFunction(object)
|
||||
@ -554,11 +554,11 @@ function Foo() {}
|
||||
const Bar = function() {};
|
||||
|
||||
util.isFunction({});
|
||||
// false
|
||||
// Returns: false
|
||||
util.isFunction(Foo);
|
||||
// true
|
||||
// Returns: true
|
||||
util.isFunction(Bar);
|
||||
// true
|
||||
// Returns: true
|
||||
```
|
||||
|
||||
### util.isNull(object)
|
||||
@ -578,11 +578,11 @@ Returns `true` if the given `object` is strictly `null`. Otherwise, returns
|
||||
const util = require('util');
|
||||
|
||||
util.isNull(0);
|
||||
// false
|
||||
// Returns: false
|
||||
util.isNull(undefined);
|
||||
// false
|
||||
// Returns: false
|
||||
util.isNull(null);
|
||||
// true
|
||||
// Returns: true
|
||||
```
|
||||
|
||||
### util.isNullOrUndefined(object)
|
||||
@ -602,11 +602,11 @@ returns `false`.
|
||||
const util = require('util');
|
||||
|
||||
util.isNullOrUndefined(0);
|
||||
// false
|
||||
// Returns: false
|
||||
util.isNullOrUndefined(undefined);
|
||||
// true
|
||||
// Returns: true
|
||||
util.isNullOrUndefined(null);
|
||||
// true
|
||||
// Returns: true
|
||||
```
|
||||
|
||||
### util.isNumber(object)
|
||||
@ -625,13 +625,13 @@ Returns `true` if the given `object` is a `Number`. Otherwise, returns `false`.
|
||||
const util = require('util');
|
||||
|
||||
util.isNumber(false);
|
||||
// false
|
||||
// Returns: false
|
||||
util.isNumber(Infinity);
|
||||
// true
|
||||
// Returns: true
|
||||
util.isNumber(0);
|
||||
// true
|
||||
// Returns: true
|
||||
util.isNumber(NaN);
|
||||
// true
|
||||
// Returns: true
|
||||
```
|
||||
|
||||
### util.isObject(object)
|
||||
@ -651,13 +651,13 @@ Returns `true` if the given `object` is strictly an `Object` **and** not a
|
||||
const util = require('util');
|
||||
|
||||
util.isObject(5);
|
||||
// false
|
||||
// Returns: false
|
||||
util.isObject(null);
|
||||
// false
|
||||
// Returns: false
|
||||
util.isObject({});
|
||||
// true
|
||||
// Returns: true
|
||||
util.isObject(function(){});
|
||||
// false
|
||||
// Returns: false
|
||||
```
|
||||
|
||||
### util.isPrimitive(object)
|
||||
@ -677,23 +677,23 @@ Returns `true` if the given `object` is a primitive type. Otherwise, returns
|
||||
const util = require('util');
|
||||
|
||||
util.isPrimitive(5);
|
||||
// true
|
||||
// Returns: true
|
||||
util.isPrimitive('foo');
|
||||
// true
|
||||
// Returns: true
|
||||
util.isPrimitive(false);
|
||||
// true
|
||||
// Returns: true
|
||||
util.isPrimitive(null);
|
||||
// true
|
||||
// Returns: true
|
||||
util.isPrimitive(undefined);
|
||||
// true
|
||||
// Returns: true
|
||||
util.isPrimitive({});
|
||||
// false
|
||||
// Returns: false
|
||||
util.isPrimitive(function() {});
|
||||
// false
|
||||
// Returns: false
|
||||
util.isPrimitive(/^$/);
|
||||
// false
|
||||
// Returns: false
|
||||
util.isPrimitive(new Date());
|
||||
// false
|
||||
// Returns: false
|
||||
```
|
||||
|
||||
### util.isRegExp(object)
|
||||
@ -712,11 +712,11 @@ Returns `true` if the given `object` is a `RegExp`. Otherwise, returns `false`.
|
||||
const util = require('util');
|
||||
|
||||
util.isRegExp(/some regexp/);
|
||||
// true
|
||||
// Returns: true
|
||||
util.isRegExp(new RegExp('another regexp'));
|
||||
// true
|
||||
// Returns: true
|
||||
util.isRegExp({});
|
||||
// false
|
||||
// Returns: false
|
||||
```
|
||||
|
||||
### util.isString(object)
|
||||
@ -735,13 +735,13 @@ Returns `true` if the given `object` is a `string`. Otherwise, returns `false`.
|
||||
const util = require('util');
|
||||
|
||||
util.isString('');
|
||||
// true
|
||||
// Returns: true
|
||||
util.isString('foo');
|
||||
// true
|
||||
// Returns: true
|
||||
util.isString(String('foo'));
|
||||
// true
|
||||
// Returns: true
|
||||
util.isString(5);
|
||||
// false
|
||||
// Returns: false
|
||||
```
|
||||
|
||||
### util.isSymbol(object)
|
||||
@ -760,11 +760,11 @@ Returns `true` if the given `object` is a `Symbol`. Otherwise, returns `false`.
|
||||
const util = require('util');
|
||||
|
||||
util.isSymbol(5);
|
||||
// false
|
||||
// Returns: false
|
||||
util.isSymbol('foo');
|
||||
// false
|
||||
// Returns: false
|
||||
util.isSymbol(Symbol('foo'));
|
||||
// true
|
||||
// Returns: true
|
||||
```
|
||||
|
||||
### util.isUndefined(object)
|
||||
@ -784,11 +784,11 @@ const util = require('util');
|
||||
|
||||
const foo = undefined;
|
||||
util.isUndefined(5);
|
||||
// false
|
||||
// Returns: false
|
||||
util.isUndefined(foo);
|
||||
// true
|
||||
// Returns: true
|
||||
util.isUndefined(null);
|
||||
// false
|
||||
// Returns: false
|
||||
```
|
||||
|
||||
### util.log(string)
|
||||
|
Loading…
x
Reference in New Issue
Block a user