doc: use destructuring in code examples
PR-URL: https://github.com/nodejs/node/pull/13349 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
78b135806f
commit
7de6998d89
@ -2609,7 +2609,7 @@ sensitive data. Use [`buf.fill(0)`][`buf.fill()`] to initialize a `SlowBuffer` t
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const SlowBuffer = require('buffer').SlowBuffer;
|
const { SlowBuffer } = require('buffer');
|
||||||
|
|
||||||
const buf = new SlowBuffer(5);
|
const buf = new SlowBuffer(5);
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ a manner that is similar, but not identical, to popen(3). This capability
|
|||||||
is primarily provided by the [`child_process.spawn()`][] function:
|
is primarily provided by the [`child_process.spawn()`][] function:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const spawn = require('child_process').spawn;
|
const { spawn } = require('child_process');
|
||||||
const ls = spawn('ls', ['-lh', '/usr']);
|
const ls = spawn('ls', ['-lh', '/usr']);
|
||||||
|
|
||||||
ls.stdout.on('data', (data) => {
|
ls.stdout.on('data', (data) => {
|
||||||
@ -87,7 +87,7 @@ spaces it needs to be quoted.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
// On Windows Only ...
|
// On Windows Only ...
|
||||||
const spawn = require('child_process').spawn;
|
const { spawn } = require('child_process');
|
||||||
const bat = spawn('cmd.exe', ['/c', 'my.bat']);
|
const bat = spawn('cmd.exe', ['/c', 'my.bat']);
|
||||||
|
|
||||||
bat.stdout.on('data', (data) => {
|
bat.stdout.on('data', (data) => {
|
||||||
@ -105,7 +105,7 @@ bat.on('exit', (code) => {
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
// OR...
|
// OR...
|
||||||
const exec = require('child_process').exec;
|
const { exec } = require('child_process');
|
||||||
exec('my.bat', (err, stdout, stderr) => {
|
exec('my.bat', (err, stdout, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@ -168,7 +168,7 @@ containing shell metacharacters may be used to trigger arbitrary command
|
|||||||
execution.
|
execution.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const exec = require('child_process').exec;
|
const { exec } = require('child_process');
|
||||||
exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => {
|
exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(`exec error: ${error}`);
|
console.error(`exec error: ${error}`);
|
||||||
@ -264,7 +264,7 @@ The same options as [`child_process.exec()`][] are supported. Since a shell is n
|
|||||||
spawned, behaviors such as I/O redirection and file globbing are not supported.
|
spawned, behaviors such as I/O redirection and file globbing are not supported.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const execFile = require('child_process').execFile;
|
const { execFile } = require('child_process');
|
||||||
const child = execFile('node', ['--version'], (error, stdout, stderr) => {
|
const child = execFile('node', ['--version'], (error, stdout, stderr) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
throw error;
|
throw error;
|
||||||
@ -410,7 +410,7 @@ Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the
|
|||||||
exit code:
|
exit code:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const spawn = require('child_process').spawn;
|
const { spawn } = require('child_process');
|
||||||
const ls = spawn('ls', ['-lh', '/usr']);
|
const ls = spawn('ls', ['-lh', '/usr']);
|
||||||
|
|
||||||
ls.stdout.on('data', (data) => {
|
ls.stdout.on('data', (data) => {
|
||||||
@ -430,7 +430,7 @@ ls.on('close', (code) => {
|
|||||||
Example: A very elaborate way to run `ps ax | grep ssh`
|
Example: A very elaborate way to run `ps ax | grep ssh`
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const spawn = require('child_process').spawn;
|
const { spawn } = require('child_process');
|
||||||
const ps = spawn('ps', ['ax']);
|
const ps = spawn('ps', ['ax']);
|
||||||
const grep = spawn('grep', ['ssh']);
|
const grep = spawn('grep', ['ssh']);
|
||||||
|
|
||||||
@ -468,7 +468,7 @@ grep.on('close', (code) => {
|
|||||||
Example of checking for failed exec:
|
Example of checking for failed exec:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const spawn = require('child_process').spawn;
|
const { spawn } = require('child_process');
|
||||||
const child = spawn('bad_command');
|
const child = spawn('bad_command');
|
||||||
|
|
||||||
child.on('error', (err) => {
|
child.on('error', (err) => {
|
||||||
@ -515,7 +515,7 @@ Example of a long-running process, by detaching and also ignoring its parent
|
|||||||
`stdio` file descriptors, in order to ignore the parent's termination:
|
`stdio` file descriptors, in order to ignore the parent's termination:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const spawn = require('child_process').spawn;
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
const child = spawn(process.argv[0], ['child_program.js'], {
|
const child = spawn(process.argv[0], ['child_program.js'], {
|
||||||
detached: true,
|
detached: true,
|
||||||
@ -529,7 +529,7 @@ Alternatively one can redirect the child process' output into files:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const spawn = require('child_process').spawn;
|
const { spawn } = require('child_process');
|
||||||
const out = fs.openSync('./out.log', 'a');
|
const out = fs.openSync('./out.log', 'a');
|
||||||
const err = fs.openSync('./out.log', 'a');
|
const err = fs.openSync('./out.log', 'a');
|
||||||
|
|
||||||
@ -601,7 +601,7 @@ pipes between the parent and child. The value is one of the following:
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const spawn = require('child_process').spawn;
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
// Child will use parent's stdios
|
// Child will use parent's stdios
|
||||||
spawn('prg', [], { stdio: 'inherit' });
|
spawn('prg', [], { stdio: 'inherit' });
|
||||||
@ -933,7 +933,7 @@ is given, the process will be sent the `'SIGTERM'` signal. See signal(7) for
|
|||||||
a list of available signals.
|
a list of available signals.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const spawn = require('child_process').spawn;
|
const { spawn } = require('child_process');
|
||||||
const grep = spawn('grep', ['ssh']);
|
const grep = spawn('grep', ['ssh']);
|
||||||
|
|
||||||
grep.on('close', (code, signal) => {
|
grep.on('close', (code, signal) => {
|
||||||
@ -963,7 +963,7 @@ as in this example:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
'use strict';
|
'use strict';
|
||||||
const spawn = require('child_process').spawn;
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
const child = spawn(
|
const child = spawn(
|
||||||
'sh',
|
'sh',
|
||||||
@ -994,7 +994,7 @@ Returns the process identifier (PID) of the child process.
|
|||||||
Example:
|
Example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const spawn = require('child_process').spawn;
|
const { spawn } = require('child_process');
|
||||||
const grep = spawn('grep', ['ssh']);
|
const grep = spawn('grep', ['ssh']);
|
||||||
|
|
||||||
console.log(`Spawned child pid: ${grep.pid}`);
|
console.log(`Spawned child pid: ${grep.pid}`);
|
||||||
|
@ -65,14 +65,14 @@ changes:
|
|||||||
|
|
||||||
The `Console` class can be used to create a simple logger with configurable
|
The `Console` class can be used to create a simple logger with configurable
|
||||||
output streams and can be accessed using either `require('console').Console`
|
output streams and can be accessed using either `require('console').Console`
|
||||||
or `console.Console`:
|
or `console.Console` (or their destructured counterparts):
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Console = require('console').Console;
|
const { Console } = require('console');
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Console = console.Console;
|
const { Console } = console;
|
||||||
```
|
```
|
||||||
|
|
||||||
### new Console(stdout[, stderr])
|
### new Console(stdout[, stderr])
|
||||||
|
@ -172,7 +172,7 @@ translation of text from one language to another:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const repl = require('repl');
|
const repl = require('repl');
|
||||||
const Translator = require('translator').Translator;
|
const { Translator } = require('translator');
|
||||||
|
|
||||||
const myTranslator = new Translator('en', 'fr');
|
const myTranslator = new Translator('en', 'fr');
|
||||||
|
|
||||||
|
@ -1023,7 +1023,7 @@ section for more information.
|
|||||||
// Pull off a header delimited by \n\n
|
// Pull off a header delimited by \n\n
|
||||||
// use unshift() if we get too much
|
// use unshift() if we get too much
|
||||||
// Call the callback with (error, header, stream)
|
// Call the callback with (error, header, stream)
|
||||||
const StringDecoder = require('string_decoder').StringDecoder;
|
const { StringDecoder } = require('string_decoder');
|
||||||
function parseHeader(stream, callback) {
|
function parseHeader(stream, callback) {
|
||||||
stream.on('error', callback);
|
stream.on('error', callback);
|
||||||
stream.on('readable', onReadable);
|
stream.on('readable', onReadable);
|
||||||
@ -1087,8 +1087,8 @@ libraries.
|
|||||||
For example:
|
For example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const OldReader = require('./old-api-module.js').OldReader;
|
const { OldReader } = require('./old-api-module.js');
|
||||||
const Readable = require('stream').Readable;
|
const { Readable } = require('stream');
|
||||||
const oreader = new OldReader();
|
const oreader = new OldReader();
|
||||||
const myReader = new Readable().wrap(oreader);
|
const myReader = new Readable().wrap(oreader);
|
||||||
|
|
||||||
@ -1170,7 +1170,7 @@ of the four basic stream classes (`stream.Writable`, `stream.Readable`,
|
|||||||
parent class constructor:
|
parent class constructor:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Writable = require('stream').Writable;
|
const { Writable } = require('stream');
|
||||||
|
|
||||||
class MyWritable extends Writable {
|
class MyWritable extends Writable {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
@ -1264,7 +1264,7 @@ objects and passing appropriate methods as constructor options.
|
|||||||
For example:
|
For example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Writable = require('stream').Writable;
|
const { Writable } = require('stream');
|
||||||
|
|
||||||
const myWritable = new Writable({
|
const myWritable = new Writable({
|
||||||
write(chunk, encoding, callback) {
|
write(chunk, encoding, callback) {
|
||||||
@ -1307,7 +1307,7 @@ constructor and implement the `writable._write()` method. The
|
|||||||
For example:
|
For example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Writable = require('stream').Writable;
|
const { Writable } = require('stream');
|
||||||
|
|
||||||
class MyWritable extends Writable {
|
class MyWritable extends Writable {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
@ -1321,7 +1321,7 @@ class MyWritable extends Writable {
|
|||||||
Or, when using pre-ES6 style constructors:
|
Or, when using pre-ES6 style constructors:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Writable = require('stream').Writable;
|
const { Writable } = require('stream');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
function MyWritable(options) {
|
function MyWritable(options) {
|
||||||
@ -1335,7 +1335,7 @@ util.inherits(MyWritable, Writable);
|
|||||||
Or, using the Simplified Constructor approach:
|
Or, using the Simplified Constructor approach:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Writable = require('stream').Writable;
|
const { Writable } = require('stream');
|
||||||
|
|
||||||
const myWritable = new Writable({
|
const myWritable = new Writable({
|
||||||
write(chunk, encoding, callback) {
|
write(chunk, encoding, callback) {
|
||||||
@ -1449,7 +1449,7 @@ on how the stream is being used. Using the callback ensures consistent and
|
|||||||
predictable handling of errors.
|
predictable handling of errors.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Writable = require('stream').Writable;
|
const { Writable } = require('stream');
|
||||||
|
|
||||||
const myWritable = new Writable({
|
const myWritable = new Writable({
|
||||||
write(chunk, encoding, callback) {
|
write(chunk, encoding, callback) {
|
||||||
@ -1470,7 +1470,7 @@ is not of any real particular usefulness, the example illustrates each of the
|
|||||||
required elements of a custom [Writable][] stream instance:
|
required elements of a custom [Writable][] stream instance:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Writable = require('stream').Writable;
|
const { Writable } = require('stream');
|
||||||
|
|
||||||
class MyWritable extends Writable {
|
class MyWritable extends Writable {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
@ -1514,7 +1514,7 @@ constructor and implement the `readable._read()` method.
|
|||||||
For example:
|
For example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Readable = require('stream').Readable;
|
const { Readable } = require('stream');
|
||||||
|
|
||||||
class MyReadable extends Readable {
|
class MyReadable extends Readable {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
@ -1528,7 +1528,7 @@ class MyReadable extends Readable {
|
|||||||
Or, when using pre-ES6 style constructors:
|
Or, when using pre-ES6 style constructors:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Readable = require('stream').Readable;
|
const { Readable } = require('stream');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
function MyReadable(options) {
|
function MyReadable(options) {
|
||||||
@ -1542,7 +1542,7 @@ util.inherits(MyReadable, Readable);
|
|||||||
Or, using the Simplified Constructor approach:
|
Or, using the Simplified Constructor approach:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Readable = require('stream').Readable;
|
const { Readable } = require('stream');
|
||||||
|
|
||||||
const myReadable = new Readable({
|
const myReadable = new Readable({
|
||||||
read(size) {
|
read(size) {
|
||||||
@ -1661,7 +1661,7 @@ consistent and predictable handling of errors.
|
|||||||
|
|
||||||
<!-- eslint-disable no-useless-return -->
|
<!-- eslint-disable no-useless-return -->
|
||||||
```js
|
```js
|
||||||
const Readable = require('stream').Readable;
|
const { Readable } = require('stream');
|
||||||
|
|
||||||
const myReadable = new Readable({
|
const myReadable = new Readable({
|
||||||
read(size) {
|
read(size) {
|
||||||
@ -1682,7 +1682,7 @@ The following is a basic example of a Readable stream that emits the numerals
|
|||||||
from 1 to 1,000,000 in ascending order, and then ends.
|
from 1 to 1,000,000 in ascending order, and then ends.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Readable = require('stream').Readable;
|
const { Readable } = require('stream');
|
||||||
|
|
||||||
class Counter extends Readable {
|
class Counter extends Readable {
|
||||||
constructor(opt) {
|
constructor(opt) {
|
||||||
@ -1739,7 +1739,7 @@ constructor and implement *both* the `readable._read()` and
|
|||||||
For example:
|
For example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Duplex = require('stream').Duplex;
|
const { Duplex } = require('stream');
|
||||||
|
|
||||||
class MyDuplex extends Duplex {
|
class MyDuplex extends Duplex {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
@ -1752,7 +1752,7 @@ class MyDuplex extends Duplex {
|
|||||||
Or, when using pre-ES6 style constructors:
|
Or, when using pre-ES6 style constructors:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Duplex = require('stream').Duplex;
|
const { Duplex } = require('stream');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
function MyDuplex(options) {
|
function MyDuplex(options) {
|
||||||
@ -1766,7 +1766,7 @@ util.inherits(MyDuplex, Duplex);
|
|||||||
Or, using the Simplified Constructor approach:
|
Or, using the Simplified Constructor approach:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Duplex = require('stream').Duplex;
|
const { Duplex } = require('stream');
|
||||||
|
|
||||||
const myDuplex = new Duplex({
|
const myDuplex = new Duplex({
|
||||||
read(size) {
|
read(size) {
|
||||||
@ -1789,7 +1789,7 @@ incoming written data via the [Writable][] interface that is read back out
|
|||||||
via the [Readable][] interface.
|
via the [Readable][] interface.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Duplex = require('stream').Duplex;
|
const { Duplex } = require('stream');
|
||||||
const kSource = Symbol('source');
|
const kSource = Symbol('source');
|
||||||
|
|
||||||
class MyDuplex extends Duplex {
|
class MyDuplex extends Duplex {
|
||||||
@ -1830,7 +1830,7 @@ that accepts JavaScript numbers that are converted to hexadecimal strings on
|
|||||||
the Readable side.
|
the Readable side.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Transform = require('stream').Transform;
|
const { Transform } = require('stream');
|
||||||
|
|
||||||
// All Transform streams are also Duplex Streams
|
// All Transform streams are also Duplex Streams
|
||||||
const myTransform = new Transform({
|
const myTransform = new Transform({
|
||||||
@ -1895,7 +1895,7 @@ the output on the Readable side is not consumed.
|
|||||||
For example:
|
For example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Transform = require('stream').Transform;
|
const { Transform } = require('stream');
|
||||||
|
|
||||||
class MyTransform extends Transform {
|
class MyTransform extends Transform {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
@ -1908,7 +1908,7 @@ class MyTransform extends Transform {
|
|||||||
Or, when using pre-ES6 style constructors:
|
Or, when using pre-ES6 style constructors:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Transform = require('stream').Transform;
|
const { Transform } = require('stream');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
|
||||||
function MyTransform(options) {
|
function MyTransform(options) {
|
||||||
@ -1922,7 +1922,7 @@ util.inherits(MyTransform, Transform);
|
|||||||
Or, using the Simplified Constructor approach:
|
Or, using the Simplified Constructor approach:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const Transform = require('stream').Transform;
|
const { Transform } = require('stream');
|
||||||
|
|
||||||
const myTransform = new Transform({
|
const myTransform = new Transform({
|
||||||
transform(chunk, encoding, callback) {
|
transform(chunk, encoding, callback) {
|
||||||
|
@ -7,13 +7,13 @@ strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16
|
|||||||
characters. It can be accessed using:
|
characters. It can be accessed using:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const StringDecoder = require('string_decoder').StringDecoder;
|
const { StringDecoder } = require('string_decoder');
|
||||||
```
|
```
|
||||||
|
|
||||||
The following example shows the basic use of the `StringDecoder` class.
|
The following example shows the basic use of the `StringDecoder` class.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const StringDecoder = require('string_decoder').StringDecoder;
|
const { StringDecoder } = require('string_decoder');
|
||||||
const decoder = new StringDecoder('utf8');
|
const decoder = new StringDecoder('utf8');
|
||||||
|
|
||||||
const cent = Buffer.from([0xC2, 0xA2]);
|
const cent = Buffer.from([0xC2, 0xA2]);
|
||||||
@ -32,7 +32,7 @@ In the following example, the three UTF-8 encoded bytes of the European Euro
|
|||||||
symbol (`€`) are written over three separate operations:
|
symbol (`€`) are written over three separate operations:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const StringDecoder = require('string_decoder').StringDecoder;
|
const { StringDecoder } = require('string_decoder');
|
||||||
const decoder = new StringDecoder('utf8');
|
const decoder = new StringDecoder('utf8');
|
||||||
|
|
||||||
decoder.write(Buffer.from([0xE2]));
|
decoder.write(Buffer.from([0xE2]));
|
||||||
|
@ -55,7 +55,7 @@ properties of a WHATWG `URL` object.
|
|||||||
Parsing the URL string using the WHATWG API:
|
Parsing the URL string using the WHATWG API:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const URL = require('url').URL;
|
const { URL } = require('url');
|
||||||
const myURL =
|
const myURL =
|
||||||
new URL('https://user:pass@sub.host.com:8080/p/a/t/h?query=string#hash');
|
new URL('https://user:pass@sub.host.com:8080/p/a/t/h?query=string#hash');
|
||||||
```
|
```
|
||||||
@ -607,7 +607,7 @@ Alias for [`urlSearchParams[@@iterator]()`][`urlSearchParams@@iterator()`].
|
|||||||
Iterates over each name-value pair in the query and invokes the given function.
|
Iterates over each name-value pair in the query and invokes the given function.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const URL = require('url').URL;
|
const { URL } = require('url');
|
||||||
const myURL = new URL('https://example.org/?a=b&c=d');
|
const myURL = new URL('https://example.org/?a=b&c=d');
|
||||||
myURL.searchParams.forEach((value, name, searchParams) => {
|
myURL.searchParams.forEach((value, name, searchParams) => {
|
||||||
console.log(name, value, myURL.searchParams === searchParams);
|
console.log(name, value, myURL.searchParams === searchParams);
|
||||||
@ -1098,7 +1098,7 @@ 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. For example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const URL = require('url').URL;
|
const { URL } = require('url');
|
||||||
const myURL = new URL('https://%CF%80.com/foo');
|
const myURL = new URL('https://%CF%80.com/foo');
|
||||||
console.log(myURL.href);
|
console.log(myURL.href);
|
||||||
// Prints https://xn--1xa.com/foo
|
// Prints https://xn--1xa.com/foo
|
||||||
|
@ -335,7 +335,7 @@ the code inside the `main` function if it's more than just declaration.
|
|||||||
```js
|
```js
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common.js');
|
const common = require('../common.js');
|
||||||
const SlowBuffer = require('buffer').SlowBuffer;
|
const { SlowBuffer } = require('buffer');
|
||||||
|
|
||||||
const configs = {
|
const configs = {
|
||||||
// Number of operations, specified here so they show up in the report.
|
// Number of operations, specified here so they show up in the report.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user