talira

through2

Tiny helpers for transform streams in Node.js and Web Streams

open sourceMITfree

through2 lets you write a transform step for a stream as a plain function instead of subclassing Transform. Its transform, objectTransform and transformer helpers take callback-style functions, async functions or async generators and return Node.js stream instances, and its through2/web entry point does the same for the Web Streams API's TransformStream. The README has recipes for map, filter, flatMap, batching, tapping and parsing newline-delimited input. Rod Vagg maintains it.

Problems it solves

  • write a Node.js transform stream without subclassing Transform
  • map or filter chunks in a stream pipeline
  • add a transform step to a Web Streams pipeline

Features

  • transform, objectTransform and transformer helpers for Node.js streams
  • accepts callback, async-function and async-generator transforms
  • through2/web for Web Streams pipelines
  • README recipes for map, filter, flatMap, batch, tap and NDJSON parsing

Limitations

  • Version 5 ships as ESM: CommonJS require() needs Node.js 22.12 or newer, or stay on through2@4.1