# stream-when

> Create a Promise that will resolve when a stream's data passes a callback

Latest version **1.0.0** (published 2015-11-03) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install stream-when
pnpm add stream-when
yarn add stream-when
bun add stream-when
```

## 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.0 |
| Published | 2015-11-03 |
| First published | 2015-11-03 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Matthew Phillips |
| Maintainers | matthewp |
| Keywords | Promise, streams |

## Links

- npm: https://www.npmjs.com/package/stream-when
- Repository: https://github.com/matthewp/stream-when
- Homepage: https://github.com/matthewp/stream-when#readme
- Issues: https://github.com/matthewp/stream-when/issues
- npm.io page: https://npm.io/package/stream-when

## 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.0 (latest) — 2015-11-03

## README

[![Build Status](https://travis-ci.org/matthewp/stream-when.svg?branch=master)](https://travis-ci.org/matthewp/stream-when)

# stream-when

Create a Promise that will resolve when a [Stream](https://nodejs.org/api/stream.html)'s `data` event passes a condition.

## Install

```
npm install stream-when --save
```

## Use

### Function

Pass a callback function that will checked on each data event.

```js
var child = spawn("echo", ["hello"]);
child.stdout.setEncoding("utf8");
var promise = streamWhen(child.stdout, function(data){
  return data.trim() === "hello";
});

promise.then(function(){
  // All done
});
```

### RegExp

Pass a Regular Expression that will be used to test.

```js
var child = spawn("echo", ["hello"]);
child.stdout.setEncoding("utf8");
var promise = streamWhen(child.stdout, /hello/);

promise.then(function(){
  // All done!
});
```
### String

Pass a string value which will be converted into a RegExp.

```js
var child = spawn("echo", ["hello"]);
child.stdout.setEncoding("utf8");
var promise = streamWhen(child.stdout, "hello");

promise.then(function(){
  // All done@
});
```

## License

BSD 2 Clause

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