p-map-series
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -1,14 +0,66 @@ | ||
/** | ||
Map over promises serially. | ||
declare const pMapSeries: { | ||
/** | ||
Map over promises serially. | ||
@param input - Mapped over serially in the `mapper` function. | ||
@param mapper - Expected to return a value. If it's a `Promise`, it's awaited before continuing with the next iteration. | ||
@returns Fulfills when all promises in `input` and ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. | ||
*/ | ||
export default function pMapSeries<ValueType, MappedValueType>( | ||
input: Iterable<PromiseLike<ValueType> | ValueType>, | ||
mapper: ( | ||
element: ValueType, | ||
index: number | ||
) => PromiseLike<MappedValueType> | MappedValueType | ||
): Promise<MappedValueType[]>; | ||
@param input - Mapped over serially in the `mapper` function. | ||
@param mapper - Expected to return a value. If it's a `Promise`, it's awaited before continuing with the next iteration. | ||
@returns Fulfills when all promises in `input` and ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. | ||
@example | ||
``` | ||
import pMapSeries = require('p-map-series'); | ||
const keywords = [ | ||
getTopKeyword() //=> Promise | ||
'rainbow', | ||
'pony' | ||
]; | ||
let scores = []; | ||
const mapper = async keyword => { | ||
const score = await fetchScore(keyword); | ||
scores.push(score); | ||
return {keyword, score}; | ||
}); | ||
(async () => { | ||
console.log(await pMapSeries(keywords, mapper)); | ||
// [ | ||
// { | ||
// keyword: 'unicorn', | ||
// score: 99 | ||
// }, | ||
// { | ||
// keyword: 'rainbow', | ||
// score: 70 | ||
// }, | ||
// { | ||
// keyword: 'pony', | ||
// score: 79 | ||
// } | ||
// ] | ||
})(); | ||
``` | ||
*/ | ||
<ValueType, MappedValueType>( | ||
input: Iterable<PromiseLike<ValueType> | ValueType>, | ||
mapper: ( | ||
element: ValueType, | ||
index: number | ||
) => PromiseLike<MappedValueType> | MappedValueType | ||
): Promise<MappedValueType[]>; | ||
// TODO: Remove this for the next major release, refactor the whole definition to: | ||
// declare function pMapSeries<ValueType, MappedValueType>( | ||
// input: Iterable<PromiseLike<ValueType> | ValueType>, | ||
// mapper: ( | ||
// element: ValueType, | ||
// index: number | ||
// ) => PromiseLike<MappedValueType> | MappedValueType | ||
// ): Promise<MappedValueType[]>; | ||
// export = pMapSeries; | ||
default: typeof pMapSeries; | ||
}; | ||
export = pMapSeries; |
@@ -16,2 +16,3 @@ 'use strict'; | ||
module.exports = pMapSeries; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = pMapSeries; |
{ | ||
"name": "p-map-series", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Map over promises serially", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
"test": "xo && ava && tsd" | ||
}, | ||
@@ -38,8 +38,8 @@ "files": [ | ||
"devDependencies": { | ||
"ava": "^1.3.1", | ||
"ava": "^1.4.1", | ||
"delay": "^4.1.0", | ||
"time-span": "^3.0.0", | ||
"tsd-check": "^0.3.0", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.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
5628
71