Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/RangerMauve/through2-map-promise
A small promise-based wrapper for through2
https://github.com/RangerMauve/through2-map-promise
Last synced: about 2 months ago
JSON representation
A small promise-based wrapper for through2
- Host: GitHub
- URL: https://github.com/RangerMauve/through2-map-promise
- Owner: RangerMauve
- License: isc
- Created: 2016-02-23T15:21:16.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-25T14:13:44.000Z (over 6 years ago)
- Last Synced: 2024-04-22T04:13:06.147Z (2 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-micro-npm-packages - through2-map-promise - A small promise-based wrapper for through2. (Modules / Stream)
- awesome-micro-npm-packages - through2-map-promise - A small promise-based wrapper for through2. (Modules / Stream)
README
# through2-map-promise
A small promise-based wrapper for through2. Allows you to easily map over data in a stream while using promises for flow control.## Quickstart
```
npm install --save through2-map-promise
``````javascript
var map = require("through2-map-promise");
var xtend = require("xtend");// in an HTTP request handler
db.users.find({}).pipe(map.obj(function(user){
var locationId = user.location;
return db.locations.findOne({_id: locationId}).then(function(location){
return xtend(user, {
location: location
});
});
})).pipe(response);
```## API
### `through2-map-promise([options,] [fn])`
Creates a transform stream which calls your transforming function, `fn`. You can throw within your function to automatically reject the promise and error-out the stream. `options` is the optional object that gets passed into [through2](https://github.com/rvagg/through2#options).### `through2-map-promise.obj([options,] [fn])`
Same as the former, but the stream is created in objectMode### `through2-map-promise.ctor([options,] [fn])`
Creates a constructor for your transform stream in case you want to be more efficient