Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Document buffer.indexOf changes in v4.2.0 #3373

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions doc/api/buffer.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -490,17 +490,21 @@ Buffer. The method returns a reference to the Buffer so calls can be chained.
console.log(b.toString());
// Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

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

* `value` String, Buffer or Number
* `byteOffset` Number, Optional, Default: 0
* `encoding` String, Optional, Default: `utf8`
* Return: Number

Operates similar to [`Array#indexOf()`][] in that it returns either the
starting index position of `value` in Buffer or `-1` if the Buffer does not
contain `value`. The `value` can be a String, Buffer or Number. Strings are
interpreted as UTF8. Buffers will use the entire Buffer (to compare a partial
Buffer use [`Buffer#slice()`][]). Numbers can range from 0 to 255.
contain `value`.
The `value` can be a String, Buffer or Number.
Strings are by default interpreted as UTF8.
Buffers will use the entire Buffer (to compare a partial
Buffer use [`Buffer#slice()`][]).
Numbers can range from 0 to 255.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this amount of linebreaks really necessary?


const buf = new Buffer('this is a buffer');

Expand All @@ -517,6 +521,11 @@ Buffer use [`Buffer#slice()`][]). Numbers can range from 0 to 255.
buf.indexOf(new Buffer('a buffer example').slice(0,8));
// returns 8

const utf16Buffer = new Buffer('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2');

assert.equal(4, utf16Buffer.indexOf('\u03a3', 0, 'ucs2'), 'First Sigma');
assert.equal(6, utf16Buffer.indexOf('\u03a3', -4, 'ucs2'), 'Second Sigma');

### buf.includes(value[, byteOffset][, encoding])

* `value` String, Buffer or Number
Expand Down