Socket
Socket
Sign inDemoInstall

buffer-indexof-polyfill

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

buffer-indexof-polyfill

This is a polyfill for Buffer#indexOf introduced in NodeJS 4.0.


Version published
Maintainers
1
Weekly downloads
2,611,563
decreased by-12.6%

Weekly downloads

Package description

What is buffer-indexof-polyfill?

The buffer-indexof-polyfill npm package provides a polyfill for the `indexOf` method on Buffer instances in Node.js. This is particularly useful for environments or versions of Node.js where `Buffer.indexOf` is not available. It allows developers to search for sequences within buffer objects, similar to how strings are searched in JavaScript.

What are buffer-indexof-polyfill's main functionalities?

Finding the index of a string within a buffer

This feature allows you to find the first occurrence of a string within a buffer. The code sample demonstrates searching for the string 'world' within a buffer containing 'hello world', which returns the index 6, indicating the start of the match.

var indexOf = require('buffer-indexof-polyfill');
var buf = Buffer.from('hello world');
var index = indexOf(buf, 'world');
console.log(index); // Outputs: 6

Finding the index of a buffer within another buffer

This feature enables searching for a sequence of bytes (represented by a buffer) within another buffer. The example shows how to find a buffer containing 'world' within another buffer, yielding the same result as searching for a string.

var indexOf = require('buffer-indexof-polyfill');
var buf = Buffer.from('hello world');
var search = Buffer.from('world');
var index = indexOf(buf, search);
console.log(index); // Outputs: 6

Other packages similar to buffer-indexof-polyfill

Readme

Source

buffer-indexof-polyfill

Build Status NPM Version NPM Downloads

This is a polyfill for Buffer#indexOf and Buffer#lastIndexOf introduced in NodeJS 4.0.

Example

require("buffer-indexof-polyfill");

new Buffer("buffer").indexOf("uff") // return 1
new Buffer("buffer").indexOf("abc") // return -1

Installation

npm install buffer-indexof-polyfill

License

MIT

Keywords

FAQs

Last updated on 09 Sep 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc