-
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
Add Buffer#includes() #3552
Comments
TypedArray#includes and Array#includes are not shipped in V8 yet. % node -v
v5.0.0-rc.1
% node --harmony
> var buffer = new Buffer(1).fill(1)
undefined
> buffer.includes(1)
true |
Though we might want to override it. v8's implementation (following the spec) is restrictive and slow. e.g. |
@trevnorris good point! Then we can just wrap it around |
Oh yeah. Good call. Easy PR for the taking. |
I made a polyfill: https://github.com/sindresorhus/buffer-includes |
Just added a PR to implement this. |
PR is #3567 |
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: #3552 PR-URL: #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>
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: nodejs#3552 PR-URL: nodejs#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>
For convenience, code clarity, and parity with
TypedArray
. SeeTypedArray#includes()
.The text was updated successfully, but these errors were encountered: