# callback2stream

> Transform sync, async or generator function to Stream. Correctly handle errors and optional arguments.

Latest version **1.0.1** (published 2016-05-06) · MIT license · 0 weekly downloads

## Install

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

## 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 | 2016-05-06 |
| First published | 2016-05-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Charlike Mike Reagent |
| Maintainers | tunnckocore |
| Keywords | args, arguments, async, asynchronous, callback, callback-stream, cb, correct, create, fn, function, generator, generators, letta, make, optional, promisify, relike, stream, streamify, sync, synchronous, to, to-stream, tranform, value |

## Links

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

## Dependencies (4)

- [letta](https://npm.io/package/letta.md) ^0.4.0
- [lazy-cache](https://npm.io/package/lazy-cache.md) ^2.0.1
- [promise2stream](https://npm.io/package/promise2stream.md) ^1.0.0
- [handle-arguments](https://npm.io/package/handle-arguments.md) ^3.1.0

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2016-05-06
- 1.0.0 — 2016-05-06
- 0.2.0 — 2016-05-06
- 0.1.0 — 2016-05-06

## README

# [callback2stream][author-www-url] [![npmjs.com][npmjs-img]][npmjs-url] [![The MIT License][license-img]][license-url] [![npm downloads][downloads-img]][downloads-url] 

> Transform sync, async or generator function to Stream. Correctly handle errors and optional arguments.

[![code climate][codeclimate-img]][codeclimate-url] [![standard code style][standard-img]][standard-url] [![travis build status][travis-img]][travis-url] [![coverage status][coveralls-img]][coveralls-url] [![dependency status][david-img]][david-url]

## Install
```
npm i callback2stream --save
```

## Usage
> For more use-cases see the [tests](./test.js)

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

### [callback2stream](index.js#L50)
> Create a stream from sync, async or generator function.

**Params**

* `fn` **{Function}**: Any kind of function.    
* `opts` **{Object}**: Directly passed to [through2][] from [promise2stream][].    
* `returns` **{Function}**: That when executed, returns transform stream, coming from [promise2stream][], using [through2][].  

**Example**

```js
var fs = require('fs')
var cb2stream = require('callback2stream')

var readFileStream = cb2stream(fs.readFile)
var stream = readFileStream('package.json', 'utf8')
stream
  .on('data', function (val) {
    var json = JSON.parse(val)
    console.log(json.name) // => 'callback2stream'
  })
  .once('error', console.error)
  .once('end', function () {
    console.log('reading finished')
  })

// you also have access to the
// contents with promise
stream.promise
  .then(JSON.parse, console.error)
  .then(function (val) {
    console.log(val.name) // => 'callback2stream'
  }, console.error)
  .catch(console.error)
```

## Related
* [letta](https://www.npmjs.com/package/letta): Let's move to promises! Drop-in replacement for `co@4` (passing 100% tests), but… [more](https://www.npmjs.com/package/letta) | [homepage](https://github.com/hybridables/letta)
* [limon](https://www.npmjs.com/package/limon): The pluggable JavaScript lexer. Limon = Lemon. | [homepage](https://github.com/limonjs/limon)
* [postjson](https://www.npmjs.com/package/postjson): Transforming JSON with plugins. | [homepage](https://github.com/postjson/postjson)
* [promise2stream](https://www.npmjs.com/package/promise2stream): Transform ES2015 Promise to Stream - specifically, Transform Stream. [homepage](https://github.com/hybridables/promise2stream)
* [promise2thunk](https://www.npmjs.com/package/promise2thunk): Convert (transform) promise to thunk, just like was in co@3 | [homepage](https://github.com/tunnckocore/promise2thunk)
* [relike](https://www.npmjs.com/package/relike): Simple promisify a callback-style function with sane defaults. Support promisify-ing sync functions. | [homepage](https://github.com/hybridables/relike)
* [stream-from-promise](https://www.npmjs.com/package/stream-from-promise): Create streams from promises | [homepage](https://github.com/schnittstabil/stream-from-promise)
* [stream-to-promise](https://www.npmjs.com/package/stream-to-promise): Convert streams (readable or writable) to promises | [homepage](https://github.com/bendrucker/stream-to-promise)
* [through2](https://www.npmjs.com/package/through2): A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise | [homepage](https://github.com/rvagg/through2)
* [thunk2promise](https://www.npmjs.com/package/thunk2promise): Transform or convert thunk to Bluebird Promise. | [homepage](https://github.com/tunnckocore/thunk2promise)
* [value2stream](https://www.npmjs.com/package/value2stream): Transform any value to stream. Create stream from any value - string,… [more](https://www.npmjs.com/package/value2stream) | [homepage](https://github.com/hybridables/value2stream)

## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/hybridables/callback2stream/issues/new).  
But before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines.

## [Charlike Make Reagent](http://j.mp/1stW47C) [![new message to charlike][new-message-img]][new-message-url] [![freenode #charlike][freenode-img]][freenode-url]

[![tunnckoCore.tk][author-www-img]][author-www-url] [![keybase tunnckoCore][keybase-img]][keybase-url] [![tunnckoCore npm][author-npm-img]][author-npm-url] [![tunnckoCore twitter][author-twitter-img]][author-twitter-url] [![tunnckoCore github][author-github-img]][author-github-url]

[promise2stream]: https://github.com/hybridables/promise2stream
[through2]: https://github.com/rvagg/through2

[npmjs-url]: https://www.npmjs.com/package/callback2stream
[npmjs-img]: https://img.shields.io/npm/v/callback2stream.svg?label=callback2stream

[license-url]: https://github.com/hybridables/callback2stream/blob/master/LICENSE
[license-img]: https://img.shields.io/npm/l/callback2stream.svg

[downloads-url]: https://www.npmjs.com/package/callback2stream
[downloads-img]: https://img.shields.io/npm/dm/callback2stream.svg

[codeclimate-url]: https://codeclimate.com/github/hybridables/callback2stream
[codeclimate-img]: https://img.shields.io/codeclimate/github/hybridables/callback2stream.svg

[travis-url]: https://travis-ci.org/hybridables/callback2stream
[travis-img]: https://img.shields.io/travis/hybridables/callback2stream/master.svg

[coveralls-url]: https://coveralls.io/r/hybridables/callback2stream
[coveralls-img]: https://img.shields.io/coveralls/hybridables/callback2stream.svg

[david-url]: https://david-dm.org/hybridables/callback2stream
[david-img]: https://img.shields.io/david/hybridables/callback2stream.svg

[standard-url]: https://github.com/feross/standard
[standard-img]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg

[author-www-url]: http://www.tunnckocore.tk
[author-www-img]: https://img.shields.io/badge/www-tunnckocore.tk-fe7d37.svg

[keybase-url]: https://keybase.io/tunnckocore
[keybase-img]: https://img.shields.io/badge/keybase-tunnckocore-8a7967.svg

[author-npm-url]: https://www.npmjs.com/~tunnckocore
[author-npm-img]: https://img.shields.io/badge/npm-~tunnckocore-cb3837.svg

[author-twitter-url]: https://twitter.com/tunnckoCore
[author-twitter-img]: https://img.shields.io/badge/twitter-@tunnckoCore-55acee.svg

[author-github-url]: https://github.com/tunnckoCore
[author-github-img]: https://img.shields.io/badge/github-@tunnckoCore-4183c4.svg

[freenode-url]: http://webchat.freenode.net/?channels=charlike
[freenode-img]: https://img.shields.io/badge/freenode-%23charlike-5654a4.svg

[new-message-url]: https://github.com/tunnckoCore/ama
[new-message-img]: https://img.shields.io/badge/ask%20me-anything-green.svg

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