# through1

> A simple utility for creating 1 to 1 transform stream.

Latest version **1.0.1** (published 2018-02-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install through1
pnpm add through1
yarn add through1
bun add through1
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-02-25 |
| First published | 2018-02-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Yoshiya Hinosawa |
| Maintainers | kt3k |
| Keywords | through, stream, node |

## Links

- npm: https://www.npmjs.com/package/through1
- Repository: https://github.com/kt3k/through1
- Homepage: https://github.com/kt3k/through1#readme
- Issues: https://github.com/kt3k/through1/issues
- npm.io page: https://npm.io/package/through1

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-02-25
- 1.0.0 — 2018-02-24

## README

# :one::aquarius::one: through1 v1.0.1

[![CircleCI](https://circleci.com/gh/kt3k/through1.svg?style=svg)](https://circleci.com/gh/kt3k/through1)
[![codecov](https://codecov.io/gh/kt3k/through1/branch/master/graph/badge.svg)](https://codecov.io/gh/kt3k/through1)

> A simple utility for creating 1 to 1 transform stream.

# :cd: 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:

```js
new Transform({
  transform (chunk, enc, cb) {
    ...
  }
})
```

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.

# :memo: Usage

```js
const through1 = require('through1')
```

If you transform the input **synchronously**, then return the transformed output:

```js
// byte stream
// synchronous transform
through1((chunk, enc) => myTransformFunc(chunk, enc))
```

If you work on the **object mode** stream (for example, like [gulp][]'s stream), then use `.obj` shorthand:

```js
// object stream
// synchronous transform
through1.obj(file => myTransformFunc(func))
```

## Asynchronous use case

If your transformation is asynchronous, then return the promise:

```js
// byte stream
// asynchronous transform
through1((chunk, enc) => myTransformPromise(chunk, enc))
```

If you work on **object mode**:

```js
// object stream
// asynchronous transform
through1.obj(file => myTransformPromise(file))
```

# 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](https://gist.github.com/kt3k/4cab6a63514381027f47046572d8d7ec)

# License

MIT

[through2]: https://npm.im/through2
[gulp]: https://npm.im/gulp
[map-stream]: https://npm.im/map-stream
[gulp-map]: https://npm.im/gulp-map

---
_Source: https://npm.io/package/through1 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
