diff --git a/doc/api/assert.md b/doc/api/assert.md index 96800217f68074..149c4161ec2bb9 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -675,7 +675,7 @@ changes: 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 from the error passed to `ifError()` including the potential new frames for -`ifError()` itself. See below for an example. +`ifError()` itself. ```js const assert = require('assert').strict; diff --git a/doc/api/async_hooks.md b/doc/api/async_hooks.md index 676e4d8395cb13..c6bb164608ff96 100644 --- a/doc/api/async_hooks.md +++ b/doc/api/async_hooks.md @@ -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 correct execution and trigger ids for promise callback contexts by default. -Here's an example: - ```js const ah = require('async_hooks'); 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. Installing async hooks via `async_hooks.createHook` enables promise execution -tracking. Example: +tracking: ```js const ah = require('async_hooks'); diff --git a/doc/api/child_process.md b/doc/api/child_process.md index d6a79421889a1e..45093d5dd84528 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -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 default is `'ignore'`. -Example: - ```js const { spawn } = require('child_process'); @@ -1045,8 +1043,7 @@ See kill(2) for reference. 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 -new process in a shell or with use of the `shell` option of `ChildProcess`, such -as in this example: +new process in a shell or with use of the `shell` option of `ChildProcess`: ```js 'use strict'; @@ -1090,8 +1087,6 @@ added: v0.1.90 Returns the process identifier (PID) of the child process. -Example: - ```js const { spawn } = require('child_process'); const grep = spawn('grep', ['ssh']); diff --git a/doc/api/cluster.md b/doc/api/cluster.md index c9dc17e994850a..54b470e0f0e3d5 100644 --- a/doc/api/cluster.md +++ b/doc/api/cluster.md @@ -765,8 +765,6 @@ Note that: * 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. -Example: - ```js const cluster = require('cluster'); cluster.setupMaster({ diff --git a/doc/api/crypto.md b/doc/api/crypto.md index f77f4213beb5fb..bf643c9c6b992a 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1678,8 +1678,6 @@ added: v0.9.3 * Returns: {string[]} An array with the names of the supported cipher algorithms. -Example: - ```js const ciphers = crypto.getCiphers(); 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. -Example: - ```js const curves = crypto.getCurves(); 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 returned object mimics the interface of objects created by [`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 generate nor exchange a group modulus beforehand, saving both processor and communication time. @@ -1747,8 +1743,6 @@ added: v0.9.3 * Returns: {string[]} An array of the names of the supported hash algorithms, such as `'RSA-SHA256'`. -Example: - ```js const hashes = crypto.getHashes(); 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 random and at least 16 bytes long. See [NIST SP 800-132][] for details. -Example: - ```js const crypto = require('crypto'); 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 random and at least 16 bytes long. See [NIST SP 800-132][] for details. -Example: - ```js const crypto = require('crypto'); const key = crypto.pbkdf2Sync('secret', 'salt', 100000, 64, 'sha512'); diff --git a/doc/api/dgram.md b/doc/api/dgram.md index 87c7b6c64e2c12..069ec40b4eff37 100644 --- a/doc/api/dgram.md +++ b/doc/api/dgram.md @@ -552,8 +552,7 @@ chained. ### Change to asynchronous `socket.bind()` behavior As of Node.js v0.10, [`dgram.Socket#bind()`][] changed to an asynchronous -execution model. Legacy code that assumes synchronous behavior, as in the -following example: +execution model. Legacy code would use synchronous behavior: ```js const s = dgram.createSocket('udp4'); @@ -561,8 +560,8 @@ s.bind(1234); s.addMembership('224.0.0.114'); ``` -Must be changed to pass a callback function to the [`dgram.Socket#bind()`][] -function: +Such legacy code would need to be changed to pass a callback function to the +[`dgram.Socket#bind()`][] function: ```js const s = dgram.createSocket('udp4'); diff --git a/doc/api/domain.md b/doc/api/domain.md index 8a0f383934bdc1..8227f9eb186212 100644 --- a/doc/api/domain.md +++ b/doc/api/domain.md @@ -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 thrown will be routed to the domain's `'error'` event. -#### Example - ```js 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 with a single error handler in a single place. -#### Example - ```js const d = domain.create(); @@ -415,8 +411,6 @@ the function. This is the most basic way to use a domain. -Example: - ```js const domain = require('domain'); const fs = require('fs'); diff --git a/doc/api/errors.md b/doc/api/errors.md index f34b53e0110598..6dc7d376088150 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1235,8 +1235,7 @@ type for one of its returned object properties on execution. ### ERR_INVALID_RETURN_VALUE Thrown in case a function option does not return an expected value -type on execution. -For example when a function is expected to return a promise. +type on execution, such as when a function is expected to return a promise. ### ERR_INVALID_SYNC_FORK_INPUT @@ -1250,8 +1249,6 @@ for more information. A Node.js API function was called with an incompatible `this` value. -Example: - ```js const urlSearchParams = new URLSearchParams('foo=bar&baz=new'); @@ -1582,7 +1579,6 @@ emitted. Prevents an abort if a string decoder was set on the Socket or if the decoder is in `objectMode`. -Example ```js const Socket = require('net').Socket; const instance = new Socket(); diff --git a/doc/api/fs.md b/doc/api/fs.md index ee5b0a7d9dce38..a9e56d23e8b29a 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -1044,8 +1044,6 @@ changes: Asynchronously append data to a file, creating the file if it does not yet exist. `data` can be a string or a [`Buffer`][]. -Example: - ```js fs.appendFile('message.txt', 'data to append', (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 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 exist. `data` can be a string or a [`Buffer`][]. -Example: - ```js try { 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 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, then the operation will fail. -Example: - ```js 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 -following example. +If the third argument is a number, then it specifies `flags`: ```js 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, then the operation will fail. -Example: - ```js const fs = require('fs'); @@ -1405,8 +1396,7 @@ fs.copyFileSync('source.txt', '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 -following example. +If the third argument is a number, then it specifies `flags`: ```js const fs = require('fs'); @@ -1548,7 +1538,7 @@ deprecated: v1.0.0 * `exists` {boolean} 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 fs.exists('/etc/passwd', (exists) => { @@ -1881,7 +1871,7 @@ fs.ftruncate(fd, 4, (err) => { ``` 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 console.log(fs.readFileSync('temp.txt', 'utf8')); @@ -2485,7 +2475,7 @@ changes: * `err` {Error} * `data` {string|Buffer} -Asynchronously reads the entire contents of a file. Example: +Asynchronously reads the entire contents of a file. ```js fs.readFile('/etc/passwd', (err, data) => { @@ -2499,7 +2489,7 @@ contents of the file. 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 fs.readFile('/etc/passwd', 'utf8', callback); @@ -3499,8 +3489,6 @@ Asynchronously writes data to a file, replacing the file if it already exists. The `encoding` option is ignored if `data` is a buffer. -Example: - ```js const data = new Uint8Array(Buffer.from('Hello Node.js')); fs.writeFile('message.txt', data, (err) => { @@ -3509,7 +3497,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 fs.writeFile('message.txt', 'Hello Node.js', 'utf8', callback); @@ -3820,7 +3808,7 @@ doTruncate().catch(console.error); ``` 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 const fs = require('fs'); @@ -4030,8 +4018,6 @@ fallback copy mechanism is used. create a copy-on-write reflink. If the platform does not support copy-on-write, then the operation will fail. -Example: - ```js const fsPromises = require('fs').promises; @@ -4041,8 +4027,7 @@ fsPromises.copyFile('source.txt', 'destination.txt') .catch(() => console.log('The file could not be copied')); ``` -If the third argument is a number, then it specifies `flags`, as shown in the -following example. +If the third argument is a number, then it specifies `flags`: ```js const fs = require('fs'); diff --git a/doc/api/http.md b/doc/api/http.md index 8251527fc8fda8..9628e5386bbc1e 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -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 [`request.setHeader()`][]. -Example: ```js request.setHeader('content-type', 'text/html'); 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. -Example: ```js 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 for network transmission. -Example: ```js 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` may also be accessed via `request.connection`. -Example: - ```js const http = require('http'); 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 on the arguments provided to [`response.setHeader()`][]. -Example: - ```js response.setHeader('Content-Type', 'text/html'); 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. All header names are lowercase. -Example: - ```js response.setHeader('Foo', 'bar'); 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 are not defined and *will not work*. -Example: - ```js response.setHeader('Foo', 'bar'); 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 outgoing headers. Note that the header name matching is case-insensitive. -Example: - ```js const hasContentType = response.hasHeader('content-type'); ``` @@ -1216,8 +1203,6 @@ added: v0.4.0 Removes a header that's queued for implicit sending. -Example: - ```js 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 for network transmission. -Example: - ```js 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 via `response.connection`. -Example: - ```js const http = require('http'); 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 the headers get flushed. -Example: - ```js 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 message for the status code will be used. -Example: - ```js 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 argument. -Example: - ```js const body = 'hello world'; response.writeHead(200, { @@ -1546,7 +1521,6 @@ added: v0.1.5 The request/response headers object. Key-value pairs of header names and values. Header names are lower-cased. -Example: ```js // Prints something like: @@ -1590,8 +1564,7 @@ added: v0.1.1 **Only valid for request obtained from [`http.Server`][].** -The request method as a string. Read only. Example: -`'GET'`, `'DELETE'`. +The request method as a string. Read only. Examples: `'GET'`, `'DELETE'`. ### message.rawHeaders -The numeric representation of the local port. For example, -`80` or `21`. +The numeric representation of the local port. For example, `80` or `21`. ### socket.pause() @@ -758,8 +755,7 @@ The string representation of the remote IP family. `'IPv4'` or `'IPv6'`. added: v0.5.10 --> -The numeric representation of the remote port. For example, -`80` or `21`. +The numeric representation of the remote port. For example, `80` or `21`. ### socket.resume() diff --git a/doc/api/os.md b/doc/api/os.md index 4557bb6b7d369a..6bd5216273778e 100644 --- a/doc/api/os.md +++ b/doc/api/os.md @@ -404,8 +404,8 @@ added: v0.3.3 * Returns: {string} 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 -and `'Windows_NT'` on Windows. +as returned by [uname(3)][]. For example, `'Linux'` on Linux, `'Darwin'` on +macOS, and `'Windows_NT'` on Windows. Please see https://en.wikipedia.org/wiki/Uname#Examples for additional information about the output of running [uname(3)][] on various operating diff --git a/doc/api/path.md b/doc/api/path.md index 887928dd1a46cb..2a1f06028ee6f4 100644 --- a/doc/api/path.md +++ b/doc/api/path.md @@ -58,7 +58,7 @@ path.posix.basename('/tmp/myfile.html'); *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 -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 [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. -For example on POSIX: +For example, on POSIX: ```js 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 current working directory. -For example on POSIX: +For example, on POSIX: ```js path.normalize('/foo/bar//baz/asdf/quux/..'); @@ -369,7 +369,7 @@ The returned object will have the following properties: * `name` {string} * `ext` {string} -For example on POSIX: +For example, on POSIX: ```js 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 directory will be used instead of the zero-length strings. -For example on POSIX: +For example, on POSIX: ```js path.relative('/data/orandea/test/aaa', '/data/orandea/impl/bbb'); @@ -515,7 +515,7 @@ Provides the platform-specific path segment separator: * `\` on Windows * `/` on POSIX -For example on POSIX: +For example, on POSIX: ```js 'foo/bar/baz'.split(path.sep); diff --git a/doc/api/process.md b/doc/api/process.md index 5aec229e9e8ed9..34f7eb6505a1f0 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -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 throw an error when the value is not a string, number, or boolean. -Example: - ```js process.env.test = null; console.log(process.env.test); @@ -956,8 +954,6 @@ console.log(process.env.test); Use `delete` to delete a property from `process.env`. -Example: - ```js process.env.TEST = 1; delete process.env.TEST; @@ -967,8 +963,6 @@ console.log(process.env.TEST); On Windows operating systems, environment variables are case-insensitive. -Example: - ```js process.env.TEST = 1; 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` 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 console.log(process.getgroups()); // [ 0 ] diff --git a/doc/api/querystring.md b/doc/api/querystring.md index 2fac9bce43da88..60230d916b3243 100644 --- a/doc/api/querystring.md +++ b/doc/api/querystring.md @@ -76,8 +76,7 @@ are not defined and *will not work*. 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 -alternative `decodeURIComponent` option will need to be specified as illustrated -in the following example: +alternative `decodeURIComponent` option will need to be specified: ```js // 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 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 -following example: +`encodeURIComponent` option will need to be specified: ```js // Assuming gbkEncodeURIComponent function already exists, diff --git a/doc/api/readline.md b/doc/api/readline.md index a2a4adf3093a9a..8efc3d6e41662e 100644 --- a/doc/api/readline.md +++ b/doc/api/readline.md @@ -510,8 +510,7 @@ rl.on('line', (line) => { ## Example: Read File Stream Line-by-Line 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 -example: +[Readable][] stream one line at a time: ```js const readline = require('readline'); diff --git a/doc/api/repl.md b/doc/api/repl.md index e66032279e5469..2f7100c7e81392 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -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. This can be used primarily to re-initialize REPL context to some pre-defined -state as illustrated in the following simple example: +state: ```js const repl = require('repl'); diff --git a/doc/api/stream.md b/doc/api/stream.md index 840e85b71606c3..8ebf8efe27ff91 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -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: -* [`Writable`][] - streams to which data can be written (for example +* [`Writable`][] - streams to which data can be written (for example, [`fs.createWriteStream()`][]). -* [`Readable`][] - streams from which data can be read (for example +* [`Readable`][] - streams from which data can be read (for example, [`fs.createReadStream()`][]). -* [`Duplex`][] - streams that are both `Readable` and `Writable` (for example +* [`Duplex`][] - streams that are both `Readable` and `Writable` (for example, [`net.Socket`][]). * [`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 [finished][]. @@ -947,8 +947,7 @@ r.pipe(z).pipe(w); By default, [`stream.end()`][stream-end] is called on the destination `Writable` stream when the source `Readable` stream emits [`'end'`][], so that the 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, -as illustrated in the following example: +option can be passed as `false`, causing the destination stream to remain open: ```js 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. 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 -following example: +stream without actually processing any of that data: ```js 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 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 -by the custom `Readable` instance as illustrated in the following example: +by the custom `Readable` instance: ```js // source is an object with readStop() and readStart() methods, diff --git a/doc/api/tls.md b/doc/api/tls.md index 34f09b052ec56e..9d95d905e70fce 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -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 certificate. -For example: - ```text { subject: { C: 'UK', @@ -1245,8 +1243,6 @@ added: v0.10.2 Returns an array with the names of the supported SSL ciphers. -For example: - ```js console.log(tls.getCiphers()); // ['AES128-SHA', 'AES256-SHA', ...] ``` diff --git a/doc/api/tracing.md b/doc/api/tracing.md index e067760643a1ea..fb855084022a6c 100644 --- a/doc/api/tracing.md +++ b/doc/api/tracing.md @@ -68,7 +68,7 @@ tab of Chrome. The logging file is by default called `node_trace.${rotation}.log`, where `${rotation}` is an incrementing log-rotation id. The filepath pattern can 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 node --trace-event-categories v8 --trace-event-file-pattern '${pid}-${rotation}.log' server.js diff --git a/doc/api/url.md b/doc/api/url.md index 8013b1ffb75462..571c3bdfdbfabb 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -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 of the output. -For example: - ```js 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 mark (`?`) or hash (`#`) characters. -For example `'/p/a/t/h'`. +For example: `'/p/a/t/h'`. 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 manner similar to that of a Web browser resolving an anchor tag HREF. -For example: - ```js const url = require('url'); 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 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 const myURL = new URL('https://%CF%80.com/foo'); diff --git a/doc/api/util.md b/doc/api/util.md index 2fadc6b9ef2ee7..a9340847c52551 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -948,8 +948,6 @@ Returns `true` if the value is a built-in [`ArrayBuffer`][] or See also [`util.types.isArrayBuffer()`][] and [`util.types.isSharedArrayBuffer()`][]. -For example: - ```js util.types.isAnyArrayBuffer(new ArrayBuffer()); // 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. -For example: - ```js 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 desirable to test for both; See [`util.types.isAnyArrayBuffer()`][] for that. -For example: - ```js util.types.isArrayBuffer(new ArrayBuffer()); // Returns true 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 a transpilation tool was used. -For example: - ```js util.types.isAsyncFunction(function foo() {}); // Returns false 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. -For example: - ```js util.types.isBigInt64Array(new BigInt64Array()); // Returns true util.types.isBigInt64Array(new BigUint64Array()); // Returns false @@ -1040,8 +1030,6 @@ added: v10.0.0 Returns `true` if the value is a `BigUint64Array` instance. -For example: - ```js util.types.isBigUint64Array(new BigInt64Array()); // Returns false 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 by `new Boolean()`. -For example: - ```js util.types.isBooleanObject(false); // 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. -For example: - ```js const ab = new ArrayBuffer(20); 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. -For example: - ```js 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. -For example: - ```js util.types.isFloat32Array(new ArrayBuffer()); // Returns false 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. -For example: - ```js util.types.isFloat64Array(new ArrayBuffer()); // 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 a transpilation tool was used. -For example: - ```js util.types.isGeneratorFunction(function foo() {}); // Returns false 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 a transpilation tool was used. -For example: - ```js function* foo() {} const generator = foo(); @@ -1203,8 +1177,6 @@ added: v10.0.0 Returns `true` if the value is a built-in [`Int8Array`][] instance. -For example: - ```js util.types.isInt8Array(new ArrayBuffer()); // Returns false 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. -For example: - ```js util.types.isInt16Array(new ArrayBuffer()); // Returns false 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. -For example: - ```js util.types.isInt32Array(new ArrayBuffer()); // Returns false 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. -For example: - ```js 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 [`Map`][] instance. -For example: - ```js const map = new Map(); 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][]. -For example: - ```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. -For example: - ```js util.types.isNativeError(new Error()); // 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 by `new Number()`. -For example: - ```js util.types.isNumberObject(0); // Returns false 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`][]. -For example: - ```js 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. -For example: - ```js const target = {}; const proxy = new Proxy(target, {}); @@ -1384,8 +1338,6 @@ added: v10.0.0 Returns `true` if the value is a regular expression object. -For example: - ```js util.types.isRegExp(/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. -For example: - ```js 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 [`Set`][] instance. -For example: - ```js const set = new Set(); 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 desirable to test for both; See [`util.types.isAnyArrayBuffer()`][] for that. -For example: - ```js util.types.isSharedArrayBuffer(new ArrayBuffer()); // Returns false 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 by `new String()`. -For example: - ```js util.types.isStringObject('foo'); // Returns false 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 by calling `Object()` on a `Symbol` primitive. -For example: - ```js const symbol = Symbol('foo'); 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. -For example: - ```js util.types.isTypedArray(new ArrayBuffer()); // Returns false 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. -For example: - ```js util.types.isUint8Array(new ArrayBuffer()); // Returns false 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. -For example: - ```js util.types.isUint8ClampedArray(new ArrayBuffer()); // Returns false 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. -For example: - ```js util.types.isUint16Array(new ArrayBuffer()); // Returns false 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. -For example: - ```js util.types.isUint32Array(new ArrayBuffer()); // Returns false 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. -For example: - ```js 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. -For example: - ```js 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. -For example: - ```js const module = new WebAssembly.Module(wasmBuffer); util.types.isWebAssemblyCompiledModule(module); // Returns true diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md index 025a8c9a3ab2cf..b9f28cbfbe411b 100644 --- a/doc/api/worker_threads.md +++ b/doc/api/worker_threads.md @@ -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 `SharedArrayBuffer` instances between them. -## Example - ```js const { 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 the thread barrier. -For example: - ```js const assert = require('assert'); const {