1.0.6 • Published 3 years ago

simple-transform-stream v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Simple Transform Stream

Transform a stream with messages separated with valid JSON strings into another stream with transformed JSON strings.

If you think I've missed something, be sure to open an issue or submit a pull request.

Installation

First install the simple-transform-stream library:

  $ npm i simple-transform-stream

Usage

To get the transform stream object:

const transformStream = require('transformStream');
const inputStream = createJSONStream();
/* Input have a stream of valid JSON objects
  { value: 1, type: 'begin' }\n
  { value: 2, type: 'hit' }\n
  { value: 3, type: 'hit' }\n
  { value: 4, type: 'end' }\n
  null
*/
const onMessage = async (message) => ({
  ...message,
  value: message.value * 2
});
const onFailure = (error, message) => console.error(error, message);
const transformedStream = transformStream({
  stream: inputStream,
  onMessage,
  onFailure
});
/* New transformed stream have values
  { value: 2, type: 'begin' }\n
  { value: 4, type: 'hit' }\n
  { value: 6, type: 'hit' }\n
  { value: 8, type: 'end' }\n
  null
*/

License

MIT

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago