Skip to content

Commit 61f91b2

Browse files
jasnellMyles Borins
authored and
Myles Borins
committed
doc: fix, modernize examples in docs
* Use single quotes consistently * Modernize examples to use template strings and arrow funcs * Fix a few typos * Example edits for consistency PR-URL: #4282 Reviewed-By: Chris Dickinson <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent d87ad30 commit 61f91b2

30 files changed

+613
-614
lines changed

doc/api/addons.markdown

+9-9
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ You can now use the binary addon in a Node.js project `hello.js` by pointing
9999
`require` to the recently built `hello.node` module:
100100

101101
// hello.js
102-
var addon = require('./build/Release/addon');
102+
const addon = require('./build/Release/addon');
103103

104104
console.log(addon.hello()); // 'world'
105105

@@ -189,7 +189,7 @@ function calls and return a result. This is the main and only needed source
189189
You can test it with the following JavaScript snippet:
190190

191191
// test.js
192-
var addon = require('./build/Release/addon');
192+
const addon = require('./build/Release/addon');
193193

194194
console.log( 'This should be eight:', addon.add(3,5) );
195195

@@ -237,7 +237,7 @@ adding the function as a property of `exports`.
237237
To test it, run the following JavaScript snippet:
238238

239239
// test.js
240-
var addon = require('./build/Release/addon');
240+
const addon = require('./build/Release/addon');
241241

242242
addon(function(msg){
243243
console.log(msg); // 'hello world'
@@ -282,7 +282,7 @@ the string passed to `createObject()`:
282282
To test it in JavaScript:
283283

284284
// test.js
285-
var addon = require('./build/Release/addon');
285+
const addon = require('./build/Release/addon');
286286

287287
var obj1 = addon('hello');
288288
var obj2 = addon('world');
@@ -336,7 +336,7 @@ wraps a C++ function:
336336
To test:
337337

338338
// test.js
339-
var addon = require('./build/Release/addon');
339+
const addon = require('./build/Release/addon');
340340

341341
var fn = addon();
342342
console.log(fn()); // 'hello world'
@@ -470,7 +470,7 @@ prototype:
470470
Test it with:
471471

472472
// test.js
473-
var addon = require('./build/Release/addon');
473+
const addon = require('./build/Release/addon');
474474

475475
var obj = new addon.MyObject(10);
476476
console.log( obj.plusOne() ); // 11
@@ -630,7 +630,7 @@ The implementation is similar to the above in `myobject.cc`:
630630
Test it with:
631631

632632
// test.js
633-
var createObject = require('./build/Release/addon');
633+
const createObject = require('./build/Release/addon');
634634

635635
var obj = createObject(10);
636636
console.log( obj.plusOne() ); // 11
@@ -792,7 +792,7 @@ The implementation of `myobject.cc` is similar to before:
792792
Test it with:
793793

794794
// test.js
795-
var addon = require('./build/Release/addon');
795+
const addon = require('./build/Release/addon');
796796

797797
var obj1 = addon.createObject(10);
798798
var obj2 = addon.createObject(20);
@@ -866,7 +866,7 @@ The file `addon.cc` implements AtExit below:
866866
Test in JavaScript by running:
867867

868868
// test.js
869-
var addon = require('./build/Release/addon');
869+
const addon = require('./build/Release/addon');
870870

871871
[online]: https://v8docs.nodesource.com/
872872
[libuv]: https://github.com/libuv/libuv

doc/api/assert.markdown

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ assertion.
4141

4242
assert.doesNotThrow(
4343
function() {
44-
throw new TypeError("Wrong value");
44+
throw new TypeError('Wrong value');
4545
},
4646
SyntaxError
4747
);
@@ -51,7 +51,7 @@ is thrown instead.
5151

5252
assert.doesNotThrow(
5353
function() {
54-
throw new TypeError("Wrong value");
54+
throw new TypeError('Wrong value');
5555
},
5656
TypeError
5757
);
@@ -102,7 +102,7 @@ Validate instanceof using constructor:
102102

103103
assert.throws(
104104
function() {
105-
throw new Error("Wrong value");
105+
throw new Error('Wrong value');
106106
},
107107
Error
108108
);
@@ -111,7 +111,7 @@ Validate error message using [`RegExp`][]:
111111

112112
assert.throws(
113113
function() {
114-
throw new Error("Wrong value");
114+
throw new Error('Wrong value');
115115
},
116116
/value/
117117
);
@@ -120,19 +120,19 @@ Custom error validation:
120120

121121
assert.throws(
122122
function() {
123-
throw new Error("Wrong value");
123+
throw new Error('Wrong value');
124124
},
125125
function(err) {
126126
if ( (err instanceof Error) && /value/.test(err) ) {
127127
return true;
128128
}
129129
},
130-
"unexpected error"
130+
'unexpected error'
131131
);
132132

133133
[`assert.deepEqual`]: #assert_assert_deepequal_actual_expected_message
134134
[`assert.deepStrictEqual`]: #assert_assert_deepstrictequal_actual_expected_message
135135
[`assert.throws()`]: #assert_assert_throws_block_error_message
136136
[`Error`]: errors.html#errors_class_error
137137
[`RegExp`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
138-
[`TypeError`]: errors.html#errors_class_typeerror
138+
[`TypeError`]: errors.html#errors_class_typeerror

doc/api/buffer.markdown

+6-6
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ Example:
104104

105105
str = '\u00bd + \u00bc = \u00be';
106106

107-
console.log(str + ": " + str.length + " characters, " +
108-
Buffer.byteLength(str, 'utf8') + " bytes");
107+
console.log(`${str}: ${str.length} characters, ` +
108+
`${Buffer.byteLength(str, 'utf8')} bytes`);
109109

110110
// ½ + ¼ = ¾: 9 characters, 12 bytes
111111

@@ -277,7 +277,7 @@ and `end` (defaults to `buffer.length`) are not given it will fill the entire
277277
buffer.
278278

279279
var b = new Buffer(50);
280-
b.fill("h");
280+
b.fill('h');
281281

282282
### buf.indexOf(value[, byteOffset])
283283

@@ -301,7 +301,7 @@ buffer object. It does not change when the contents of the buffer are changed.
301301
buf = new Buffer(1234);
302302

303303
console.log(buf.length);
304-
buf.write("some string", 0, "ascii");
304+
buf.write('some string', 0, 'ascii');
305305
console.log(buf.length);
306306

307307
// 1234
@@ -313,7 +313,7 @@ modify the length of a buffer should therefore treat `length` as read-only and
313313
use [`buf.slice`][] to create a new buffer.
314314

315315
buf = new Buffer(10);
316-
buf.write("abcdefghj", 0, "ascii");
316+
buf.write('abcdefghj', 0, 'ascii');
317317
console.log(buf.length); // 10
318318
buf = buf.slice(0,5);
319319
console.log(buf.length); // 5
@@ -639,7 +639,7 @@ The method will not write partial characters.
639639

640640
buf = new Buffer(256);
641641
len = buf.write('\u00bd + \u00bc = \u00be', 0);
642-
console.log(len + " bytes: " + buf.toString('utf8', 0, len));
642+
console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);
643643

644644
### buf.writeDoubleBE(value, offset[, noAssert])
645645
### buf.writeDoubleLE(value, offset[, noAssert])

0 commit comments

Comments
 (0)