mirror of https://github.com/nodejs/node.git
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/7745pull/7735/head
parent
bb9eabec40
commit
28d9485c25
|
@ -71,7 +71,7 @@ const obj3 = {
|
|||
a : {
|
||||
b : 1
|
||||
}
|
||||
}
|
||||
};
|
||||
const obj4 = Object.create(obj1);
|
||||
|
||||
assert.deepEqual(obj1, obj1);
|
||||
|
@ -230,7 +230,7 @@ const assert = require('assert');
|
|||
|
||||
assert.ifError(0); // OK
|
||||
assert.ifError(1); // Throws 1
|
||||
assert.ifError('error') // Throws 'error'
|
||||
assert.ifError('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]);
|
||||
|
||||
for (var b of buf)
|
||||
console.log(b)
|
||||
console.log(b);
|
||||
|
||||
// Prints:
|
||||
// 1
|
||||
|
|
|
@ -236,7 +236,7 @@ var decrypted = '';
|
|||
decipher.on('readable', () => {
|
||||
var data = decipher.read();
|
||||
if (data)
|
||||
decrypted += data.toString('utf8');
|
||||
decrypted += data.toString('utf8');
|
||||
});
|
||||
decipher.on('end', () => {
|
||||
console.log(decrypted);
|
||||
|
|
|
@ -1022,12 +1022,12 @@ will be returned._
|
|||
// OS X and Linux
|
||||
fs.open('<directory>', 'a+', (err, fd) => {
|
||||
// => [Error: EISDIR: illegal operation on a directory, open <directory>]
|
||||
})
|
||||
});
|
||||
|
||||
// Windows and FreeBSD
|
||||
fs.open('<directory>', 'a+', (err, fd) => {
|
||||
// => null, <fd>
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
## fs.openSync(path, flags[, mode])
|
||||
|
|
|
@ -90,7 +90,7 @@ http.get({
|
|||
agent: false // create a new agent just for this one request
|
||||
}, (res) => {
|
||||
// Do stuff with response
|
||||
})
|
||||
});
|
||||
```
|
||||
|
||||
### new Agent([options])
|
||||
|
@ -1451,8 +1451,8 @@ var req = http.request(options, (res) => {
|
|||
console.log(`BODY: ${chunk}`);
|
||||
});
|
||||
res.on('end', () => {
|
||||
console.log('No more data in response.')
|
||||
})
|
||||
console.log('No more data in response.');
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (e) => {
|
||||
|
|
|
@ -231,7 +231,7 @@ options.agent = new https.Agent(options);
|
|||
|
||||
var req = https.request(options, (res) => {
|
||||
...
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Alternatively, opt out of connection pooling by not using an `Agent`.
|
||||
|
@ -251,7 +251,7 @@ var options = {
|
|||
|
||||
var req = https.request(options, (res) => {
|
||||
...
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
[`Agent`]: #https_class_https_agent
|
||||
|
|
|
@ -234,7 +234,7 @@ path.format({
|
|||
base : "file.txt",
|
||||
ext : ".txt",
|
||||
name : "file"
|
||||
})
|
||||
});
|
||||
// returns 'C:\\path\\dir\\file.txt'
|
||||
```
|
||||
|
||||
|
|
|
@ -398,10 +398,10 @@ For instance: `[[substr1, substr2, ...], originalsubstring]`.
|
|||
|
||||
```js
|
||||
function completer(line) {
|
||||
var completions = '.help .error .exit .quit .q'.split(' ')
|
||||
var hits = completions.filter((c) => { return c.indexOf(line) == 0 })
|
||||
var completions = '.help .error .exit .quit .q'.split(' ');
|
||||
var hits = completions.filter((c) => { return c.indexOf(line) == 0 });
|
||||
// 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
|
||||
}).on('exit', () => {
|
||||
socket.end();
|
||||
})
|
||||
});
|
||||
}).listen('/tmp/node-repl-sock');
|
||||
|
||||
net.createServer((socket) => {
|
||||
|
|
|
@ -1227,9 +1227,9 @@ const Writable = require('stream').Writable;
|
|||
const myWritable = new Writable({
|
||||
write(chunk, encoding, callback) {
|
||||
if (chunk.toString().indexOf('a') >= 0) {
|
||||
callback(new Error('chunk is invalid'))
|
||||
callback(new Error('chunk is invalid'));
|
||||
} else {
|
||||
callback()
|
||||
callback();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1252,9 +1252,9 @@ class MyWritable extends Writable {
|
|||
|
||||
_write(chunk, encoding, callback) {
|
||||
if (chunk.toString().indexOf('a') >= 0) {
|
||||
callback(new Error('chunk is invalid'))
|
||||
callback(new Error('chunk is invalid'));
|
||||
} else {
|
||||
callback()
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,14 +145,14 @@ const util = require('util');
|
|||
const EventEmitter = require('events');
|
||||
|
||||
function MyStream() {
|
||||
EventEmitter.call(this);
|
||||
EventEmitter.call(this);
|
||||
}
|
||||
|
||||
util.inherits(MyStream, EventEmitter);
|
||||
|
||||
MyStream.prototype.write = function(data) {
|
||||
this.emit('data', data);
|
||||
}
|
||||
this.emit('data', data);
|
||||
};
|
||||
|
||||
const stream = new MyStream();
|
||||
|
||||
|
@ -161,7 +161,7 @@ console.log(MyStream.super_ === EventEmitter); // true
|
|||
|
||||
stream.on('data', (data) => {
|
||||
console.log(`Received data: "${data}"`);
|
||||
})
|
||||
});
|
||||
stream.write('It works!'); // Received data: "It works!"
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue