1.0.1 • Published 6 years ago

@nlib/replace-stream v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

@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

1.0.1

6 years ago

1.0.0

6 years ago