doc: remove redundant 'Example:' and similar notes
Some nits were also fixed in passing. PR-URL: https://github.com/nodejs/node/pull/22537 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
b2f0cfa6b0
commit
1a25f9639a
@ -675,7 +675,7 @@ changes:
|
|||||||
Throws `value` if `value` is not `undefined` or `null`. This is useful when
|
Throws `value` if `value` is not `undefined` or `null`. This is useful when
|
||||||
testing the `error` argument in callbacks. The stack trace contains all frames
|
testing the `error` argument in callbacks. The stack trace contains all frames
|
||||||
from the error passed to `ifError()` including the potential new frames for
|
from the error passed to `ifError()` including the potential new frames for
|
||||||
`ifError()` itself. See below for an example.
|
`ifError()` itself.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const assert = require('assert').strict;
|
const assert = require('assert').strict;
|
||||||
|
@ -534,8 +534,6 @@ expensive nature of the [promise introspection API][PromiseHooks] provided by
|
|||||||
V8. This means that programs using promises or `async`/`await` will not get
|
V8. This means that programs using promises or `async`/`await` will not get
|
||||||
correct execution and trigger ids for promise callback contexts by default.
|
correct execution and trigger ids for promise callback contexts by default.
|
||||||
|
|
||||||
Here's an example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const ah = require('async_hooks');
|
const ah = require('async_hooks');
|
||||||
Promise.resolve(1729).then(() => {
|
Promise.resolve(1729).then(() => {
|
||||||
@ -551,7 +549,7 @@ the `triggerAsyncId` value is `0`, which means that we are missing context about
|
|||||||
the resource that caused (triggered) the `then()` callback to be executed.
|
the resource that caused (triggered) the `then()` callback to be executed.
|
||||||
|
|
||||||
Installing async hooks via `async_hooks.createHook` enables promise execution
|
Installing async hooks via `async_hooks.createHook` enables promise execution
|
||||||
tracking. Example:
|
tracking:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const ah = require('async_hooks');
|
const ah = require('async_hooks');
|
||||||
|
@ -642,8 +642,6 @@ pipes between the parent and child. The value is one of the following:
|
|||||||
words, stdin, stdout, and stderr) a pipe is created. For fd 3 and up, the
|
words, stdin, stdout, and stderr) a pipe is created. For fd 3 and up, the
|
||||||
default is `'ignore'`.
|
default is `'ignore'`.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
@ -1060,8 +1058,7 @@ See kill(2) for reference.
|
|||||||
|
|
||||||
Also note: on Linux, child processes of child processes will not be terminated
|
Also note: on Linux, child processes of child processes will not be terminated
|
||||||
when attempting to kill their parent. This is likely to happen when running a
|
when attempting to kill their parent. This is likely to happen when running a
|
||||||
new process in a shell or with use of the `shell` option of `ChildProcess`, such
|
new process in a shell or with use of the `shell` option of `ChildProcess`:
|
||||||
as in this example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -1105,8 +1102,6 @@ added: v0.1.90
|
|||||||
|
|
||||||
Returns the process identifier (PID) of the child process.
|
Returns the process identifier (PID) of the child process.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
const grep = spawn('grep', ['ssh']);
|
const grep = spawn('grep', ['ssh']);
|
||||||
|
@ -765,8 +765,6 @@ Note that:
|
|||||||
* The defaults above apply to the first call only, the defaults for later
|
* The defaults above apply to the first call only, the defaults for later
|
||||||
calls is the current value at the time of `cluster.setupMaster()` is called.
|
calls is the current value at the time of `cluster.setupMaster()` is called.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const cluster = require('cluster');
|
const cluster = require('cluster');
|
||||||
cluster.setupMaster({
|
cluster.setupMaster({
|
||||||
|
@ -1678,8 +1678,6 @@ added: v0.9.3
|
|||||||
* Returns: {string[]} An array with the names of the supported cipher
|
* Returns: {string[]} An array with the names of the supported cipher
|
||||||
algorithms.
|
algorithms.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const ciphers = crypto.getCiphers();
|
const ciphers = crypto.getCiphers();
|
||||||
console.log(ciphers); // ['aes-128-cbc', 'aes-128-ccm', ...]
|
console.log(ciphers); // ['aes-128-cbc', 'aes-128-ccm', ...]
|
||||||
@ -1691,8 +1689,6 @@ added: v2.3.0
|
|||||||
-->
|
-->
|
||||||
* Returns: {string[]} An array with the names of the supported elliptic curves.
|
* Returns: {string[]} An array with the names of the supported elliptic curves.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const curves = crypto.getCurves();
|
const curves = crypto.getCurves();
|
||||||
console.log(curves); // ['Oakley-EC2N-3', 'Oakley-EC2N-4', ...]
|
console.log(curves); // ['Oakley-EC2N-3', 'Oakley-EC2N-4', ...]
|
||||||
@ -1711,7 +1707,7 @@ supported groups are: `'modp1'`, `'modp2'`, `'modp5'` (defined in
|
|||||||
`'modp16'`, `'modp17'`, `'modp18'` (defined in [RFC 3526][]). The
|
`'modp16'`, `'modp17'`, `'modp18'` (defined in [RFC 3526][]). The
|
||||||
returned object mimics the interface of objects created by
|
returned object mimics the interface of objects created by
|
||||||
[`crypto.createDiffieHellman()`][], but will not allow changing
|
[`crypto.createDiffieHellman()`][], but will not allow changing
|
||||||
the keys (with [`diffieHellman.setPublicKey()`][] for example). The
|
the keys (with [`diffieHellman.setPublicKey()`][], for example). The
|
||||||
advantage of using this method is that the parties do not have to
|
advantage of using this method is that the parties do not have to
|
||||||
generate nor exchange a group modulus beforehand, saving both processor
|
generate nor exchange a group modulus beforehand, saving both processor
|
||||||
and communication time.
|
and communication time.
|
||||||
@ -1747,8 +1743,6 @@ added: v0.9.3
|
|||||||
* Returns: {string[]} An array of the names of the supported hash algorithms,
|
* Returns: {string[]} An array of the names of the supported hash algorithms,
|
||||||
such as `'RSA-SHA256'`.
|
such as `'RSA-SHA256'`.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const hashes = crypto.getHashes();
|
const hashes = crypto.getHashes();
|
||||||
console.log(hashes); // ['DSA', 'DSA-SHA', 'DSA-SHA1', ...]
|
console.log(hashes); // ['DSA', 'DSA-SHA', 'DSA-SHA1', ...]
|
||||||
@ -1797,8 +1791,6 @@ but will take a longer amount of time to complete.
|
|||||||
The `salt` should be as unique as possible. It is recommended that a salt is
|
The `salt` should be as unique as possible. It is recommended that a salt is
|
||||||
random and at least 16 bytes long. See [NIST SP 800-132][] for details.
|
random and at least 16 bytes long. See [NIST SP 800-132][] for details.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
crypto.pbkdf2('secret', 'salt', 100000, 64, 'sha512', (err, derivedKey) => {
|
crypto.pbkdf2('secret', 'salt', 100000, 64, 'sha512', (err, derivedKey) => {
|
||||||
@ -1862,8 +1854,6 @@ but will take a longer amount of time to complete.
|
|||||||
The `salt` should be as unique as possible. It is recommended that a salt is
|
The `salt` should be as unique as possible. It is recommended that a salt is
|
||||||
random and at least 16 bytes long. See [NIST SP 800-132][] for details.
|
random and at least 16 bytes long. See [NIST SP 800-132][] for details.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const key = crypto.pbkdf2Sync('secret', 'salt', 100000, 64, 'sha512');
|
const key = crypto.pbkdf2Sync('secret', 'salt', 100000, 64, 'sha512');
|
||||||
|
@ -552,8 +552,7 @@ chained.
|
|||||||
### Change to asynchronous `socket.bind()` behavior
|
### Change to asynchronous `socket.bind()` behavior
|
||||||
|
|
||||||
As of Node.js v0.10, [`dgram.Socket#bind()`][] changed to an asynchronous
|
As of Node.js v0.10, [`dgram.Socket#bind()`][] changed to an asynchronous
|
||||||
execution model. Legacy code that assumes synchronous behavior, as in the
|
execution model. Legacy code would use synchronous behavior:
|
||||||
following example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const s = dgram.createSocket('udp4');
|
const s = dgram.createSocket('udp4');
|
||||||
@ -561,8 +560,8 @@ s.bind(1234);
|
|||||||
s.addMembership('224.0.0.114');
|
s.addMembership('224.0.0.114');
|
||||||
```
|
```
|
||||||
|
|
||||||
Must be changed to pass a callback function to the [`dgram.Socket#bind()`][]
|
Such legacy code would need to be changed to pass a callback function to the
|
||||||
function:
|
[`dgram.Socket#bind()`][] function:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const s = dgram.createSocket('udp4');
|
const s = dgram.createSocket('udp4');
|
||||||
|
@ -311,8 +311,6 @@ The returned function will be a wrapper around the supplied callback
|
|||||||
function. When the returned function is called, any errors that are
|
function. When the returned function is called, any errors that are
|
||||||
thrown will be routed to the domain's `'error'` event.
|
thrown will be routed to the domain's `'error'` event.
|
||||||
|
|
||||||
#### Example
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const d = domain.create();
|
const d = domain.create();
|
||||||
|
|
||||||
@ -370,8 +368,6 @@ objects sent as the first argument to the function.
|
|||||||
In this way, the common `if (err) return callback(err);` pattern can be replaced
|
In this way, the common `if (err) return callback(err);` pattern can be replaced
|
||||||
with a single error handler in a single place.
|
with a single error handler in a single place.
|
||||||
|
|
||||||
#### Example
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const d = domain.create();
|
const d = domain.create();
|
||||||
|
|
||||||
@ -415,8 +411,6 @@ the function.
|
|||||||
|
|
||||||
This is the most basic way to use a domain.
|
This is the most basic way to use a domain.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const domain = require('domain');
|
const domain = require('domain');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
@ -1243,8 +1243,7 @@ type for one of its returned object properties on execution.
|
|||||||
### ERR_INVALID_RETURN_VALUE
|
### ERR_INVALID_RETURN_VALUE
|
||||||
|
|
||||||
Thrown in case a function option does not return an expected value
|
Thrown in case a function option does not return an expected value
|
||||||
type on execution.
|
type on execution, such as when a function is expected to return a promise.
|
||||||
For example when a function is expected to return a promise.
|
|
||||||
|
|
||||||
<a id="ERR_INVALID_SYNC_FORK_INPUT"></a>
|
<a id="ERR_INVALID_SYNC_FORK_INPUT"></a>
|
||||||
### ERR_INVALID_SYNC_FORK_INPUT
|
### ERR_INVALID_SYNC_FORK_INPUT
|
||||||
@ -1258,8 +1257,6 @@ for more information.
|
|||||||
|
|
||||||
A Node.js API function was called with an incompatible `this` value.
|
A Node.js API function was called with an incompatible `this` value.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const urlSearchParams = new URLSearchParams('foo=bar&baz=new');
|
const urlSearchParams = new URLSearchParams('foo=bar&baz=new');
|
||||||
|
|
||||||
@ -1590,7 +1587,6 @@ emitted.
|
|||||||
Prevents an abort if a string decoder was set on the Socket or if the decoder
|
Prevents an abort if a string decoder was set on the Socket or if the decoder
|
||||||
is in `objectMode`.
|
is in `objectMode`.
|
||||||
|
|
||||||
Example
|
|
||||||
```js
|
```js
|
||||||
const Socket = require('net').Socket;
|
const Socket = require('net').Socket;
|
||||||
const instance = new Socket();
|
const instance = new Socket();
|
||||||
|
@ -1044,8 +1044,6 @@ changes:
|
|||||||
Asynchronously append data to a file, creating the file if it does not yet
|
Asynchronously append data to a file, creating the file if it does not yet
|
||||||
exist. `data` can be a string or a [`Buffer`][].
|
exist. `data` can be a string or a [`Buffer`][].
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
fs.appendFile('message.txt', 'data to append', (err) => {
|
fs.appendFile('message.txt', 'data to append', (err) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
@ -1053,7 +1051,7 @@ fs.appendFile('message.txt', 'data to append', (err) => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
If `options` is a string, then it specifies the encoding. Example:
|
If `options` is a string, then it specifies the encoding:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
fs.appendFile('message.txt', 'data to append', 'utf8', callback);
|
fs.appendFile('message.txt', 'data to append', 'utf8', callback);
|
||||||
@ -1097,8 +1095,6 @@ changes:
|
|||||||
Synchronously append data to a file, creating the file if it does not yet
|
Synchronously append data to a file, creating the file if it does not yet
|
||||||
exist. `data` can be a string or a [`Buffer`][].
|
exist. `data` can be a string or a [`Buffer`][].
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
try {
|
try {
|
||||||
fs.appendFileSync('message.txt', 'data to append');
|
fs.appendFileSync('message.txt', 'data to append');
|
||||||
@ -1108,7 +1104,7 @@ try {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If `options` is a string, then it specifies the encoding. Example:
|
If `options` is a string, then it specifies the encoding:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
fs.appendFileSync('message.txt', 'data to append', 'utf8');
|
fs.appendFileSync('message.txt', 'data to append', 'utf8');
|
||||||
@ -1344,8 +1340,6 @@ fallback copy mechanism is used.
|
|||||||
create a copy-on-write reflink. If the platform does not support copy-on-write,
|
create a copy-on-write reflink. If the platform does not support copy-on-write,
|
||||||
then the operation will fail.
|
then the operation will fail.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
@ -1356,8 +1350,7 @@ fs.copyFile('source.txt', 'destination.txt', (err) => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
If the third argument is a number, then it specifies `flags`, as shown in the
|
If the third argument is a number, then it specifies `flags`:
|
||||||
following example.
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@ -1395,8 +1388,6 @@ fallback copy mechanism is used.
|
|||||||
create a copy-on-write reflink. If the platform does not support copy-on-write,
|
create a copy-on-write reflink. If the platform does not support copy-on-write,
|
||||||
then the operation will fail.
|
then the operation will fail.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
@ -1405,8 +1396,7 @@ fs.copyFileSync('source.txt', 'destination.txt');
|
|||||||
console.log('source.txt was copied to destination.txt');
|
console.log('source.txt was copied to destination.txt');
|
||||||
```
|
```
|
||||||
|
|
||||||
If the third argument is a number, then it specifies `flags`, as shown in the
|
If the third argument is a number, then it specifies `flags`:
|
||||||
following example.
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@ -1568,7 +1558,7 @@ deprecated: v1.0.0
|
|||||||
* `exists` {boolean}
|
* `exists` {boolean}
|
||||||
|
|
||||||
Test whether or not the given path exists by checking with the file system.
|
Test whether or not the given path exists by checking with the file system.
|
||||||
Then call the `callback` argument with either true or false. Example:
|
Then call the `callback` argument with either true or false:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
fs.exists('/etc/passwd', (exists) => {
|
fs.exists('/etc/passwd', (exists) => {
|
||||||
@ -1901,7 +1891,7 @@ fs.ftruncate(fd, 4, (err) => {
|
|||||||
```
|
```
|
||||||
|
|
||||||
If the file previously was shorter than `len` bytes, it is extended, and the
|
If the file previously was shorter than `len` bytes, it is extended, and the
|
||||||
extended part is filled with null bytes (`'\0'`). For example,
|
extended part is filled with null bytes (`'\0'`):
|
||||||
|
|
||||||
```js
|
```js
|
||||||
console.log(fs.readFileSync('temp.txt', 'utf8'));
|
console.log(fs.readFileSync('temp.txt', 'utf8'));
|
||||||
@ -2505,7 +2495,7 @@ changes:
|
|||||||
* `err` {Error}
|
* `err` {Error}
|
||||||
* `data` {string|Buffer}
|
* `data` {string|Buffer}
|
||||||
|
|
||||||
Asynchronously reads the entire contents of a file. Example:
|
Asynchronously reads the entire contents of a file.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
fs.readFile('/etc/passwd', (err, data) => {
|
fs.readFile('/etc/passwd', (err, data) => {
|
||||||
@ -2519,7 +2509,7 @@ contents of the file.
|
|||||||
|
|
||||||
If no encoding is specified, then the raw buffer is returned.
|
If no encoding is specified, then the raw buffer is returned.
|
||||||
|
|
||||||
If `options` is a string, then it specifies the encoding. Example:
|
If `options` is a string, then it specifies the encoding:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
fs.readFile('/etc/passwd', 'utf8', callback);
|
fs.readFile('/etc/passwd', 'utf8', callback);
|
||||||
@ -3519,8 +3509,6 @@ Asynchronously writes data to a file, replacing the file if it already exists.
|
|||||||
|
|
||||||
The `encoding` option is ignored if `data` is a buffer.
|
The `encoding` option is ignored if `data` is a buffer.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
const data = new Uint8Array(Buffer.from('Hello Node.js'));
|
||||||
fs.writeFile('message.txt', data, (err) => {
|
fs.writeFile('message.txt', data, (err) => {
|
||||||
@ -3529,7 +3517,7 @@ fs.writeFile('message.txt', data, (err) => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
If `options` is a string, then it specifies the encoding. Example:
|
If `options` is a string, then it specifies the encoding:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
fs.writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
|
fs.writeFile('message.txt', 'Hello Node.js', 'utf8', callback);
|
||||||
@ -3840,7 +3828,7 @@ doTruncate().catch(console.error);
|
|||||||
```
|
```
|
||||||
|
|
||||||
If the file previously was shorter than `len` bytes, it is extended, and the
|
If the file previously was shorter than `len` bytes, it is extended, and the
|
||||||
extended part is filled with null bytes (`'\0'`). For example,
|
extended part is filled with null bytes (`'\0'`):
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@ -4050,8 +4038,6 @@ fallback copy mechanism is used.
|
|||||||
create a copy-on-write reflink. If the platform does not support copy-on-write,
|
create a copy-on-write reflink. If the platform does not support copy-on-write,
|
||||||
then the operation will fail.
|
then the operation will fail.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const fsPromises = require('fs').promises;
|
const fsPromises = require('fs').promises;
|
||||||
|
|
||||||
@ -4061,8 +4047,7 @@ fsPromises.copyFile('source.txt', 'destination.txt')
|
|||||||
.catch(() => console.log('The file could not be copied'));
|
.catch(() => console.log('The file could not be copied'));
|
||||||
```
|
```
|
||||||
|
|
||||||
If the third argument is a number, then it specifies `flags`, as shown in the
|
If the third argument is a number, then it specifies `flags`:
|
||||||
following example.
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
@ -602,7 +602,6 @@ Reads out a header on the request. Note that the name is case insensitive.
|
|||||||
The type of the return value depends on the arguments provided to
|
The type of the return value depends on the arguments provided to
|
||||||
[`request.setHeader()`][].
|
[`request.setHeader()`][].
|
||||||
|
|
||||||
Example:
|
|
||||||
```js
|
```js
|
||||||
request.setHeader('content-type', 'text/html');
|
request.setHeader('content-type', 'text/html');
|
||||||
request.setHeader('Content-Length', Buffer.byteLength(body));
|
request.setHeader('Content-Length', Buffer.byteLength(body));
|
||||||
@ -630,7 +629,6 @@ added: v1.6.0
|
|||||||
|
|
||||||
Removes a header that's already defined into headers object.
|
Removes a header that's already defined into headers object.
|
||||||
|
|
||||||
Example:
|
|
||||||
```js
|
```js
|
||||||
request.removeHeader('Content-Type');
|
request.removeHeader('Content-Type');
|
||||||
```
|
```
|
||||||
@ -650,7 +648,6 @@ stored without modification. Therefore, [`request.getHeader()`][] may return
|
|||||||
non-string values. However, the non-string values will be converted to strings
|
non-string values. However, the non-string values will be converted to strings
|
||||||
for network transmission.
|
for network transmission.
|
||||||
|
|
||||||
Example:
|
|
||||||
```js
|
```js
|
||||||
request.setHeader('Content-Type', 'application/json');
|
request.setHeader('Content-Type', 'application/json');
|
||||||
```
|
```
|
||||||
@ -707,8 +704,6 @@ this property. In particular, the socket will not emit `'readable'` events
|
|||||||
because of how the protocol parser attaches to the socket. The `socket`
|
because of how the protocol parser attaches to the socket. The `socket`
|
||||||
may also be accessed via `request.connection`.
|
may also be accessed via `request.connection`.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const options = {
|
const options = {
|
||||||
@ -1119,8 +1114,6 @@ Reads out a header that's already been queued but not sent to the client.
|
|||||||
Note that the name is case insensitive. The type of the return value depends
|
Note that the name is case insensitive. The type of the return value depends
|
||||||
on the arguments provided to [`response.setHeader()`][].
|
on the arguments provided to [`response.setHeader()`][].
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
response.setHeader('Content-Type', 'text/html');
|
response.setHeader('Content-Type', 'text/html');
|
||||||
response.setHeader('Content-Length', Buffer.byteLength(body));
|
response.setHeader('Content-Length', Buffer.byteLength(body));
|
||||||
@ -1143,8 +1136,6 @@ added: v7.7.0
|
|||||||
Returns an array containing the unique names of the current outgoing headers.
|
Returns an array containing the unique names of the current outgoing headers.
|
||||||
All header names are lowercase.
|
All header names are lowercase.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
response.setHeader('Foo', 'bar');
|
response.setHeader('Foo', 'bar');
|
||||||
response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
||||||
@ -1171,8 +1162,6 @@ prototypically inherit from the JavaScript `Object`. This means that typical
|
|||||||
`Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others
|
`Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others
|
||||||
are not defined and *will not work*.
|
are not defined and *will not work*.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
response.setHeader('Foo', 'bar');
|
response.setHeader('Foo', 'bar');
|
||||||
response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
||||||
@ -1192,8 +1181,6 @@ added: v7.7.0
|
|||||||
Returns `true` if the header identified by `name` is currently set in the
|
Returns `true` if the header identified by `name` is currently set in the
|
||||||
outgoing headers. Note that the header name matching is case-insensitive.
|
outgoing headers. Note that the header name matching is case-insensitive.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const hasContentType = response.hasHeader('content-type');
|
const hasContentType = response.hasHeader('content-type');
|
||||||
```
|
```
|
||||||
@ -1216,8 +1203,6 @@ added: v0.4.0
|
|||||||
|
|
||||||
Removes a header that's queued for implicit sending.
|
Removes a header that's queued for implicit sending.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
response.removeHeader('Content-Encoding');
|
response.removeHeader('Content-Encoding');
|
||||||
```
|
```
|
||||||
@ -1250,8 +1235,6 @@ stored without modification. Therefore, [`response.getHeader()`][] may return
|
|||||||
non-string values. However, the non-string values will be converted to strings
|
non-string values. However, the non-string values will be converted to strings
|
||||||
for network transmission.
|
for network transmission.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
response.setHeader('Content-Type', 'text/html');
|
response.setHeader('Content-Type', 'text/html');
|
||||||
```
|
```
|
||||||
@ -1317,8 +1300,6 @@ because of how the protocol parser attaches to the socket. After
|
|||||||
`response.end()`, the property is nulled. The `socket` may also be accessed
|
`response.end()`, the property is nulled. The `socket` may also be accessed
|
||||||
via `response.connection`.
|
via `response.connection`.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
@ -1339,8 +1320,6 @@ When using implicit headers (not calling [`response.writeHead()`][] explicitly),
|
|||||||
this property controls the status code that will be sent to the client when
|
this property controls the status code that will be sent to the client when
|
||||||
the headers get flushed.
|
the headers get flushed.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
response.statusCode = 404;
|
response.statusCode = 404;
|
||||||
```
|
```
|
||||||
@ -1360,8 +1339,6 @@ this property controls the status message that will be sent to the client when
|
|||||||
the headers get flushed. If this is left as `undefined` then the standard
|
the headers get flushed. If this is left as `undefined` then the standard
|
||||||
message for the status code will be used.
|
message for the status code will be used.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
response.statusMessage = 'Not found';
|
response.statusMessage = 'Not found';
|
||||||
```
|
```
|
||||||
@ -1434,8 +1411,6 @@ status code, like `404`. The last argument, `headers`, are the response headers.
|
|||||||
Optionally one can give a human-readable `statusMessage` as the second
|
Optionally one can give a human-readable `statusMessage` as the second
|
||||||
argument.
|
argument.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const body = 'hello world';
|
const body = 'hello world';
|
||||||
response.writeHead(200, {
|
response.writeHead(200, {
|
||||||
@ -1546,7 +1521,6 @@ added: v0.1.5
|
|||||||
The request/response headers object.
|
The request/response headers object.
|
||||||
|
|
||||||
Key-value pairs of header names and values. Header names are lower-cased.
|
Key-value pairs of header names and values. Header names are lower-cased.
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Prints something like:
|
// Prints something like:
|
||||||
@ -1590,8 +1564,7 @@ added: v0.1.1
|
|||||||
|
|
||||||
**Only valid for request obtained from [`http.Server`][].**
|
**Only valid for request obtained from [`http.Server`][].**
|
||||||
|
|
||||||
The request method as a string. Read only. Example:
|
The request method as a string. Read only. Examples: `'GET'`, `'DELETE'`.
|
||||||
`'GET'`, `'DELETE'`.
|
|
||||||
|
|
||||||
### message.rawHeaders
|
### message.rawHeaders
|
||||||
<!-- YAML
|
<!-- YAML
|
||||||
@ -1713,7 +1686,7 @@ Then `request.url` will be:
|
|||||||
```
|
```
|
||||||
|
|
||||||
To parse the url into its parts `require('url').parse(request.url)`
|
To parse the url into its parts `require('url').parse(request.url)`
|
||||||
can be used. Example:
|
can be used:
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
$ node
|
$ node
|
||||||
@ -1735,8 +1708,7 @@ Url {
|
|||||||
|
|
||||||
To extract the parameters from the query string, the
|
To extract the parameters from the query string, the
|
||||||
`require('querystring').parse` function can be used, or
|
`require('querystring').parse` function can be used, or
|
||||||
`true` can be passed as the second argument to `require('url').parse`.
|
`true` can be passed as the second argument to `require('url').parse`:
|
||||||
Example:
|
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
$ node
|
$ node
|
||||||
@ -1829,7 +1801,7 @@ data for reasons stated in [`http.ClientRequest`][] section.
|
|||||||
The `callback` is invoked with a single argument that is an instance of
|
The `callback` is invoked with a single argument that is an instance of
|
||||||
[`http.IncomingMessage`][].
|
[`http.IncomingMessage`][].
|
||||||
|
|
||||||
JSON Fetching Example:
|
JSON fetching example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
http.get('http://nodejs.org/dist/index.json', (res) => {
|
http.get('http://nodejs.org/dist/index.json', (res) => {
|
||||||
@ -1947,8 +1919,6 @@ the [`'response'`][] event.
|
|||||||
class. The `ClientRequest` instance is a writable stream. If one needs to
|
class. The `ClientRequest` instance is a writable stream. If one needs to
|
||||||
upload a file with a POST request, then write to the `ClientRequest` object.
|
upload a file with a POST request, then write to the `ClientRequest` object.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const postData = querystring.stringify({
|
const postData = querystring.stringify({
|
||||||
'msg': 'Hello World!'
|
'msg': 'Hello World!'
|
||||||
|
@ -2493,7 +2493,6 @@ added: v8.4.0
|
|||||||
The request/response headers object.
|
The request/response headers object.
|
||||||
|
|
||||||
Key-value pairs of header names and values. Header names are lower-cased.
|
Key-value pairs of header names and values. Header names are lower-cased.
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Prints something like:
|
// Prints something like:
|
||||||
@ -2538,8 +2537,7 @@ added: v8.4.0
|
|||||||
|
|
||||||
* {string}
|
* {string}
|
||||||
|
|
||||||
The request method as a string. Read-only. Example:
|
The request method as a string. Read-only. Examples: `'GET'`, `'DELETE'`.
|
||||||
`'GET'`, `'DELETE'`.
|
|
||||||
|
|
||||||
#### request.rawHeaders
|
#### request.rawHeaders
|
||||||
<!-- YAML
|
<!-- YAML
|
||||||
@ -2666,7 +2664,7 @@ Then `request.url` will be:
|
|||||||
```
|
```
|
||||||
|
|
||||||
To parse the url into its parts `require('url').parse(request.url)`
|
To parse the url into its parts `require('url').parse(request.url)`
|
||||||
can be used. Example:
|
can be used:
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
$ node
|
$ node
|
||||||
@ -2689,7 +2687,6 @@ Url {
|
|||||||
To extract the parameters from the query string, the
|
To extract the parameters from the query string, the
|
||||||
`require('querystring').parse` function can be used, or
|
`require('querystring').parse` function can be used, or
|
||||||
`true` can be passed as the second argument to `require('url').parse`.
|
`true` can be passed as the second argument to `require('url').parse`.
|
||||||
Example:
|
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
$ node
|
$ node
|
||||||
@ -2807,8 +2804,6 @@ added: v8.4.0
|
|||||||
Reads out a header that has already been queued but not sent to the client.
|
Reads out a header that has already been queued but not sent to the client.
|
||||||
Note that the name is case insensitive.
|
Note that the name is case insensitive.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const contentType = response.getHeader('content-type');
|
const contentType = response.getHeader('content-type');
|
||||||
```
|
```
|
||||||
@ -2823,8 +2818,6 @@ added: v8.4.0
|
|||||||
Returns an array containing the unique names of the current outgoing headers.
|
Returns an array containing the unique names of the current outgoing headers.
|
||||||
All header names are lowercase.
|
All header names are lowercase.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
response.setHeader('Foo', 'bar');
|
response.setHeader('Foo', 'bar');
|
||||||
response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
||||||
@ -2851,8 +2844,6 @@ prototypically inherit from the JavaScript `Object`. This means that typical
|
|||||||
`Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others
|
`Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others
|
||||||
are not defined and *will not work*.
|
are not defined and *will not work*.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
response.setHeader('Foo', 'bar');
|
response.setHeader('Foo', 'bar');
|
||||||
response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
|
||||||
@ -2872,8 +2863,6 @@ added: v8.4.0
|
|||||||
Returns `true` if the header identified by `name` is currently set in the
|
Returns `true` if the header identified by `name` is currently set in the
|
||||||
outgoing headers. Note that the header name matching is case-insensitive.
|
outgoing headers. Note that the header name matching is case-insensitive.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const hasContentType = response.hasHeader('content-type');
|
const hasContentType = response.hasHeader('content-type');
|
||||||
```
|
```
|
||||||
@ -2896,8 +2885,6 @@ added: v8.4.0
|
|||||||
|
|
||||||
Removes a header that has been queued for implicit sending.
|
Removes a header that has been queued for implicit sending.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
response.removeHeader('Content-Encoding');
|
response.removeHeader('Content-Encoding');
|
||||||
```
|
```
|
||||||
@ -2927,8 +2914,6 @@ Sets a single header value for implicit headers. If this header already exists
|
|||||||
in the to-be-sent headers, its value will be replaced. Use an array of strings
|
in the to-be-sent headers, its value will be replaced. Use an array of strings
|
||||||
here to send multiple headers with the same name.
|
here to send multiple headers with the same name.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
response.setHeader('Content-Type', 'text/html');
|
response.setHeader('Content-Type', 'text/html');
|
||||||
```
|
```
|
||||||
@ -2998,8 +2983,6 @@ more information.
|
|||||||
|
|
||||||
All other interactions will be routed directly to the socket.
|
All other interactions will be routed directly to the socket.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const http2 = require('http2');
|
const http2 = require('http2');
|
||||||
const server = http2.createServer((req, res) => {
|
const server = http2.createServer((req, res) => {
|
||||||
@ -3020,8 +3003,6 @@ When using implicit headers (not calling [`response.writeHead()`][] explicitly),
|
|||||||
this property controls the status code that will be sent to the client when
|
this property controls the status code that will be sent to the client when
|
||||||
the headers get flushed.
|
the headers get flushed.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
response.statusCode = 404;
|
response.statusCode = 404;
|
||||||
```
|
```
|
||||||
@ -3112,8 +3093,6 @@ passed as the second argument. However, because the `statusMessage` has no
|
|||||||
meaning within HTTP/2, the argument will have no effect and a process warning
|
meaning within HTTP/2, the argument will have no effect and a process warning
|
||||||
will be emitted.
|
will be emitted.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const body = 'hello world';
|
const body = 'hello world';
|
||||||
response.writeHead(200, {
|
response.writeHead(200, {
|
||||||
|
@ -76,8 +76,6 @@ added: v0.3.4
|
|||||||
[`tls.createSecureContext()`][] and [`http.createServer()`][].
|
[`tls.createSecureContext()`][] and [`http.createServer()`][].
|
||||||
* `requestListener` {Function} A listener to be added to the `'request'` event.
|
* `requestListener` {Function} A listener to be added to the `'request'` event.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// curl -k https://localhost:8000/
|
// curl -k https://localhost:8000/
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
@ -134,8 +132,6 @@ Like [`http.get()`][] but for HTTPS.
|
|||||||
string, it is automatically parsed with [`new URL()`][]. If it is a [`URL`][]
|
string, it is automatically parsed with [`new URL()`][]. If it is a [`URL`][]
|
||||||
object, it will be automatically converted to an ordinary `options` object.
|
object, it will be automatically converted to an ordinary `options` object.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
|
|
||||||
@ -193,8 +189,6 @@ The following additional `options` from [`tls.connect()`][] are also accepted:
|
|||||||
string, it is automatically parsed with [`new URL()`][]. If it is a [`URL`][]
|
string, it is automatically parsed with [`new URL()`][]. If it is a [`URL`][]
|
||||||
object, it will be automatically converted to an ordinary `options` object.
|
object, it will be automatically converted to an ordinary `options` object.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
|
|
||||||
@ -239,8 +233,6 @@ const req = https.request(options, (res) => {
|
|||||||
|
|
||||||
Alternatively, opt out of connection pooling by not using an [`Agent`][].
|
Alternatively, opt out of connection pooling by not using an [`Agent`][].
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const options = {
|
const options = {
|
||||||
hostname: 'encrypted.google.com',
|
hostname: 'encrypted.google.com',
|
||||||
|
@ -708,7 +708,7 @@ this, assign the desired export object to `module.exports`. Note that assigning
|
|||||||
the desired object to `exports` will simply rebind the local `exports` variable,
|
the desired object to `exports` will simply rebind the local `exports` variable,
|
||||||
which is probably not what is desired.
|
which is probably not what is desired.
|
||||||
|
|
||||||
For example suppose we were making a module called `a.js`:
|
For example, suppose we were making a module called `a.js`:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
|
@ -451,7 +451,7 @@ originalName [code]
|
|||||||
```
|
```
|
||||||
|
|
||||||
where `originalName` is the original name associated with the error
|
where `originalName` is the original name associated with the error
|
||||||
and `code` is the code that was provided. For example if the code
|
and `code` is the code that was provided. For example, if the code
|
||||||
is `'ERR_ERROR_1'` and a `TypeError` is being created the name will be:
|
is `'ERR_ERROR_1'` and a `TypeError` is being created the name will be:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
@ -3478,8 +3478,6 @@ called on a class prototype and a function called on an instance of a class.
|
|||||||
A common pattern used to address this problem is to save a persistent
|
A common pattern used to address this problem is to save a persistent
|
||||||
reference to the class constructor for later `instanceof` checks.
|
reference to the class constructor for later `instanceof` checks.
|
||||||
|
|
||||||
As an example:
|
|
||||||
|
|
||||||
```C
|
```C
|
||||||
napi_value MyClass_constructor = NULL;
|
napi_value MyClass_constructor = NULL;
|
||||||
status = napi_get_reference_value(env, MyClass::es_constructor, &MyClass_constructor);
|
status = napi_get_reference_value(env, MyClass::es_constructor, &MyClass_constructor);
|
||||||
@ -3931,7 +3929,7 @@ invoking the callback. This should be a value previously obtained
|
|||||||
from [`napi_async_init`][].
|
from [`napi_async_init`][].
|
||||||
- `[out] result`: The newly created scope.
|
- `[out] result`: The newly created scope.
|
||||||
|
|
||||||
There are cases (for example resolving promises) where it is
|
There are cases (for example, resolving promises) where it is
|
||||||
necessary to have the equivalent of the scope associated with a callback
|
necessary to have the equivalent of the scope associated with a callback
|
||||||
in place when making certain N-API calls. If there is no other script on
|
in place when making certain N-API calls. If there is no other script on
|
||||||
the stack the [`napi_open_callback_scope`][] and
|
the stack the [`napi_open_callback_scope`][] and
|
||||||
|
@ -124,8 +124,6 @@ as reported by the operating system if listening on an IP socket
|
|||||||
For a server listening on a pipe or UNIX domain socket, the name is returned
|
For a server listening on a pipe or UNIX domain socket, the name is returned
|
||||||
as a string.
|
as a string.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const server = net.createServer((socket) => {
|
const server = net.createServer((socket) => {
|
||||||
socket.end('goodbye\n');
|
socket.end('goodbye\n');
|
||||||
@ -716,8 +714,7 @@ connects on `'192.168.1.1'`, the value of `socket.localAddress` would be
|
|||||||
added: v0.9.6
|
added: v0.9.6
|
||||||
-->
|
-->
|
||||||
|
|
||||||
The numeric representation of the local port. For example,
|
The numeric representation of the local port. For example, `80` or `21`.
|
||||||
`80` or `21`.
|
|
||||||
|
|
||||||
### socket.pause()
|
### socket.pause()
|
||||||
|
|
||||||
@ -758,8 +755,7 @@ The string representation of the remote IP family. `'IPv4'` or `'IPv6'`.
|
|||||||
added: v0.5.10
|
added: v0.5.10
|
||||||
-->
|
-->
|
||||||
|
|
||||||
The numeric representation of the remote port. For example,
|
The numeric representation of the remote port. For example, `80` or `21`.
|
||||||
`80` or `21`.
|
|
||||||
|
|
||||||
### socket.resume()
|
### socket.resume()
|
||||||
|
|
||||||
|
@ -404,8 +404,8 @@ added: v0.3.3
|
|||||||
* Returns: {string}
|
* Returns: {string}
|
||||||
|
|
||||||
The `os.type()` method returns a string identifying the operating system name
|
The `os.type()` method returns a string identifying the operating system name
|
||||||
as returned by [uname(3)][]. For example `'Linux'` on Linux, `'Darwin'` on macOS
|
as returned by [uname(3)][]. For example, `'Linux'` on Linux, `'Darwin'` on
|
||||||
and `'Windows_NT'` on Windows.
|
macOS, and `'Windows_NT'` on Windows.
|
||||||
|
|
||||||
Please see https://en.wikipedia.org/wiki/Uname#Examples for additional
|
Please see https://en.wikipedia.org/wiki/Uname#Examples for additional
|
||||||
information about the output of running [uname(3)][] on various operating
|
information about the output of running [uname(3)][] on various operating
|
||||||
|
@ -58,7 +58,7 @@ path.posix.basename('/tmp/myfile.html');
|
|||||||
|
|
||||||
*Note:* On Windows Node.js follows the concept of per-drive working directory.
|
*Note:* On Windows Node.js follows the concept of per-drive working directory.
|
||||||
This behavior can be observed when using a drive path without a backslash. For
|
This behavior can be observed when using a drive path without a backslash. For
|
||||||
example `path.resolve('c:\\')` can potentially return a different result than
|
example, `path.resolve('c:\\')` can potentially return a different result than
|
||||||
`path.resolve('c:')`. For more information, see
|
`path.resolve('c:')`. For more information, see
|
||||||
[this MSDN page][MSDN-Rel-Path].
|
[this MSDN page][MSDN-Rel-Path].
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ The `path.isAbsolute()` method determines if `path` is an absolute path.
|
|||||||
|
|
||||||
If the given `path` is a zero-length string, `false` will be returned.
|
If the given `path` is a zero-length string, `false` will be returned.
|
||||||
|
|
||||||
For example on POSIX:
|
For example, on POSIX:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
path.isAbsolute('/foo/bar'); // true
|
path.isAbsolute('/foo/bar'); // true
|
||||||
@ -325,7 +325,7 @@ instance of the platform specific path segment separator (`/` on POSIX and
|
|||||||
If the `path` is a zero-length string, `'.'` is returned, representing the
|
If the `path` is a zero-length string, `'.'` is returned, representing the
|
||||||
current working directory.
|
current working directory.
|
||||||
|
|
||||||
For example on POSIX:
|
For example, on POSIX:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
path.normalize('/foo/bar//baz/asdf/quux/..');
|
path.normalize('/foo/bar//baz/asdf/quux/..');
|
||||||
@ -369,7 +369,7 @@ The returned object will have the following properties:
|
|||||||
* `name` {string}
|
* `name` {string}
|
||||||
* `ext` {string}
|
* `ext` {string}
|
||||||
|
|
||||||
For example on POSIX:
|
For example, on POSIX:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
path.parse('/home/user/dir/file.txt');
|
path.parse('/home/user/dir/file.txt');
|
||||||
@ -446,7 +446,7 @@ path (after calling `path.resolve()` on each), a zero-length string is returned.
|
|||||||
If a zero-length string is passed as `from` or `to`, the current working
|
If a zero-length string is passed as `from` or `to`, the current working
|
||||||
directory will be used instead of the zero-length strings.
|
directory will be used instead of the zero-length strings.
|
||||||
|
|
||||||
For example on POSIX:
|
For example, on POSIX:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb');
|
path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb');
|
||||||
@ -515,7 +515,7 @@ Provides the platform-specific path segment separator:
|
|||||||
* `\` on Windows
|
* `\` on Windows
|
||||||
* `/` on POSIX
|
* `/` on POSIX
|
||||||
|
|
||||||
For example on POSIX:
|
For example, on POSIX:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
'foo/bar/baz'.split(path.sep);
|
'foo/bar/baz'.split(path.sep);
|
||||||
|
@ -943,8 +943,6 @@ Assigning a property on `process.env` will implicitly convert the value
|
|||||||
to a string. **This behavior is deprecated.** Future versions of Node.js may
|
to a string. **This behavior is deprecated.** Future versions of Node.js may
|
||||||
throw an error when the value is not a string, number, or boolean.
|
throw an error when the value is not a string, number, or boolean.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
process.env.test = null;
|
process.env.test = null;
|
||||||
console.log(process.env.test);
|
console.log(process.env.test);
|
||||||
@ -956,8 +954,6 @@ console.log(process.env.test);
|
|||||||
|
|
||||||
Use `delete` to delete a property from `process.env`.
|
Use `delete` to delete a property from `process.env`.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
process.env.TEST = 1;
|
process.env.TEST = 1;
|
||||||
delete process.env.TEST;
|
delete process.env.TEST;
|
||||||
@ -967,8 +963,6 @@ console.log(process.env.TEST);
|
|||||||
|
|
||||||
On Windows operating systems, environment variables are case-insensitive.
|
On Windows operating systems, environment variables are case-insensitive.
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
process.env.TEST = 1;
|
process.env.TEST = 1;
|
||||||
console.log(process.env.test);
|
console.log(process.env.test);
|
||||||
@ -1283,7 +1277,7 @@ the group access list, using all groups of which the user is a member. This is
|
|||||||
a privileged operation that requires that the Node.js process either have `root`
|
a privileged operation that requires that the Node.js process either have `root`
|
||||||
access or the `CAP_SETGID` capability.
|
access or the `CAP_SETGID` capability.
|
||||||
|
|
||||||
Note that care must be taken when dropping privileges. Example:
|
Note that care must be taken when dropping privileges:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
console.log(process.getgroups()); // [ 0 ]
|
console.log(process.getgroups()); // [ 0 ]
|
||||||
|
@ -76,8 +76,7 @@ are not defined and *will not work*.
|
|||||||
|
|
||||||
By default, percent-encoded characters within the query string will be assumed
|
By default, percent-encoded characters within the query string will be assumed
|
||||||
to use UTF-8 encoding. If an alternative character encoding is used, then an
|
to use UTF-8 encoding. If an alternative character encoding is used, then an
|
||||||
alternative `decodeURIComponent` option will need to be specified as illustrated
|
alternative `decodeURIComponent` option will need to be specified:
|
||||||
in the following example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Assuming gbkDecodeURIComponent function already exists...
|
// Assuming gbkDecodeURIComponent function already exists...
|
||||||
@ -118,8 +117,7 @@ querystring.stringify({ foo: 'bar', baz: 'qux' }, ';', ':');
|
|||||||
|
|
||||||
By default, characters requiring percent-encoding within the query string will
|
By default, characters requiring percent-encoding within the query string will
|
||||||
be encoded as UTF-8. If an alternative encoding is required, then an alternative
|
be encoded as UTF-8. If an alternative encoding is required, then an alternative
|
||||||
`encodeURIComponent` option will need to be specified as illustrated in the
|
`encodeURIComponent` option will need to be specified:
|
||||||
following example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Assuming gbkEncodeURIComponent function already exists,
|
// Assuming gbkEncodeURIComponent function already exists,
|
||||||
|
@ -510,8 +510,7 @@ rl.on('line', (line) => {
|
|||||||
## Example: Read File Stream Line-by-Line
|
## Example: Read File Stream Line-by-Line
|
||||||
|
|
||||||
A common use case for `readline` is to consume input from a filesystem
|
A common use case for `readline` is to consume input from a filesystem
|
||||||
[Readable][] stream one line at a time, as illustrated in the following
|
[Readable][] stream one line at a time:
|
||||||
example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const readline = require('readline');
|
const readline = require('readline');
|
||||||
|
@ -323,7 +323,7 @@ the default evaluator and the `repl.REPLServer` instance was created with the
|
|||||||
reference to the `context` object as the only argument.
|
reference to the `context` object as the only argument.
|
||||||
|
|
||||||
This can be used primarily to re-initialize REPL context to some pre-defined
|
This can be used primarily to re-initialize REPL context to some pre-defined
|
||||||
state as illustrated in the following simple example:
|
state:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const repl = require('repl');
|
const repl = require('repl');
|
||||||
|
@ -37,14 +37,14 @@ the elements of the API that are required to *implement* new types of streams.
|
|||||||
|
|
||||||
There are four fundamental stream types within Node.js:
|
There are four fundamental stream types within Node.js:
|
||||||
|
|
||||||
* [`Writable`][] - streams to which data can be written (for example
|
* [`Writable`][] - streams to which data can be written (for example,
|
||||||
[`fs.createWriteStream()`][]).
|
[`fs.createWriteStream()`][]).
|
||||||
* [`Readable`][] - streams from which data can be read (for example
|
* [`Readable`][] - streams from which data can be read (for example,
|
||||||
[`fs.createReadStream()`][]).
|
[`fs.createReadStream()`][]).
|
||||||
* [`Duplex`][] - streams that are both `Readable` and `Writable` (for example
|
* [`Duplex`][] - streams that are both `Readable` and `Writable` (for example,
|
||||||
[`net.Socket`][]).
|
[`net.Socket`][]).
|
||||||
* [`Transform`][] - `Duplex` streams that can modify or transform the data as it
|
* [`Transform`][] - `Duplex` streams that can modify or transform the data as it
|
||||||
is written and read (for example [`zlib.createDeflate()`][]).
|
is written and read (for example, [`zlib.createDeflate()`][]).
|
||||||
|
|
||||||
Additionally this module includes the utility functions [pipeline][] and
|
Additionally this module includes the utility functions [pipeline][] and
|
||||||
[finished][].
|
[finished][].
|
||||||
@ -947,8 +947,7 @@ r.pipe(z).pipe(w);
|
|||||||
By default, [`stream.end()`][stream-end] is called on the destination `Writable`
|
By default, [`stream.end()`][stream-end] is called on the destination `Writable`
|
||||||
stream when the source `Readable` stream emits [`'end'`][], so that the
|
stream when the source `Readable` stream emits [`'end'`][], so that the
|
||||||
destination is no longer writable. To disable this default behavior, the `end`
|
destination is no longer writable. To disable this default behavior, the `end`
|
||||||
option can be passed as `false`, causing the destination stream to remain open,
|
option can be passed as `false`, causing the destination stream to remain open:
|
||||||
as illustrated in the following example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
reader.pipe(writer, { end: false });
|
reader.pipe(writer, { end: false });
|
||||||
@ -1048,8 +1047,7 @@ The `readable.resume()` method causes an explicitly paused `Readable` stream to
|
|||||||
resume emitting [`'data'`][] events, switching the stream into flowing mode.
|
resume emitting [`'data'`][] events, switching the stream into flowing mode.
|
||||||
|
|
||||||
The `readable.resume()` method can be used to fully consume the data from a
|
The `readable.resume()` method can be used to fully consume the data from a
|
||||||
stream without actually processing any of that data as illustrated in the
|
stream without actually processing any of that data:
|
||||||
following example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
getReadableStreamSomehow()
|
getReadableStreamSomehow()
|
||||||
@ -1890,7 +1888,7 @@ When the `Readable` is operating in flowing mode, the data added with
|
|||||||
The `readable.push()` method is designed to be as flexible as possible. For
|
The `readable.push()` method is designed to be as flexible as possible. For
|
||||||
example, when wrapping a lower-level source that provides some form of
|
example, when wrapping a lower-level source that provides some form of
|
||||||
pause/resume mechanism, and a data callback, the low-level source can be wrapped
|
pause/resume mechanism, and a data callback, the low-level source can be wrapped
|
||||||
by the custom `Readable` instance as illustrated in the following example:
|
by the custom `Readable` instance:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// source is an object with readStop() and readStart() methods,
|
// source is an object with readStop() and readStart() methods,
|
||||||
|
@ -618,8 +618,6 @@ If the full certificate chain was requested, each certificate will include an
|
|||||||
`issuerCertificate` property containing an object representing its issuer's
|
`issuerCertificate` property containing an object representing its issuer's
|
||||||
certificate.
|
certificate.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```text
|
```text
|
||||||
{ subject:
|
{ subject:
|
||||||
{ C: 'UK',
|
{ C: 'UK',
|
||||||
@ -1245,8 +1243,6 @@ added: v0.10.2
|
|||||||
|
|
||||||
Returns an array with the names of the supported SSL ciphers.
|
Returns an array with the names of the supported SSL ciphers.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
console.log(tls.getCiphers()); // ['AES128-SHA', 'AES256-SHA', ...]
|
console.log(tls.getCiphers()); // ['AES128-SHA', 'AES256-SHA', ...]
|
||||||
```
|
```
|
||||||
|
@ -68,7 +68,7 @@ tab of Chrome.
|
|||||||
The logging file is by default called `node_trace.${rotation}.log`, where
|
The logging file is by default called `node_trace.${rotation}.log`, where
|
||||||
`${rotation}` is an incrementing log-rotation id. The filepath pattern can
|
`${rotation}` is an incrementing log-rotation id. The filepath pattern can
|
||||||
be specified with `--trace-event-file-pattern` that accepts a template
|
be specified with `--trace-event-file-pattern` that accepts a template
|
||||||
string that supports `${rotation}` and `${pid}`. For example:
|
string that supports `${rotation}` and `${pid}`:
|
||||||
|
|
||||||
```txt
|
```txt
|
||||||
node --trace-event-categories v8 --trace-event-file-pattern '${pid}-${rotation}.log' server.js
|
node --trace-event-categories v8 --trace-event-file-pattern '${pid}-${rotation}.log' server.js
|
||||||
|
@ -906,8 +906,6 @@ string serializations of the URL. These are not, however, customizable in
|
|||||||
any way. The `url.format(URL[, options])` method allows for basic customization
|
any way. The `url.format(URL[, options])` method allows for basic customization
|
||||||
of the output.
|
of the output.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const myURL = new URL('https://a:b@你好你好?abc#foo');
|
const myURL = new URL('https://a:b@你好你好?abc#foo');
|
||||||
|
|
||||||
@ -982,7 +980,7 @@ is everything following the `host` (including the `port`) and before the start
|
|||||||
of the `query` or `hash` components, delimited by either the ASCII question
|
of the `query` or `hash` components, delimited by either the ASCII question
|
||||||
mark (`?`) or hash (`#`) characters.
|
mark (`?`) or hash (`#`) characters.
|
||||||
|
|
||||||
For example `'/p/a/t/h'`.
|
For example: `'/p/a/t/h'`.
|
||||||
|
|
||||||
No decoding of the path string is performed.
|
No decoding of the path string is performed.
|
||||||
|
|
||||||
@ -1164,8 +1162,6 @@ changes:
|
|||||||
The `url.resolve()` method resolves a target URL relative to a base URL in a
|
The `url.resolve()` method resolves a target URL relative to a base URL in a
|
||||||
manner similar to that of a Web browser resolving an anchor tag HREF.
|
manner similar to that of a Web browser resolving an anchor tag HREF.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
url.resolve('/one/two/three', 'four'); // '/one/two/four'
|
url.resolve('/one/two/three', 'four'); // '/one/two/four'
|
||||||
@ -1223,7 +1219,7 @@ specific conditions, in addition to all other cases.
|
|||||||
|
|
||||||
When non-ASCII characters appear within a hostname, the hostname is encoded
|
When non-ASCII characters appear within a hostname, the hostname is encoded
|
||||||
using the [Punycode][] algorithm. Note, however, that a hostname *may* contain
|
using the [Punycode][] algorithm. Note, however, that a hostname *may* contain
|
||||||
*both* Punycode encoded and percent-encoded characters. For example:
|
*both* Punycode encoded and percent-encoded characters:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const myURL = new URL('https://%CF%80.com/foo');
|
const myURL = new URL('https://%CF%80.com/foo');
|
||||||
|
@ -948,8 +948,6 @@ Returns `true` if the value is a built-in [`ArrayBuffer`][] or
|
|||||||
See also [`util.types.isArrayBuffer()`][] and
|
See also [`util.types.isArrayBuffer()`][] and
|
||||||
[`util.types.isSharedArrayBuffer()`][].
|
[`util.types.isSharedArrayBuffer()`][].
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isAnyArrayBuffer(new ArrayBuffer()); // Returns true
|
util.types.isAnyArrayBuffer(new ArrayBuffer()); // Returns true
|
||||||
util.types.isAnyArrayBuffer(new SharedArrayBuffer()); // Returns true
|
util.types.isAnyArrayBuffer(new SharedArrayBuffer()); // Returns true
|
||||||
@ -965,8 +963,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is an `arguments` object.
|
Returns `true` if the value is an `arguments` object.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
<!-- eslint-disable prefer-rest-params -->
|
<!-- eslint-disable prefer-rest-params -->
|
||||||
```js
|
```js
|
||||||
function foo() {
|
function foo() {
|
||||||
@ -986,8 +982,6 @@ Returns `true` if the value is a built-in [`ArrayBuffer`][] instance.
|
|||||||
This does *not* include [`SharedArrayBuffer`][] instances. Usually, it is
|
This does *not* include [`SharedArrayBuffer`][] instances. Usually, it is
|
||||||
desirable to test for both; See [`util.types.isAnyArrayBuffer()`][] for that.
|
desirable to test for both; See [`util.types.isAnyArrayBuffer()`][] for that.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isArrayBuffer(new ArrayBuffer()); // Returns true
|
util.types.isArrayBuffer(new ArrayBuffer()); // Returns true
|
||||||
util.types.isArrayBuffer(new SharedArrayBuffer()); // Returns false
|
util.types.isArrayBuffer(new SharedArrayBuffer()); // Returns false
|
||||||
@ -1006,8 +1000,6 @@ Note that this only reports back what the JavaScript engine is seeing;
|
|||||||
in particular, the return value may not match the original source code if
|
in particular, the return value may not match the original source code if
|
||||||
a transpilation tool was used.
|
a transpilation tool was used.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isAsyncFunction(function foo() {}); // Returns false
|
util.types.isAsyncFunction(function foo() {}); // Returns false
|
||||||
util.types.isAsyncFunction(async function foo() {}); // Returns true
|
util.types.isAsyncFunction(async function foo() {}); // Returns true
|
||||||
@ -1023,8 +1015,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a `BigInt64Array` instance.
|
Returns `true` if the value is a `BigInt64Array` instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isBigInt64Array(new BigInt64Array()); // Returns true
|
util.types.isBigInt64Array(new BigInt64Array()); // Returns true
|
||||||
util.types.isBigInt64Array(new BigUint64Array()); // Returns false
|
util.types.isBigInt64Array(new BigUint64Array()); // Returns false
|
||||||
@ -1040,8 +1030,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a `BigUint64Array` instance.
|
Returns `true` if the value is a `BigUint64Array` instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isBigUint64Array(new BigInt64Array()); // Returns false
|
util.types.isBigUint64Array(new BigInt64Array()); // Returns false
|
||||||
util.types.isBigUint64Array(new BigUint64Array()); // Returns true
|
util.types.isBigUint64Array(new BigUint64Array()); // Returns true
|
||||||
@ -1058,8 +1046,6 @@ added: v10.0.0
|
|||||||
Returns `true` if the value is a boolean object, e.g. created
|
Returns `true` if the value is a boolean object, e.g. created
|
||||||
by `new Boolean()`.
|
by `new Boolean()`.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isBooleanObject(false); // Returns false
|
util.types.isBooleanObject(false); // Returns false
|
||||||
util.types.isBooleanObject(true); // Returns false
|
util.types.isBooleanObject(true); // Returns false
|
||||||
@ -1079,8 +1065,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`DataView`][] instance.
|
Returns `true` if the value is a built-in [`DataView`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const ab = new ArrayBuffer(20);
|
const ab = new ArrayBuffer(20);
|
||||||
util.types.isDataView(new DataView(ab)); // Returns true
|
util.types.isDataView(new DataView(ab)); // Returns true
|
||||||
@ -1099,8 +1083,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Date`][] instance.
|
Returns `true` if the value is a built-in [`Date`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isDate(new Date()); // Returns true
|
util.types.isDate(new Date()); // Returns true
|
||||||
```
|
```
|
||||||
@ -1125,8 +1107,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Float32Array`][] instance.
|
Returns `true` if the value is a built-in [`Float32Array`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isFloat32Array(new ArrayBuffer()); // Returns false
|
util.types.isFloat32Array(new ArrayBuffer()); // Returns false
|
||||||
util.types.isFloat32Array(new Float32Array()); // Returns true
|
util.types.isFloat32Array(new Float32Array()); // Returns true
|
||||||
@ -1143,8 +1123,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Float64Array`][] instance.
|
Returns `true` if the value is a built-in [`Float64Array`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isFloat64Array(new ArrayBuffer()); // Returns false
|
util.types.isFloat64Array(new ArrayBuffer()); // Returns false
|
||||||
util.types.isFloat64Array(new Uint8Array()); // Returns false
|
util.types.isFloat64Array(new Uint8Array()); // Returns false
|
||||||
@ -1164,8 +1142,6 @@ Note that this only reports back what the JavaScript engine is seeing;
|
|||||||
in particular, the return value may not match the original source code if
|
in particular, the return value may not match the original source code if
|
||||||
a transpilation tool was used.
|
a transpilation tool was used.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isGeneratorFunction(function foo() {}); // Returns false
|
util.types.isGeneratorFunction(function foo() {}); // Returns false
|
||||||
util.types.isGeneratorFunction(function* foo() {}); // Returns true
|
util.types.isGeneratorFunction(function* foo() {}); // Returns true
|
||||||
@ -1185,8 +1161,6 @@ Note that this only reports back what the JavaScript engine is seeing;
|
|||||||
in particular, the return value may not match the original source code if
|
in particular, the return value may not match the original source code if
|
||||||
a transpilation tool was used.
|
a transpilation tool was used.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
function* foo() {}
|
function* foo() {}
|
||||||
const generator = foo();
|
const generator = foo();
|
||||||
@ -1203,8 +1177,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Int8Array`][] instance.
|
Returns `true` if the value is a built-in [`Int8Array`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isInt8Array(new ArrayBuffer()); // Returns false
|
util.types.isInt8Array(new ArrayBuffer()); // Returns false
|
||||||
util.types.isInt8Array(new Int8Array()); // Returns true
|
util.types.isInt8Array(new Int8Array()); // Returns true
|
||||||
@ -1221,8 +1193,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Int16Array`][] instance.
|
Returns `true` if the value is a built-in [`Int16Array`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isInt16Array(new ArrayBuffer()); // Returns false
|
util.types.isInt16Array(new ArrayBuffer()); // Returns false
|
||||||
util.types.isInt16Array(new Int16Array()); // Returns true
|
util.types.isInt16Array(new Int16Array()); // Returns true
|
||||||
@ -1239,8 +1209,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Int32Array`][] instance.
|
Returns `true` if the value is a built-in [`Int32Array`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isInt32Array(new ArrayBuffer()); // Returns false
|
util.types.isInt32Array(new ArrayBuffer()); // Returns false
|
||||||
util.types.isInt32Array(new Int32Array()); // Returns true
|
util.types.isInt32Array(new Int32Array()); // Returns true
|
||||||
@ -1257,8 +1225,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Map`][] instance.
|
Returns `true` if the value is a built-in [`Map`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isMap(new Map()); // Returns true
|
util.types.isMap(new Map()); // Returns true
|
||||||
```
|
```
|
||||||
@ -1274,8 +1240,6 @@ added: v10.0.0
|
|||||||
Returns `true` if the value is an iterator returned for a built-in
|
Returns `true` if the value is an iterator returned for a built-in
|
||||||
[`Map`][] instance.
|
[`Map`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const map = new Map();
|
const map = new Map();
|
||||||
util.types.isMapIterator(map.keys()); // Returns true
|
util.types.isMapIterator(map.keys()); // Returns true
|
||||||
@ -1294,8 +1258,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is an instance of a [Module Namespace Object][].
|
Returns `true` if the value is an instance of a [Module Namespace Object][].
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
<!-- eslint-skip -->
|
<!-- eslint-skip -->
|
||||||
```js
|
```js
|
||||||
import * as ns from './a.js';
|
import * as ns from './a.js';
|
||||||
@ -1313,8 +1275,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is an instance of a built-in [`Error`][] type.
|
Returns `true` if the value is an instance of a built-in [`Error`][] type.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isNativeError(new Error()); // Returns true
|
util.types.isNativeError(new Error()); // Returns true
|
||||||
util.types.isNativeError(new TypeError()); // Returns true
|
util.types.isNativeError(new TypeError()); // Returns true
|
||||||
@ -1332,8 +1292,6 @@ added: v10.0.0
|
|||||||
Returns `true` if the value is a number object, e.g. created
|
Returns `true` if the value is a number object, e.g. created
|
||||||
by `new Number()`.
|
by `new Number()`.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isNumberObject(0); // Returns false
|
util.types.isNumberObject(0); // Returns false
|
||||||
util.types.isNumberObject(new Number(0)); // Returns true
|
util.types.isNumberObject(new Number(0)); // Returns true
|
||||||
@ -1349,8 +1307,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Promise`][].
|
Returns `true` if the value is a built-in [`Promise`][].
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isPromise(Promise.resolve(42)); // Returns true
|
util.types.isPromise(Promise.resolve(42)); // Returns true
|
||||||
```
|
```
|
||||||
@ -1365,8 +1321,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a [`Proxy`][] instance.
|
Returns `true` if the value is a [`Proxy`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const target = {};
|
const target = {};
|
||||||
const proxy = new Proxy(target, {});
|
const proxy = new Proxy(target, {});
|
||||||
@ -1384,8 +1338,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a regular expression object.
|
Returns `true` if the value is a regular expression object.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isRegExp(/abc/); // Returns true
|
util.types.isRegExp(/abc/); // Returns true
|
||||||
util.types.isRegExp(new RegExp('abc')); // Returns true
|
util.types.isRegExp(new RegExp('abc')); // Returns true
|
||||||
@ -1401,8 +1353,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Set`][] instance.
|
Returns `true` if the value is a built-in [`Set`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isSet(new Set()); // Returns true
|
util.types.isSet(new Set()); // Returns true
|
||||||
```
|
```
|
||||||
@ -1418,8 +1368,6 @@ added: v10.0.0
|
|||||||
Returns `true` if the value is an iterator returned for a built-in
|
Returns `true` if the value is an iterator returned for a built-in
|
||||||
[`Set`][] instance.
|
[`Set`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const set = new Set();
|
const set = new Set();
|
||||||
util.types.isSetIterator(set.keys()); // Returns true
|
util.types.isSetIterator(set.keys()); // Returns true
|
||||||
@ -1440,8 +1388,6 @@ Returns `true` if the value is a built-in [`SharedArrayBuffer`][] instance.
|
|||||||
This does *not* include [`ArrayBuffer`][] instances. Usually, it is
|
This does *not* include [`ArrayBuffer`][] instances. Usually, it is
|
||||||
desirable to test for both; See [`util.types.isAnyArrayBuffer()`][] for that.
|
desirable to test for both; See [`util.types.isAnyArrayBuffer()`][] for that.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isSharedArrayBuffer(new ArrayBuffer()); // Returns false
|
util.types.isSharedArrayBuffer(new ArrayBuffer()); // Returns false
|
||||||
util.types.isSharedArrayBuffer(new SharedArrayBuffer()); // Returns true
|
util.types.isSharedArrayBuffer(new SharedArrayBuffer()); // Returns true
|
||||||
@ -1458,8 +1404,6 @@ added: v10.0.0
|
|||||||
Returns `true` if the value is a string object, e.g. created
|
Returns `true` if the value is a string object, e.g. created
|
||||||
by `new String()`.
|
by `new String()`.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isStringObject('foo'); // Returns false
|
util.types.isStringObject('foo'); // Returns false
|
||||||
util.types.isStringObject(new String('foo')); // Returns true
|
util.types.isStringObject(new String('foo')); // Returns true
|
||||||
@ -1476,8 +1420,6 @@ added: v10.0.0
|
|||||||
Returns `true` if the value is a symbol object, created
|
Returns `true` if the value is a symbol object, created
|
||||||
by calling `Object()` on a `Symbol` primitive.
|
by calling `Object()` on a `Symbol` primitive.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const symbol = Symbol('foo');
|
const symbol = Symbol('foo');
|
||||||
util.types.isSymbolObject(symbol); // Returns false
|
util.types.isSymbolObject(symbol); // Returns false
|
||||||
@ -1494,8 +1436,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`TypedArray`][] instance.
|
Returns `true` if the value is a built-in [`TypedArray`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isTypedArray(new ArrayBuffer()); // Returns false
|
util.types.isTypedArray(new ArrayBuffer()); // Returns false
|
||||||
util.types.isTypedArray(new Uint8Array()); // Returns true
|
util.types.isTypedArray(new Uint8Array()); // Returns true
|
||||||
@ -1514,8 +1454,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Uint8Array`][] instance.
|
Returns `true` if the value is a built-in [`Uint8Array`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isUint8Array(new ArrayBuffer()); // Returns false
|
util.types.isUint8Array(new ArrayBuffer()); // Returns false
|
||||||
util.types.isUint8Array(new Uint8Array()); // Returns true
|
util.types.isUint8Array(new Uint8Array()); // Returns true
|
||||||
@ -1532,8 +1470,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Uint8ClampedArray`][] instance.
|
Returns `true` if the value is a built-in [`Uint8ClampedArray`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isUint8ClampedArray(new ArrayBuffer()); // Returns false
|
util.types.isUint8ClampedArray(new ArrayBuffer()); // Returns false
|
||||||
util.types.isUint8ClampedArray(new Uint8ClampedArray()); // Returns true
|
util.types.isUint8ClampedArray(new Uint8ClampedArray()); // Returns true
|
||||||
@ -1550,8 +1486,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Uint16Array`][] instance.
|
Returns `true` if the value is a built-in [`Uint16Array`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isUint16Array(new ArrayBuffer()); // Returns false
|
util.types.isUint16Array(new ArrayBuffer()); // Returns false
|
||||||
util.types.isUint16Array(new Uint16Array()); // Returns true
|
util.types.isUint16Array(new Uint16Array()); // Returns true
|
||||||
@ -1568,8 +1502,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`Uint32Array`][] instance.
|
Returns `true` if the value is a built-in [`Uint32Array`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isUint32Array(new ArrayBuffer()); // Returns false
|
util.types.isUint32Array(new ArrayBuffer()); // Returns false
|
||||||
util.types.isUint32Array(new Uint32Array()); // Returns true
|
util.types.isUint32Array(new Uint32Array()); // Returns true
|
||||||
@ -1586,8 +1518,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`WeakMap`][] instance.
|
Returns `true` if the value is a built-in [`WeakMap`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isWeakMap(new WeakMap()); // Returns true
|
util.types.isWeakMap(new WeakMap()); // Returns true
|
||||||
```
|
```
|
||||||
@ -1602,8 +1532,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`WeakSet`][] instance.
|
Returns `true` if the value is a built-in [`WeakSet`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
util.types.isWeakSet(new WeakSet()); // Returns true
|
util.types.isWeakSet(new WeakSet()); // Returns true
|
||||||
```
|
```
|
||||||
@ -1618,8 +1546,6 @@ added: v10.0.0
|
|||||||
|
|
||||||
Returns `true` if the value is a built-in [`WebAssembly.Module`][] instance.
|
Returns `true` if the value is a built-in [`WebAssembly.Module`][] instance.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const module = new WebAssembly.Module(wasmBuffer);
|
const module = new WebAssembly.Module(wasmBuffer);
|
||||||
util.types.isWebAssemblyCompiledModule(module); // Returns true
|
util.types.isWebAssemblyCompiledModule(module); // Returns true
|
||||||
|
@ -20,8 +20,6 @@ Workers, unlike child processes or when using the `cluster` module, can also
|
|||||||
share memory efficiently by transferring `ArrayBuffer` instances or sharing
|
share memory efficiently by transferring `ArrayBuffer` instances or sharing
|
||||||
`SharedArrayBuffer` instances between them.
|
`SharedArrayBuffer` instances between them.
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const {
|
const {
|
||||||
Worker, isMainThread, parentPort, workerData
|
Worker, isMainThread, parentPort, workerData
|
||||||
@ -281,8 +279,6 @@ See [`port.postMessage()`][] for more information on how messages are passed,
|
|||||||
and what kind of JavaScript values can be successfully transported through
|
and what kind of JavaScript values can be successfully transported through
|
||||||
the thread barrier.
|
the thread barrier.
|
||||||
|
|
||||||
For example:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const {
|
const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user