@nlib/replace-stream

Transform streams

Stats

StarsIssuesVersionUpdatedCreatedSize
@nlib/replace-stream
001.0.14 years ago4 years agoMinified + gzip package size for @nlib/replace-stream in KB

Readme

@nlib/replace-stream

Build Status Build status codecov dependencies Status devDependencies Status

Transform streams.

Install

npm install @nlib/replace-stream

Usage

const {PassThrough} = require('stream');
const {ReplaceStream} = require('@nlib/replace-stream');
const stream = new PassThrough();
const chunks = [];
stream.pipe(new ReplaceStream([
  {
    pattern: 'foo',
    replacement: 'FOO',
  },
  {
    pattern: /ba+r/,
    replacement: 'BAR',
    limit: 2
  },
]))
.on('data', (chunk) => {
  chunks.push(chunk);
})
.once('end', () => {
  console.log(Buffer.concat(chunks).toString());
  // FOOfooBARBARbaaar
});
for (const byte of Buffer.from('foofoobarbaarbaaar')) {
  stream.write(Buffer.from([byte]));
}
stream.end();
const {PassThrough} = require('stream');
const {ReplaceStream} = require('@nlib/replace-stream');
const stream = new PassThrough();
const chunks = [];
stream.pipe(new ReplaceStream([
  {
    pattern: '😀',
    replacement: '😎',
  },
]))
.on('data', (chunk) => {
  chunks.push(chunk);
})
.once('end', () => {
  console.log(Buffer.concat(chunks).toString());
  // 😎😁😂
});
for (const byte of Buffer.from('😀😁😂')) {
  stream.write(Buffer.from([byte]));
}
stream.end();

LICENSE

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.