doc: conform to rules for eslint-plugin-markdown

PR-URL: https://github.com/nodejs/node/pull/12563
Refs: https://github.com/nodejs/node/pull/12557#issuecomment-296015032
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
This commit is contained in:
Vse Mozhet Byt 2017-04-21 17:38:31 +03:00
parent b6d293d215
commit e2c3e4727d
18 changed files with 141 additions and 137 deletions

View File

@ -63,18 +63,18 @@ are evaluated also:
const assert = require('assert'); const assert = require('assert');
const obj1 = { const obj1 = {
a : { a: {
b : 1 b: 1
} }
}; };
const obj2 = { const obj2 = {
a : { a: {
b : 2 b: 2
} }
}; };
const obj3 = { const obj3 = {
a : { a: {
b : 1 b: 1
} }
}; };
const obj4 = Object.create(obj1); const obj4 = Object.create(obj1);
@ -322,18 +322,18 @@ Tests for any deep inequality. Opposite of [`assert.deepEqual()`][].
const assert = require('assert'); const assert = require('assert');
const obj1 = { const obj1 = {
a : { a: {
b : 1 b: 1
} }
}; };
const obj2 = { const obj2 = {
a : { a: {
b : 2 b: 2
} }
}; };
const obj3 = { const obj3 = {
a : { a: {
b : 1 b: 1
} }
}; };
const obj4 = Object.create(obj1); const obj4 = Object.create(obj1);
@ -368,10 +368,10 @@ Tests for deep strict inequality. Opposite of [`assert.deepStrictEqual()`][].
```js ```js
const assert = require('assert'); const assert = require('assert');
assert.notDeepEqual({a:1}, {a:'1'}); assert.notDeepEqual({a: 1}, {a: '1'});
// AssertionError: { a: 1 } notDeepEqual { a: '1' } // AssertionError: { a: 1 } notDeepEqual { a: '1' }
assert.notDeepStrictEqual({a:1}, {a:'1'}); assert.notDeepStrictEqual({a: 1}, {a: '1'});
// OK // OK
``` ```
@ -542,7 +542,7 @@ assert.throws(
throw new Error('Wrong value'); throw new Error('Wrong value');
}, },
function(err) { function(err) {
if ( (err instanceof Error) && /value/.test(err) ) { if ((err instanceof Error) && /value/.test(err)) {
return true; return true;
} }
}, },

View File

@ -959,7 +959,7 @@ Example: Copy an ASCII string into a `Buffer`, one byte at a time
const str = 'Node.js'; const str = 'Node.js';
const buf = Buffer.allocUnsafe(str.length); const buf = Buffer.allocUnsafe(str.length);
for (let i = 0; i < str.length ; i++) { for (let i = 0; i < str.length; i++) {
buf[i] = str.charCodeAt(i); buf[i] = str.charCodeAt(i);
} }
@ -1087,7 +1087,7 @@ byte 16 through byte 19 into `buf2`, starting at the 8th byte in `buf2`
const buf1 = Buffer.allocUnsafe(26); const buf1 = Buffer.allocUnsafe(26);
const buf2 = Buffer.allocUnsafe(26).fill('!'); const buf2 = Buffer.allocUnsafe(26).fill('!');
for (let i = 0 ; i < 26 ; i++) { for (let i = 0; i < 26; i++) {
// 97 is the decimal ASCII value for 'a' // 97 is the decimal ASCII value for 'a'
buf1[i] = i + 97; buf1[i] = i + 97;
} }
@ -1104,7 +1104,7 @@ overlapping region within the same `Buffer`
```js ```js
const buf = Buffer.allocUnsafe(26); const buf = Buffer.allocUnsafe(26);
for (let i = 0 ; i < 26 ; i++) { for (let i = 0; i < 26; i++) {
// 97 is the decimal ASCII value for 'a' // 97 is the decimal ASCII value for 'a'
buf[i] = i + 97; buf[i] = i + 97;
} }
@ -1871,7 +1871,7 @@ one byte from the original `Buffer`
```js ```js
const buf1 = Buffer.allocUnsafe(26); const buf1 = Buffer.allocUnsafe(26);
for (let i = 0 ; i < 26 ; i++) { for (let i = 0; i < 26; i++) {
// 97 is the decimal ASCII value for 'a' // 97 is the decimal ASCII value for 'a'
buf1[i] = i + 97; buf1[i] = i + 97;
} }
@ -2021,9 +2021,9 @@ const json = JSON.stringify(buf);
console.log(json); console.log(json);
const copy = JSON.parse(json, (key, value) => { const copy = JSON.parse(json, (key, value) => {
return value && value.type === 'Buffer' return value && value.type === 'Buffer' ?
? Buffer.from(value.data) Buffer.from(value.data) :
: value; value;
}); });
// Prints: <Buffer 01 02 03 04 05> // Prints: <Buffer 01 02 03 04 05>
@ -2049,7 +2049,7 @@ Examples:
```js ```js
const buf1 = Buffer.allocUnsafe(26); const buf1 = Buffer.allocUnsafe(26);
for (let i = 0 ; i < 26 ; i++) { for (let i = 0; i < 26; i++) {
// 97 is the decimal ASCII value for 'a' // 97 is the decimal ASCII value for 'a'
buf1[i] = i + 97; buf1[i] = i + 97;
} }

