-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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: add Buffer.lastIndexOf #4933
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -593,6 +593,46 @@ for (var key of buf.keys()) { | |
// 5 | ||
``` | ||
|
||
### buf.lastIndexOf(value[, byteOffset][, encoding]) | ||
|
||
* `value` {String|Buffer|Number} | ||
* `byteOffset` {Number} Default: `buf.length` | ||
* `encoding` {String} Default: `'utf8'` | ||
* Return: {Number} | ||
|
||
Identical to [`Buffer#indexOf()`][], but searches the Buffer from back to front | ||
instead of front to back. Returns 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 by default interpreted as UTF8. If | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UTF**-**8 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also you should need to mention the default encoding at all since it is listed above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's rendered "UTF8" everywhere else in this file. I think this is fine. |
||
`byteOffset` is provided, will return the last match that begins at or before | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. first match that begins at ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is |
||
`byteOffset`. | ||
|
||
```js | ||
const buf = new Buffer('this buffer is a buffer'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add const Buffer = require('buffer').Buffer; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it needed for the linter ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The linter does complain about it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tflanagan no other code sample in this doc does that which linter are you talking about? |
||
|
||
buf.lastIndexOf('this'); | ||
// returns 0 | ||
buf.lastIndexOf('buffer'); | ||
// returns 17 | ||
buf.lastIndexOf(new Buffer('buffer')); | ||
// returns 17 | ||
buf.lastIndexOf(97); // ascii for 'a' | ||
// returns 15 | ||
buf.lastIndexOf(new Buffer('yolo')); | ||
// returns -1 | ||
buf.lastIndexOf('buffer', 5) | ||
// returns 5 | ||
buf.lastIndexOf('buffer', 4) | ||
// returns -1 | ||
|
||
const utf16Buffer = new Buffer('\u039a\u0391\u03a3\u03a3\u0395', 'ucs2'); | ||
|
||
utf16Buffer.lastIndexOf('\u03a3', null, 'ucs2'); | ||
// returns 6 | ||
utf16Buffer.lastIndexOf('\u03a3', -5, 'ucs2'); | ||
// returns 4 | ||
``` | ||
|
||
### buf.length | ||
|
||
* {Number} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can simply write these two lines as