diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-02-11 21:44:38 +0100 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-02-11 21:44:38 +0100 |
commit | 669f3b39849890c48171d807225cd6eaa3c9086b (patch) | |
tree | bc07fefc4e13ac8f737174166ac1d19512379298 /lib/utils/promise.js | |
parent | e7eed2abbe91fa44bd071819123bd9ea04d1702a (diff) | |
download | gitbook-669f3b39849890c48171d807225cd6eaa3c9086b.zip gitbook-669f3b39849890c48171d807225cd6eaa3c9086b.tar.gz gitbook-669f3b39849890c48171d807225cd6eaa3c9086b.tar.bz2 |
Add base for normalizing html
Diffstat (limited to 'lib/utils/promise.js')
-rw-r--r-- | lib/utils/promise.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/utils/promise.js b/lib/utils/promise.js index 82f4a60..adcc1c3 100644 --- a/lib/utils/promise.js +++ b/lib/utils/promise.js @@ -32,7 +32,19 @@ function some(arr, iter) { }, Q()); } +// Map an array using an async (promised) iterator +function map(arr, iter) { + return reduce(arr, function(prev, entry, i) { + return Q(iter(entry, i)) + .then(function(out) { + prev.push(out); + return prev; + }); + }, []); +} + module.exports = Q; module.exports.reduce = reduce; +module.exports.map = map; module.exports.serie = serie; module.exports.some = some; |