View File

@ -200,7 +200,7 @@ the process is spawned. The default options are:
const defaults = { const defaults = {
encoding: 'utf8', encoding: 'utf8',
timeout: 0, timeout: 0,
maxBuffer: 200*1024, maxBuffer: 200 * 1024,
killSignal: 'SIGTERM', killSignal: 'SIGTERM',
cwd: null, cwd: null,
env: null env: null
@ -933,13 +933,17 @@ as in this example:
'use strict'; 'use strict';
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
const child = spawn('sh', ['-c', const child = spawn(
`node -e "setInterval(() => { 'sh',
[
'-c',
`node -e "setInterval(() => {
console.log(process.pid, 'is alive') console.log(process.pid, 'is alive')
}, 500);"` }, 500);"`
], { ], {
stdio: ['inherit', 'inherit', 'inherit'] stdio: ['inherit', 'inherit', 'inherit']
}); }
);
setTimeout(() => { setTimeout(() => {
child.kill(); // does not terminate the node process in the shell child.kill(); // does not terminate the node process in the shell

View File

@ -523,11 +523,14 @@ When any of the workers die the cluster module will emit the `'exit'` event.
This can be used to restart the worker by calling `.fork()` again. This can be used to restart the worker by calling `.fork()` again.
```js ```js
cluster.on('exit', (worker, code, signal) => { cluster.on(
console.log('worker %d died (%s). restarting...', 'exit',
worker.process.pid, signal || code); (worker, code, signal) => {
cluster.fork(); console.log('worker %d died (%s). restarting...',
}); worker.process.pid, signal || code);
cluster.fork();
}
);
``` ```
See [child_process event: 'exit'][]. See [child_process event: 'exit'][].

View File

@ -142,7 +142,7 @@ the default behavior of `console` in Node.js.
// new impl for assert without monkey-patching. // new impl for assert without monkey-patching.
const myConsole = Object.create(console, { const myConsole = Object.create(console, {
assert: { assert: {
value: function assert(assertion, message, ...args) { value(assertion, message, ...args) {
try { try {
console.assert(assertion, message, ...args); console.assert(assertion, message, ...args);
} catch (err) { } catch (err) {
@ -276,9 +276,7 @@ prints the result to `stdout`:
```js ```js
console.time('100-elements'); console.time('100-elements');
for (let i = 0; i < 100; i++) { for (let i = 0; i < 100; i++) ;
;
}
console.timeEnd('100-elements'); console.timeEnd('100-elements');
// prints 100-elements: 225.438ms // prints 100-elements: 225.438ms
``` ```

View File

@ -288,7 +288,8 @@ decipher.on('end', () => {
// Prints: some clear text data // Prints: some clear text data
}); });
const encrypted = 'ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504'; const encrypted =
'ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504';
decipher.write(encrypted, 'hex'); decipher.write(encrypted, 'hex');
decipher.end(); decipher.end();
``` ```
@ -312,7 +313,8 @@ Example: Using the [`decipher.update()`][] and [`decipher.final()`][] methods:
const crypto = require('crypto'); const crypto = require('crypto');
const decipher = crypto.createDecipher('aes192', 'a password'); const decipher = crypto.createDecipher('aes192', 'a password');
const encrypted = 'ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504'; const encrypted =
'ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504';
let decrypted = decipher.update(encrypted, 'hex', 'utf8'); let decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8'); decrypted += decipher.final('utf8');
console.log(decrypted); console.log(decrypted);

View File

@ -162,7 +162,7 @@ function handleRequest(req, res) {
setTimeout(() => { setTimeout(() => {
// Whoops! // Whoops!
flerb.bark(); flerb.bark();
}); }, timeout);
break; break;
default: default:
res.end('ok'); res.end('ok');

View File

@ -309,7 +309,7 @@ const net = require('net');
const url = require('url'); const url = require('url');
// Create an HTTP tunneling proxy // Create an HTTP tunneling proxy
const proxy = http.createServer( (req, res) => { const proxy = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'}); res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('okay'); res.end('okay');
}); });
@ -405,7 +405,7 @@ A client server pair demonstrating how to listen for the `'upgrade'` event.
const http = require('http'); const http = require('http');
// Create an HTTP server // Create an HTTP server
const srv = http.createServer( (req, res) => { const srv = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'}); res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('okay'); res.end('okay');
}); });
@ -1570,10 +1570,10 @@ http.get('http://nodejs.org/dist/index.json', (res) => {
let error; let error;
if (statusCode !== 200) { if (statusCode !== 200) {
error = new Error(`Request Failed.\n` + error = new Error('Request Failed.\n' +
`Status Code: ${statusCode}`); `Status Code: ${statusCode}`);
} else if (!/^application\/json/.test(contentType)) { } else if (!/^application\/json/.test(contentType)) {
error = new Error(`Invalid content-type.\n` + error = new Error('Invalid content-type.\n' +
`Expected application/json but received ${contentType}`); `Expected application/json but received ${contentType}`);
} }
if (error) { if (error) {

View File

@ -70,7 +70,7 @@ When a file is run directly from Node.js, `require.main` is set to its
directly by testing directly by testing
```js ```js
require.main === module require.main === module;
``` ```
For a file `foo.js`, this will be `true` if run via `node foo.js`, but For a file `foo.js`, this will be `true` if run via `node foo.js`, but
@ -441,7 +441,7 @@ Before a module's code is executed, Node.js will wrap it with a function
wrapper that looks like the following: wrapper that looks like the following:
```js ```js
(function (exports, require, module, __filename, __dirname) { (function(exports, require, module, __filename, __dirname) {
// Your module code actually lives in here // Your module code actually lives in here
}); });
``` ```

View File

@ -74,10 +74,10 @@ the Unix `basename` command. Trailing directory separators are ignored, see
For example: For example:
```js ```js
path.basename('/foo/bar/baz/asdf/quux.html') path.basename('/foo/bar/baz/asdf/quux.html');
// Returns: 'quux.html' // Returns: 'quux.html'
path.basename('/foo/bar/baz/asdf/quux.html', '.html') path.basename('/foo/bar/baz/asdf/quux.html', '.html');
// Returns: 'quux' // Returns: 'quux'
``` ```
@ -99,21 +99,21 @@ Provides the platform-specific path delimiter:
For example, on POSIX: For example, on POSIX:
```js ```js
console.log(process.env.PATH) console.log(process.env.PATH);
// Prints: '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin' // Prints: '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin'
process.env.PATH.split(path.delimiter) process.env.PATH.split(path.delimiter);
// Returns: ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin'] // Returns: ['/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/bin']
``` ```
On Windows: On Windows:
```js ```js
console.log(process.env.PATH) console.log(process.env.PATH);
// Prints: 'C:\Windows\system32;C:\Windows;C:\Program Files\node\' // Prints: 'C:\Windows\system32;C:\Windows;C:\Program Files\node\'
process.env.PATH.split(path.delimiter) process.env.PATH.split(path.delimiter);
// Returns: ['C:\\Windows\\system32', 'C:\\Windows', 'C:\\Program Files\\node\\'] // Returns ['C:\\Windows\\system32', 'C:\\Windows', 'C:\\Program Files\\node\\']
``` ```
## path.dirname(path) ## path.dirname(path)
@ -135,7 +135,7 @@ the Unix `dirname` command. Trailing directory separators are ignored, see
For example: For example:
```js ```js
path.dirname('/foo/bar/baz/asdf/quux') path.dirname('/foo/bar/baz/asdf/quux');
// Returns: '/foo/bar/baz/asdf' // Returns: '/foo/bar/baz/asdf'
``` ```
@ -162,19 +162,19 @@ an empty string is returned.
For example: For example:
```js ```js
path.extname('index.html') path.extname('index.html');
// Returns: '.html' // Returns: '.html'
path.extname('index.coffee.md') path.extname('index.coffee.md');
// Returns: '.md' // Returns: '.md'
path.extname('index.') path.extname('index.');
// Returns: '.' // Returns: '.'
path.extname('index') path.extname('index');
// Returns: '' // Returns: ''
path.extname('.index') path.extname('.index');
// Returns: '' // Returns: ''
``` ```
@ -259,22 +259,22 @@ 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
path.isAbsolute('/baz/..') // true path.isAbsolute('/baz/..'); // true
path.isAbsolute('qux/') // false path.isAbsolute('qux/'); // false
path.isAbsolute('.') // false path.isAbsolute('.'); // false
``` ```
On Windows: On Windows:
```js ```js
path.isAbsolute('//server') // true path.isAbsolute('//server'); // true
path.isAbsolute('\\\\server') // true path.isAbsolute('\\\\server'); // true
path.isAbsolute('C:/foo/..') // true path.isAbsolute('C:/foo/..'); // true
path.isAbsolute('C:\\foo\\..') // true path.isAbsolute('C:\\foo\\..'); // true
path.isAbsolute('bar\\baz') // false path.isAbsolute('bar\\baz'); // false
path.isAbsolute('bar/baz') // false path.isAbsolute('bar/baz'); // false
path.isAbsolute('.') // false path.isAbsolute('.'); // false
``` ```
A [`TypeError`][] is thrown if `path` is not a string. A [`TypeError`][] is thrown if `path` is not a string.
@ -297,10 +297,10 @@ working directory.
For example: For example:
```js ```js
path.join('/foo', 'bar', 'baz/asdf', 'quux', '..') path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');
// Returns: '/foo/bar/baz/asdf' // Returns: '/foo/bar/baz/asdf'
path.join('foo', {}, 'bar') path.join('foo', {}, 'bar');
// throws 'TypeError: Path must be a string. Received {}' // throws 'TypeError: Path must be a string. Received {}'
``` ```
@ -327,14 +327,14 @@ 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/..');
// Returns: '/foo/bar/baz/asdf' // Returns: '/foo/bar/baz/asdf'
``` ```
On Windows: On Windows:
```js ```js
path.normalize('C:\\temp\\\\foo\\bar\\..\\') path.normalize('C:\\temp\\\\foo\\bar\\..\\');
// Returns: 'C:\\temp\\foo\\' // Returns: 'C:\\temp\\foo\\'
``` ```
@ -363,7 +363,7 @@ The returned object will have the following properties:
For example on POSIX: For example on POSIX:
```js ```js
path.parse('/home/user/dir/file.txt') path.parse('/home/user/dir/file.txt');
// Returns: // Returns:
// { root: '/', // { root: '/',
// dir: '/home/user/dir', // dir: '/home/user/dir',
@ -385,7 +385,7 @@ path.parse('/home/user/dir/file.txt')
On Windows: On Windows:
```js ```js
path.parse('C:\\path\\dir\\file.txt') path.parse('C:\\path\\dir\\file.txt');
// Returns: // Returns:
// { root: 'C:\\', // { root: 'C:\\',
// dir: 'C:\\path\\dir', // dir: 'C:\\path\\dir',
@ -440,14 +440,14 @@ 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');
// Returns: '../../impl/bbb' // Returns: '../../impl/bbb'
``` ```
On Windows: On Windows:
```js ```js
path.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb') path.relative('C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb');
// Returns: '..\\..\\impl\\bbb' // Returns: '..\\..\\impl\\bbb'
``` ```
@ -483,13 +483,13 @@ of the current working directory.
For example: For example:
```js ```js
path.resolve('/foo/bar', './baz') path.resolve('/foo/bar', './baz');
// Returns: '/foo/bar/baz' // Returns: '/foo/bar/baz'
path.resolve('/foo/bar', '/tmp/file/') path.resolve('/foo/bar', '/tmp/file/');
// Returns: '/tmp/file' // Returns: '/tmp/file'
path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif') path.resolve('wwwroot', 'static_files/png/', '../gif/image.gif');
// if the current working directory is /home/myself/node, // if the current working directory is /home/myself/node,
// this returns '/home/myself/node/wwwroot/static_files/gif/image.gif' // this returns '/home/myself/node/wwwroot/static_files/gif/image.gif'
``` ```
@ -511,14 +511,14 @@ Provides the platform-specific path segment separator:
For example on POSIX: For example on POSIX:
```js ```js
'foo/bar/baz'.split(path.sep) 'foo/bar/baz'.split(path.sep);
// Returns: ['foo', 'bar', 'baz'] // Returns: ['foo', 'bar', 'baz']
``` ```
On Windows: On Windows:
```js ```js
'foo\\bar\\baz'.split(path.sep) 'foo\\bar\\baz'.split(path.sep);
// Returns: ['foo', 'bar', 'baz'] // Returns: ['foo', 'bar', 'baz']
``` ```

View File

@ -509,8 +509,7 @@ console.log(`Starting directory: ${process.cwd()}`);
try { try {
process.chdir('/tmp'); process.chdir('/tmp');
console.log(`New directory: ${process.cwd()}`); console.log(`New directory: ${process.cwd()}`);
} } catch (err) {
catch (err) {
console.error(`chdir: ${err}`); console.error(`chdir: ${err}`);
} }
``` ```
@ -1398,8 +1397,7 @@ if (process.getegid && process.setegid) {
try { try {
process.setegid(501); process.setegid(501);
console.log(`New gid: ${process.getegid()}`); console.log(`New gid: ${process.getegid()}`);
} } catch (err) {
catch (err) {
console.log(`Failed to set gid: ${err}`); console.log(`Failed to set gid: ${err}`);
} }
} }
@ -1427,8 +1425,7 @@ if (process.geteuid && process.seteuid) {
try { try {
process.seteuid(501); process.seteuid(501);
console.log(`New uid: ${process.geteuid()}`); console.log(`New uid: ${process.geteuid()}`);
} } catch (err) {
catch (err) {
console.log(`Failed to set uid: ${err}`); console.log(`Failed to set uid: ${err}`);
} }
} }
@ -1455,8 +1452,7 @@ if (process.getgid && process.setgid) {
try { try {
process.setgid(501); process.setgid(501);
console.log(`New gid: ${process.getgid()}`); console.log(`New gid: ${process.getgid()}`);
} } catch (err) {
catch (err) {
console.log(`Failed to set gid: ${err}`); console.log(`Failed to set gid: ${err}`);
} }
} }
@ -1497,8 +1493,7 @@ if (process.getuid && process.setuid) {
try { try {
process.setuid(501); process.setuid(501);
console.log(`New uid: ${process.getuid()}`); console.log(`New uid: ${process.getuid()}`);
} } catch (err) {
catch (err) {
console.log(`Failed to set uid: ${err}`); console.log(`Failed to set uid: ${err}`);
} }
} }

View File

@ -80,7 +80,7 @@ in the following example:
// Assuming gbkDecodeURIComponent function already exists... // Assuming gbkDecodeURIComponent function already exists...
querystring.parse('w=%D6%D0%CE%C4&foo=bar', null, null, querystring.parse('w=%D6%D0%CE%C4&foo=bar', null, null,
{ decodeURIComponent: gbkDecodeURIComponent }) { decodeURIComponent: gbkDecodeURIComponent });
``` ```
## querystring.stringify(obj[, sep[, eq[, options]]]) ## querystring.stringify(obj[, sep[, eq[, options]]])
@ -108,10 +108,10 @@ Any other input values will be coerced to empty strings.
For example: For example:
```js ```js
querystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' }) querystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' });
// returns 'foo=bar&baz=qux&baz=quux&corge=' // returns 'foo=bar&baz=qux&baz=quux&corge='
querystring.stringify({ foo: 'bar', baz: 'qux' }, ';', ':') querystring.stringify({ foo: 'bar', baz: 'qux' }, ';', ':');
// returns 'foo:bar;baz:qux' // returns 'foo:bar;baz:qux'
``` ```
@ -124,7 +124,7 @@ following example:
// Assuming gbkEncodeURIComponent function already exists, // Assuming gbkEncodeURIComponent function already exists,
querystring.stringify({ w: '中文', foo: 'bar' }, null, null, querystring.stringify({ w: '中文', foo: 'bar' }, null, null,
{ encodeURIComponent: gbkEncodeURIComponent }) { encodeURIComponent: gbkEncodeURIComponent });
``` ```
## querystring.unescape(str) ## querystring.unescape(str)

View File

@ -414,7 +414,7 @@ For instance: `[[substr1, substr2, ...], originalsubstring]`.
```js ```js
function completer(line) { function completer(line) {
const completions = '.help .error .exit .quit .q'.split(' '); const completions = '.help .error .exit .quit .q'.split(' ');
const hits = completions.filter((c) => { return c.indexOf(line) === 0 }); const hits = completions.filter((c) => { return c.indexOf(line) === 0; });
// show all completions if none found // show all completions if none found
return [hits.length ? hits : completions, line]; return [hits.length ? hits : completions, line];
} }
@ -492,7 +492,7 @@ const rl = readline.createInterface({
rl.prompt(); rl.prompt();
rl.on('line', (line) => { rl.on('line', (line) => {
switch(line.trim()) { switch (line.trim()) {
case 'hello': case 'hello':
console.log('world!'); console.log('world!');
break; break;

View File

@ -112,7 +112,7 @@ that implements an HTTP server:
```js ```js
const http = require('http'); const http = require('http');
const server = http.createServer( (req, res) => { const server = http.createServer((req, res) => {
// req is an http.IncomingMessage, which is a Readable Stream // req is an http.IncomingMessage, which is a Readable Stream
// res is an http.ServerResponse, which is a Writable Stream // res is an http.ServerResponse, which is a Writable Stream
@ -280,7 +280,7 @@ has been called, and all data has been flushed to the underlying system.
```js ```js
const writer = getWritableStreamSomehow(); const writer = getWritableStreamSomehow();
for (var i = 0; i < 100; i ++) { for (var i = 0; i < 100; i++) {
writer.write(`hello, #${i}!\n`); writer.write(`hello, #${i}!\n`);
} }
writer.end('This is the end\n'); writer.end('This is the end\n');
@ -483,18 +483,18 @@ possible to respect backpressure and avoid memory issues using the
[`'drain'`][] event: [`'drain'`][] event:
```js ```js
function write (data, cb) { function write(data, cb) {
if (!stream.write(data)) { if (!stream.write(data)) {
stream.once('drain', cb) stream.once('drain', cb);
} else { } else {
process.nextTick(cb) process.nextTick(cb);
} }
} }
// Wait for cb to be called before doing any other write. // Wait for cb to be called before doing any other write.
write('hello', () => { write('hello', () => {
console.log('write completed, do more writes now') console.log('write completed, do more writes now');
}) });
``` ```
A Writable stream in object mode will always ignore the `encoding` argument. A Writable stream in object mode will always ignore the `encoding` argument.
@ -749,13 +749,13 @@ Readable. This is used primarily by the mechanism that underlies the
use this method directly. use this method directly.
```js ```js
const readable = new stream.Readable const readable = new stream.Readable();
readable.isPaused() // === false readable.isPaused(); // === false
readable.pause() readable.pause();
readable.isPaused() // === true readable.isPaused(); // === true
readable.resume() readable.resume();
readable.isPaused() // === false readable.isPaused(); // === false
``` ```
##### readable.pause() ##### readable.pause()
@ -1065,7 +1065,7 @@ For example:
```js ```js
const OldReader = require('./old-api-module.js').OldReader; const OldReader = require('./old-api-module.js').OldReader;
const Readable = require('stream').Readable; const Readable = require('stream').Readable;
const oreader = new OldReader; const oreader = new OldReader();
const myReader = new Readable().wrap(oreader); const myReader = new Readable().wrap(oreader);
myReader.on('readable', () => { myReader.on('readable', () => {
@ -1906,12 +1906,12 @@ argument is passed to the `callback`, it will be forwarded on to the
`readable.push()` method. In other words the following are equivalent: `readable.push()` method. In other words the following are equivalent:
```js ```js
transform.prototype._transform = function (data, encoding, callback) { transform.prototype._transform = function(data, encoding, callback) {
this.push(data); this.push(data);
callback(); callback();
}; };
transform.prototype._transform = function (data, encoding, callback) { transform.prototype._transform = function(data, encoding, callback) {
callback(null, data); callback(null, data);
}; };
``` ```

View File

@ -289,9 +289,9 @@ manner similar to that of a Web browser resolving an anchor tag HREF.
For example: For example:
```js ```js
url.resolve('/one/two/three', 'four') // '/one/two/four' url.resolve('/one/two/three', 'four'); // '/one/two/four'
url.resolve('http://example.com/', '/one') // 'http://example.com/one' url.resolve('http://example.com/', '/one'); // 'http://example.com/one'
url.resolve('http://example.com/one', '/two') // 'http://example.com/two' url.resolve('http://example.com/one', '/two'); // 'http://example.com/two'
``` ```
## Escaped Characters ## Escaped Characters
@ -460,7 +460,7 @@ const myURL = new URL('https://example.org/foo');
console.log(myURL.href); console.log(myURL.href);
// Prints https://example.org/foo // Prints https://example.org/foo
myURL.href = 'https://example.com/bar' myURL.href = 'https://example.com/bar';
// Prints https://example.com/bar // Prints https://example.com/bar
``` ```

View File

@ -328,7 +328,8 @@ class Box {
// Five space padding because that's the size of "Box< ". // Five space padding because that's the size of "Box< ".
const padding = ' '.repeat(5); const padding = ' '.repeat(5);
const inner = util.inspect(this.value, newOptions).replace(/\n/g, '\n' + padding); const inner = util.inspect(this.value, newOptions)
.replace(/\n/g, '\n' + padding);
return options.stylize('Box', 'special') + '< ' + inner + ' >'; return options.stylize('Box', 'special') + '< ' + inner + ' >';
} }
} }
@ -460,7 +461,7 @@ const util = require('util');
util.isArray([]); util.isArray([]);
// Returns: true // Returns: true
util.isArray(new Array); util.isArray(new Array());
// Returns: true // Returns: true
util.isArray({}); util.isArray({});
// Returns: false // Returns: false
@ -696,7 +697,7 @@ util.isObject(null);
// Returns: false // Returns: false
util.isObject({}); util.isObject({});
// Returns: true // Returns: true
util.isObject(function(){}); util.isObject(function() {});
// Returns: false // Returns: false
``` ```

View File

@ -435,7 +435,7 @@ to the `http` module passed to it. For instance:
'use strict'; 'use strict';
const vm = require('vm'); const vm = require('vm');
let code = const code =
`(function(require) { `(function(require) {
const http = require('http'); const http = require('http');
@ -448,7 +448,7 @@ let code =
console.log('Server running at http://127.0.0.1:8124/'); console.log('Server running at http://127.0.0.1:8124/');
})`; })`;
vm.runInThisContext(code)(require); vm.runInThisContext(code)(require);
``` ```
*Note*: The `require()` in the above case shares the state with the context it *Note*: The `require()` in the above case shares the state with the context it

View File

@ -65,9 +65,9 @@ const zlib = require('zlib');
const http = require('http'); const http = require('http');
const fs = require('fs'); const fs = require('fs');
const request = http.get({ host: 'example.com', const request = http.get({ host: 'example.com',
path: '/', path: '/',
port: 80, port: 80,
headers: { 'Accept-Encoding': 'gzip,deflate' } }); headers: { 'Accept-Encoding': 'gzip,deflate' } });
request.on('response', (response) => { request.on('response', (response) => {
var output = fs.createWriteStream('example.com_index.html'); var output = fs.createWriteStream('example.com_index.html');
@ -125,15 +125,16 @@ method that is used to compressed the last chunk of input data:
// This is a truncated version of the buffer from the above examples // This is a truncated version of the buffer from the above examples
const buffer = Buffer.from('eJzT0yMA', 'base64'); const buffer = Buffer.from('eJzT0yMA', 'base64');
zlib.unzip(buffer, zlib.unzip(
{finishFlush: zlib.constants.Z_SYNC_FLUSH}, buffer,
(err, buffer) => { {finishFlush: zlib.constants.Z_SYNC_FLUSH},
if (!err) { (err, buffer) => {
console.log(buffer.toString()); if (!err) {
} else { console.log(buffer.toString());
// handle error } else {
} // handle error
}); }
});
``` ```
This will not change the behavior in other error-throwing situations, e.g. This will not change the behavior in other error-throwing situations, e.g.
@ -151,7 +152,7 @@ From `zlib/zconf.h`, modified to node.js's usage:
The memory requirements for deflate are (in bytes): The memory requirements for deflate are (in bytes):
```js ```js
(1 << (windowBits+2)) + (1 << (memLevel+9)) (1 << (windowBits + 2)) + (1 << (memLevel + 9));
``` ```
That is: 128K for windowBits=15 + 128K for memLevel = 8 That is: 128K for windowBits=15 + 128K for memLevel = 8
@ -169,7 +170,7 @@ This will, however, generally degrade compression.
The memory requirements for inflate are (in bytes) The memory requirements for inflate are (in bytes)
```js ```js
1 << windowBits 1 << windowBits;
``` ```
That is, 32K for windowBits=15 (default value) plus a few kilobytes That is, 32K for windowBits=15 (default value) plus a few kilobytes