1️⃣♒️1️⃣ through1 v1.0.1
A simple utility for creating 1 to 1 transform stream.
💿 Install
Via npm:
npm i through1
Motivation
In the the most use cases, transforms are 1 to 1 transform, which means that it generates one output for each input. The official transform constructor is too complex for this usage. It has the following signature:
{ ... }
This supports one to N transform, where N is 0, 1, 2, or any arbitrary positive integer. This is too much for 1 to 1 transform.
through1
provides simpler interface for creating 1 to 1 transform.
📝 Usage
const through1 =
If you transform the input synchronously, then return the transformed output:
// byte stream// synchronous transform
If you work on the object mode stream (for example, like gulp's stream), then use .obj
shorthand:
// object stream// synchronous transformthrough1
Asynchronous use case
If your transformation is asynchronous, then return the promise:
// byte stream// asynchronous transform
If you work on object mode:
// object stream// asynchronous transformthrough1
Comparison
through1 | map-stream | gulp-map | |
---|---|---|---|
object mode support | ✅ | ✅ | ✅ |
non object mode support | ✅ | ✅ | ❌ |
promise support | ✅ | ❌ | ✅ |
stream version | stream 2 | stream 1 | stream 2 |
back-pressure support | ✅ | ❌ | ✅ |
dependencies | 0 | 0 | 9 |
License
MIT