Comparing version 1.1.0 to 1.2.0
14
index.js
'use strict'; | ||
const pMap = require('p-map'); | ||
const map = input => { | ||
return Promise.all(input.values()).then(values => { | ||
const map = (input, mapper, options) => { | ||
return pMap(input.entries(), entry => mapper(entry[1], entry[0]), options).then(values => { | ||
const ret = new Map(); | ||
@@ -17,7 +18,7 @@ | ||
const obj = input => { | ||
const obj = (input, mapper, options) => { | ||
// TODO: use `Object.entries()` when targeting Node.js 6 | ||
const keys = Object.keys(input); | ||
return Promise.all(keys.map(key => input[key])).then(values => { | ||
return pMap(keys, key => mapper(input[key], key), options).then(values => { | ||
const ret = {}; | ||
@@ -40,2 +41,5 @@ | ||
module.exports = input => input instanceof Map ? map(input) : obj(input); | ||
module.exports = (input, mapper, options) => { | ||
mapper = mapper || (value => value); | ||
return input instanceof Map ? map(input, mapper, options) : obj(input, mapper, options); | ||
}; |
{ | ||
"name": "p-props", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Like `Promise.all()` but for `Map` and `Object`", | ||
@@ -38,2 +38,5 @@ "license": "MIT", | ||
], | ||
"dependencies": { | ||
"p-map": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
@@ -40,0 +43,0 @@ "ava": "*", |
@@ -39,5 +39,5 @@ # p-props [![Build Status](https://travis-ci.org/sindresorhus/p-props.svg?branch=master)](https://travis-ci.org/sindresorhus/p-props) | ||
### pProps(input) | ||
### pProps(input, [mapper], [options]) | ||
Returns a `Promise` that is fulfilled when all promises in `input` are fulfilled, or rejects if any of the promises reject. The fulfilled value is the same as `input`, but with a fulfilled version of each entry value. | ||
Returns a `Promise` that is fulfilled when all promises in `input` and ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. The fulfilled value is the same as `input`, but with a fulfilled version of each entry value, or the fulfilled value returned from `mapper`, if defined. | ||
@@ -50,3 +50,14 @@ #### input | ||
#### mapper(element, index) | ||
Type: `Function` | ||
Expected to return a `Promise` or value. | ||
#### options | ||
Type: `Object` | ||
See the [`p-map` options](https://github.com/sindresorhus/p-map#options). | ||
## Related | ||
@@ -53,0 +64,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4795
34
71
1
+ Addedp-map@^1.2.0
+ Addedp-map@1.2.0(transitive)