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: clarify the parameter byteOffset for lastIndexOf method of Buffer #38167

Closed
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
6 changes: 3 additions & 3 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -1405,9 +1405,9 @@ changes:
-->

* `value` {string|Buffer|Uint8Array|integer} What to search for.
* `byteOffset` {integer} Where to begin searching in `buf`. If negative, then
offset is calculated from the end of `buf`. **Default:**
`buf.length - 1`.
* `byteOffset` {integer} The index of the last byte in `buf` to be considered
as the beginning of a match. If negative, then offset is calculated
Comment on lines +1408 to +1409
Copy link
Contributor

@DerekNonGeneric DerekNonGeneric May 2, 2021

Choose a reason for hiding this comment

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

Suggested change
* `byteOffset` {integer} The index of the last byte in `buf` to be considered
as the beginning of a match. If negative, then offset is calculated
* `byteOffset` {integer} The last zero-based index (in bytes) of `buf` to be
considered as the beginning of a match. If negative, then offset is calculated

My 2¢, but given that Buffer is a subclass of Uint8Array, we may be able to use some of the language used by MDN if it's more suitable.

The Buffer class is a subclass of JavaScript's Uint8Array class and extends it with methods that cover additional use cases.

See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/byteOffset

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I find the proposed wording harder to understand, but maybe that's just me. Do others think it is either more precise or easier to read? @nodejs/documentation

I was inspired by the documentation concerning the lastIndexOf method of string (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf)) but we can also draw inspiration from the documentation of TypedArray (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/lastIndexOf) as suggested by @DerekNonGeneric

from the end of `buf`. **Default:** `buf.length - 1`.
* `encoding` {string} If `value` is a string, this is the encoding used to
determine the binary representation of the string that will be searched for in
`buf`. **Default:** `'utf8'`.
Expand Down