# stream-iterators-utils

> An utility belt for working with streams using async iterators

Latest version **0.1.1** (published 2019-04-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install stream-iterators-utils
pnpm add stream-iterators-utils
yarn add stream-iterators-utils
bun add stream-iterators-utils
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2019-04-15 |
| First published | 2018-11-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Matteo Collina |
| Maintainers | matteo.collina |
| Keywords | stream, async, iterator |

## Links

- npm: https://www.npmjs.com/package/stream-iterators-utils
- npm.io page: https://npm.io/package/stream-iterators-utils

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

- 0.1.1 (latest) — 2019-04-15
- 0.1.0 — 2018-11-20

## README

# Stream Iterators Utils

[![Build Status](https://travis-ci.com/mcollina/stream-iterators-utils.svg?branch=master)](https://travis-ci.com/mcollina/stream-iterators-utils)

This is a toolbelt of functions to facilitate the usage of async
iterators with Streams in Node.js. Requires Node 10+.

## Install

```
npm i stream-iterators-utils
```

## API

### utils.toReadable(generator, opts)

Create a new `Readable` stream from the async generator. `opts` are
passed to the `Readable` constructor

```js
const { toReadable } = require('stream-iterators-utils')

async function * generate () {
  yield 'a'
  yield 'b'
  yield 'c'
}

const stream = toReadable(generate(), { objectMode: true })

stream.on('data', (chunk) => {
  console.log(chunk)
})
```

### utils.once(emitter, event)

Creates a promise that is resolved when the `EventEmitter` emits the
given event or `'error'`.

```js
const { once } = require('stream-iterators-utils')

async function run () {
  const ee = new EventEmitter()

  process.nextTick(() => {
    ee.emit('myevent', 42)
  })

  const [value] = await once(ee, 'myevent')

  const err = new Error('kaboom')
  process.nextTick(() => {
    ee.emit('error', err)
  })

  try {
    await once(ee, 'myevent')
  } catch (err) {
    console.log('error happened', err)
  }
}

run()
```

## License

MIT

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