mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
buffer: add includes() for parity with TypedArray
Add Buffer#includes() by wrapping an indexOf and performing a strict equals check to -1. The includes method takes the search value, byteOffset, and encoding as arguments. The test is a modified version of the indexOf test. Fixes: https://github.com/nodejs/node/issues/3552 PR-URL: https://github.com/nodejs/node/pull/3567 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
23e7703c85
commit
67e181986a
3 changed files with 274 additions and 0 deletions
|
@ -488,6 +488,11 @@ Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) {
|
|||
};
|
||||
|
||||
|
||||
Buffer.prototype.includes = function includes(val, byteOffset, encoding) {
|
||||
return this.indexOf(val, byteOffset, encoding) !== -1;
|
||||
};
|
||||
|
||||
|
||||
Buffer.prototype.fill = function fill(val, start, end) {
|
||||
start = start >> 0;
|
||||
end = (end === undefined) ? this.length : end >> 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue