doc: fix inconsistencies in code style
Adds missing semicolons, removes extra white space, and properly indents various code snippets in the documentation. Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: targos - Michaël Zasso <mic.besace@gmail.com> PR-URL: https://github.com/nodejs/node/pull/7745
This commit is contained in:
parent
bb9eabec40
commit
28d9485c25
@ -71,7 +71,7 @@ const obj3 = {
|
|||||||
a : {
|
a : {
|
||||||
b : 1
|
b : 1
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
const obj4 = Object.create(obj1);
|
const obj4 = Object.create(obj1);
|
||||||
|
|
||||||
assert.deepEqual(obj1, obj1);
|
assert.deepEqual(obj1, obj1);
|
||||||
@ -230,7 +230,7 @@ const assert = require('assert');
|
|||||||
|
|
||||||
assert.ifError(0); // OK
|
assert.ifError(0); // OK
|
||||||
assert.ifError(1); // Throws 1
|
assert.ifError(1); // Throws 1
|
||||||
assert.ifError('error') // Throws 'error'
|
assert.ifError('error'); // Throws 'error'
|
||||||
assert.ifError(new Error()); // Throws Error
|
assert.ifError(new Error()); // Throws Error
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ Buffers can be iterated over using the ECMAScript 2015 (ES6) `for..of` syntax:
|
|||||||
const buf = Buffer.from([1, 2, 3]);
|
const buf = Buffer.from([1, 2, 3]);
|
||||||
|
|
||||||
for (var b of buf)
|
for (var b of buf)
|
||||||
console.log(b)
|
console.log(b);
|
||||||
|
|
||||||
// Prints:
|
// Prints:
|
||||||
// 1
|
// 1
|
||||||
|
@ -1022,12 +1022,12 @@ will be returned._
|
|||||||
// OS X and Linux
|
// OS X and Linux
|
||||||
fs.open('<directory>', 'a+', (err, fd) => {
|
fs.open('<directory>', 'a+', (err, fd) => {
|
||||||
// => [Error: EISDIR: illegal operation on a directory, open <directory>]
|
// => [Error: EISDIR: illegal operation on a directory, open <directory>]
|
||||||
})
|
});
|
||||||
|
|
||||||
// Windows and FreeBSD
|
// Windows and FreeBSD
|
||||||
fs.open('<directory>', 'a+', (err, fd) => {
|
fs.open('<directory>', 'a+', (err, fd) => {
|
||||||
// => null, <fd>
|
// => null, <fd>
|
||||||
})
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## fs.openSync(path, flags[, mode])
|
## fs.openSync(path, flags[, mode])
|
||||||
|
@ -90,7 +90,7 @@ http.get({
|
|||||||
agent: false // create a new agent just for this one request
|
agent: false // create a new agent just for this one request
|
||||||
}, (res) => {
|
}, (res) => {
|
||||||
// Do stuff with response
|
// Do stuff with response
|
||||||
})
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### new Agent([options])
|
### new Agent([options])
|
||||||
@ -1451,8 +1451,8 @@ var req = http.request(options, (res) => {
|
|||||||
console.log(`BODY: ${chunk}`);
|
console.log(`BODY: ${chunk}`);
|
||||||
});
|
});
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
console.log('No more data in response.')
|
console.log('No more data in response.');
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('error', (e) => {
|
req.on('error', (e) => {
|
||||||
|
@ -231,7 +231,7 @@ options.agent = new https.Agent(options);
|
|||||||
|
|
||||||
var req = https.request(options, (res) => {
|
var 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`.
|
||||||
@ -251,7 +251,7 @@ var options = {
|
|||||||
|
|
||||||
var req = https.request(options, (res) => {
|
var req = https.request(options, (res) => {
|
||||||
...
|
...
|
||||||
}
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
[`Agent`]: #https_class_https_agent
|
[`Agent`]: #https_class_https_agent
|
||||||
|
@ -234,7 +234,7 @@ path.format({
|
|||||||
base : "file.txt",
|
base : "file.txt",
|
||||||
ext : ".txt",
|
ext : ".txt",
|
||||||
name : "file"
|
name : "file"
|
||||||
})
|
});
|
||||||
// returns 'C:\\path\\dir\\file.txt'
|
// returns 'C:\\path\\dir\\file.txt'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -398,10 +398,10 @@ For instance: `[[substr1, substr2, ...], originalsubstring]`.
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function completer(line) {
|
function completer(line) {
|
||||||
var completions = '.help .error .exit .quit .q'.split(' ')
|
var completions = '.help .error .exit .quit .q'.split(' ');
|
||||||
var hits = completions.filter((c) => { return c.indexOf(line) == 0 })
|
var 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];
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -494,7 +494,7 @@ net.createServer((socket) => {
|
|||||||
output: socket
|
output: socket
|
||||||
}).on('exit', () => {
|
}).on('exit', () => {
|
||||||
socket.end();
|
socket.end();
|
||||||
})
|
});
|
||||||
}).listen('/tmp/node-repl-sock');
|
}).listen('/tmp/node-repl-sock');
|
||||||
|
|
||||||
net.createServer((socket) => {
|
net.createServer((socket) => {
|
||||||
|
@ -1227,9 +1227,9 @@ const Writable = require('stream').Writable;
|
|||||||
const myWritable = new Writable({
|
const myWritable = new Writable({
|
||||||
write(chunk, encoding, callback) {
|
write(chunk, encoding, callback) {
|
||||||
if (chunk.toString().indexOf('a') >= 0) {
|
if (chunk.toString().indexOf('a') >= 0) {
|
||||||
callback(new Error('chunk is invalid'))
|
callback(new Error('chunk is invalid'));
|
||||||
} else {
|
} else {
|
||||||
callback()
|
callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1252,9 +1252,9 @@ class MyWritable extends Writable {
|
|||||||
|
|
||||||
_write(chunk, encoding, callback) {
|
_write(chunk, encoding, callback) {
|
||||||
if (chunk.toString().indexOf('a') >= 0) {
|
if (chunk.toString().indexOf('a') >= 0) {
|
||||||
callback(new Error('chunk is invalid'))
|
callback(new Error('chunk is invalid'));
|
||||||
} else {
|
} else {
|
||||||
callback()
|
callback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ util.inherits(MyStream, EventEmitter);
|
|||||||
|
|
||||||
MyStream.prototype.write = function(data) {
|
MyStream.prototype.write = function(data) {
|
||||||
this.emit('data', data);
|
this.emit('data', data);
|
||||||
}
|
};
|
||||||
|
|
||||||
const stream = new MyStream();
|
const stream = new MyStream();
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ console.log(MyStream.super_ === EventEmitter); // true
|
|||||||
|
|
||||||
stream.on('data', (data) => {
|
stream.on('data', (data) => {
|
||||||
console.log(`Received data: "${data}"`);
|
console.log(`Received data: "${data}"`);
|
||||||
})
|
});
|
||||||
stream.write('It works!'); // Received data: "It works!"
|
stream.write('It works!'); // Received data: "It works!"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user