Skip to content

Commit

Permalink
doc: fix, modernize examples in docs
Browse files Browse the repository at this point in the history
* 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 <christopher.s.dickinson@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
jasnell authored and Myles Borins committed Jan 19, 2016
1 parent d87ad30 commit 61f91b2
Show file tree
Hide file tree
Showing 30 changed files with 613 additions and 614 deletions.
18 changes: 9 additions & 9 deletions doc/api/addons.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ You can now use the binary addon in a Node.js project `hello.js` by pointing
`require` to the recently built `hello.node` module:

// hello.js
var addon = require('./build/Release/addon');
const addon = require('./build/Release/addon');

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

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

// test.js
var addon = require('./build/Release/addon');
const addon = require('./build/Release/addon');

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

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

// test.js
var addon = require('./build/Release/addon');
const addon = require('./build/Release/addon');

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

// test.js
var addon = require('./build/Release/addon');
const addon = require('./build/Release/addon');

var obj1 = addon('hello');
var obj2 = addon('world');
Expand Down Expand Up @@ -336,7 +336,7 @@ wraps a C++ function:
To test:

// test.js
var addon = require('./build/Release/addon');
const addon = require('./build/Release/addon');

var fn = addon();
console.log(fn()); // 'hello world'
Expand Down Expand Up @@ -470,7 +470,7 @@ prototype:
Test it with:

// test.js
var addon = require('./build/Release/addon');
const addon = require('./build/Release/addon');

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

// test.js
var createObject = require('./build/Release/addon');
const createObject = require('./build/Release/addon');

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

// test.js
var addon = require('./build/Release/addon');
const addon = require('./build/Release/addon');

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

// test.js
var addon = require('./build/Release/addon');
const addon = require('./build/Release/addon');

[online]: https://v8docs.nodesource.com/
[libuv]: https://github.com/libuv/libuv
Expand Down
14 changes: 7 additions & 7 deletions doc/api/assert.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ assertion.

assert.doesNotThrow(
function() {
throw new TypeError("Wrong value");
throw new TypeError('Wrong value');
},
SyntaxError
);
Expand All @@ -51,7 +51,7 @@ is thrown instead.

assert.doesNotThrow(
function() {
throw new TypeError("Wrong value");
throw new TypeError('Wrong value');
},
TypeError
);
Expand Down Expand Up @@ -102,7 +102,7 @@ Validate instanceof using constructor:

assert.throws(
function() {
throw new Error("Wrong value");
throw new Error('Wrong value');
},
Error
);
Expand All @@ -111,7 +111,7 @@ Validate error message using [`RegExp`][]:

assert.throws(
function() {
throw new Error("Wrong value");
throw new Error('Wrong value');
},
/value/
);
Expand All @@ -120,19 +120,19 @@ Custom error validation:

assert.throws(
function() {
throw new Error("Wrong value");
throw new Error('Wrong value');
},
function(err) {
if ( (err instanceof Error) && /value/.test(err) ) {
return true;
}
},
"unexpected error"
'unexpected error'
);

[`assert.deepEqual`]: #assert_assert_deepequal_actual_expected_message
[`assert.deepStrictEqual`]: #assert_assert_deepstrictequal_actual_expected_message
[`assert.throws()`]: #assert_assert_throws_block_error_message
[`Error`]: errors.html#errors_class_error
[`RegExp`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
[`TypeError`]: errors.html#errors_class_typeerror
[`TypeError`]: errors.html#errors_class_typeerror
12 changes: 6 additions & 6 deletions doc/api/buffer.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ Example:

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

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

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

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

var b = new Buffer(50);
b.fill("h");
b.fill('h');

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

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

console.log(buf.length);
buf.write("some string", 0, "ascii");
buf.write('some string', 0, 'ascii');
console.log(buf.length);

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

buf = new Buffer(10);
buf.write("abcdefghj", 0, "ascii");
buf.write('abcdefghj', 0, 'ascii');
console.log(buf.length); // 10
buf = buf.slice(0,5);
console.log(buf.length); // 5
Expand Down Expand Up @@ -639,7 +639,7 @@ The method will not write partial characters.

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

### buf.writeDoubleBE(value, offset[, noAssert])
### buf.writeDoubleLE(value, offset[, noAssert])
Expand Down
Loading

0 comments on commit 61f91b2

Please sign in to comment.