Skip to content

Commit

Permalink
generate docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed May 6, 2016
1 parent 0b153ee commit c3c0958
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,43 @@ npm i callback2stream --save
const callback2stream = require('callback2stream')
```

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

* `fn` **{Function}**: Any kind of function.
* `opts` **{Object}**: Directly passed to [promise2stream][] package.
* `returns` **{Stream}**: 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)
```

## 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.
Expand All @@ -24,6 +61,9 @@ But before doing anything, please read the [CONTRIBUTING.md](./CONTRIBUTING.md)

[![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

Expand Down
37 changes: 37 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,43 @@ var letta = require('letta')
var handle = require('handle-arguments')
var promise2stream = require('promise2stream')

/**
* > Create a stream from sync, async or generator function.
*
* **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)
* ```
*
* @param {Function} `fn` Any kind of function.
* @param {Object} `opts` Directly passed to [promise2stream][] package.
* @return {Stream} Transform stream, coming from [promise2stream][] using [through2][]
* @api public
*/

module.exports = function callback2stream (fn, opts) {
var self = this
return function () {
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
],
"lint": {
"reflinks": true
}
},
"reflinks": [
"promise2stream",
"through2"
]
}
}
}

0 comments on commit c3c0958

Please sign in to comment.