Socket
Socket
Sign inDemoInstall

replace-buffer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

replace-buffer

Replace matches in a Buffer


Version published
Weekly downloads
20K
decreased by-13%
Maintainers
1
Weekly downloads
 
Created
Source

replace-buffer Build Status

Replace matches in a Buffer

Install

$ npm install replace-buffer

Usage

const replaceBuffer = require('replace-buffer');

const input = Buffer.from('My friend has a dog. I want a dog too!');

replaceBuffer(input, 'dog', 'unicorn').toString();
//=> 'My friend has a unicorn. I want a unicorn too!'

API

replaceBuffer(input, needle, replacement, [options])

Returns a new Buffer with all needle matches replaced with replacement.

input

Type: Buffer

Buffer to work on.

needle

Type: string

String to match in input.

replacement

Type: string Function

Replacement for needle matches.

If a function, it receives the following arguments; the needle, the match count, and the input:

replaceBuffer(Buffer.from('Foo Unicorn Bar'), 'Unicorn', (needle, matchCount, input) => `${needle}❤️`);
//=> 'Foo Unicorn❤️ Bar'
options

Type: Object

fromIndex

Type: number
Default: 0

Index at which to start replacing.

License

MIT © Kevin Mårtensson

Keywords

FAQs

Package last updated on 15 Aug 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc