Replace matches in a Buffer
$ npm install replace-buffer
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!'
Returns a new Buffer
with all needle matches replaced with replacement.
Type: Buffer
Buffer
to work on.
Type: string
String to match in input
.
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'
Type: Object
Type: number
Default: 0
Index at which to start replacing.
- splice-buffer - Remove or replace part of a
Buffer
likeArray#splice
MIT © Kevin Mårtensson