{"_id":"p-reduce","_rev":"139931","name":"p-reduce","description":"Reduce a list of values using promises into a promise for a value","dist-tags":{"latest":"3.0.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2021-06-03T11:26:17.000Z","created":"2016-10-21T04:24:28.119Z","3.0.0":"2021-04-08T18:18:57.037Z","2.1.0":"2019-04-04T04:57:45.948Z","2.0.0":"2019-03-12T05:12:38.774Z","1.0.0":"2016-10-21T04:24:28.119Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reduce.git"},"versions":{"3.0.0":{"name":"p-reduce","version":"3.0.0","description":"Reduce a list of values using promises into a promise for a value","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reduce.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":"./index.js","engines":{"node":">=12"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","reduce","collection","iterable","iterator","async","await","promises","accumulate","bluebird"],"devDependencies":{"ava":"^3.15.0","delay":"^5.0.0","tsd":"^0.14.0","xo":"^0.38.2"},"gitHead":"b8cfa3dd34304384501d4e5243c44131998c4ee5","bugs":{"url":"https://github.com/sindresorhus/p-reduce/issues"},"homepage":"https://github.com/sindresorhus/p-reduce#readme","_id":"p-reduce@3.0.0","_nodeVersion":"15.12.0","_npmVersion":"6.14.10","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"f11773794792974bd1f7a14c72934248abff4160","size":2577,"noattachment":false,"key":"/p-reduce/-/p-reduce-3.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/p-reduce/download/p-reduce-3.0.0.tgz"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-reduce_3.0.0_1617905936908_0.15612528844177098"},"_hasShrinkwrap":false,"publish_time":1617905937037,"_cnpm_publish_time":1617905937037},"2.1.0":{"name":"p-reduce","version":"2.1.0","description":"Reduce a list of values using promises into a promise for a value","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reduce.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd"},"keywords":["promise","reduce","collection","iterable","iterator","async","await","promises","accumulate","bluebird"],"devDependencies":{"ava":"^1.4.1","delay":"^4.1.0","tsd":"^0.7.2","xo":"^0.24.0"},"gitHead":"cb9d053d05194221f010fcd0dfa9d0c203aa26d7","bugs":{"url":"https://github.com/sindresorhus/p-reduce/issues"},"homepage":"https://github.com/sindresorhus/p-reduce#readme","_id":"p-reduce@2.1.0","_nodeVersion":"8.15.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"09408da49507c6c274faa31f28df334bc712b64a","size":2590,"noattachment":false,"key":"/p-reduce/-/p-reduce-2.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/p-reduce/download/p-reduce-2.1.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-reduce_2.1.0_1554353865830_0.3691561520970803"},"_hasShrinkwrap":false,"publish_time":1554353865948,"_cnpm_publish_time":1554353865948},"2.0.0":{"name":"p-reduce","version":"2.0.0","description":"Reduce a list of values using promises into a promise for a value","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reduce.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=8"},"scripts":{"test":"xo && ava && tsd-check"},"keywords":["promise","reduce","collection","iterable","iterator","async","await","promises","accumulate","bluebird"],"devDependencies":{"ava":"^1.3.1","delay":"^4.1.0","tsd-check":"^0.3.0","xo":"^0.24.0"},"gitHead":"44439fb758f74506b45863488abef8d3d8762629","bugs":{"url":"https://github.com/sindresorhus/p-reduce/issues"},"homepage":"https://github.com/sindresorhus/p-reduce#readme","_id":"p-reduce@2.0.0","_nodeVersion":"8.15.0","_npmVersion":"6.9.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"365a26916213650711124881a6bdc4e32c2bfe36","size":2406,"noattachment":false,"key":"/p-reduce/-/p-reduce-2.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/p-reduce/download/p-reduce-2.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/p-reduce_2.0.0_1552367558654_0.1055260822991213"},"_hasShrinkwrap":false,"publish_time":1552367558774,"_cnpm_publish_time":1552367558774},"1.0.0":{"name":"p-reduce","version":"1.0.0","description":"Reduce a list of values using promises into a promise for a value","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/p-reduce.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"sindresorhus.com"},"engines":{"node":">=4"},"scripts":{"test":"xo && ava"},"files":["index.js"],"keywords":["promise","reduce","collection","iterable","iterator","async","await","promises","accumulate","bluebird"],"devDependencies":{"ava":"*","delay":"^1.3.1","xo":"*"},"xo":{"esnext":true},"gitHead":"fa526a9b6b51a3c4811c61954328218a4636871d","bugs":{"url":"https://github.com/sindresorhus/p-reduce/issues"},"homepage":"https://github.com/sindresorhus/p-reduce#readme","_id":"p-reduce@1.0.0","_shasum":"18c2b0dd936a4690a529f8231f58a0fdb6a47dfa","_from":".","_npmVersion":"2.15.9","_nodeVersion":"4.6.0","_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"dist":{"shasum":"18c2b0dd936a4690a529f8231f58a0fdb6a47dfa","size":2161,"noattachment":false,"key":"/p-reduce/-/p-reduce-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/p-reduce/download/p-reduce-1.0.0.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/p-reduce-1.0.0.tgz_1477023867894_0.5352144201751798"},"directories":{},"publish_time":1477023868119,"_cnpm_publish_time":1477023868119,"_hasShrinkwrap":false}},"readme":"# p-reduce\n\n> Reduce a list of values using promises into a promise for a value\n\nUseful when you need to calculate some accumulated value based on async resources.\n\n## Install\n\n```\n$ npm install p-reduce\n```\n\n## Usage\n\n```js\nimport pReduce from 'p-reduce';\nimport humanInfo from 'human-info'; // Not a real module\n\nconst names = [\n\tgetUser('sindresorhus').then(info => info.name),\n\t'Addy Osmani',\n\t'Pascal Hartig',\n\t'Stephen Sawchuk'\n];\n\nconst totalAge = await pReduce(names, async (total, name) => {\n\tconst info = await humanInfo(name);\n\treturn total + info.age;\n}, 0);\n\nconsole.log(totalAge);\n//=> 125\n```\n\n## API\n\n### pReduce(input, reducer, initialValue?)\n\nReturns a `Promise` that is fulfilled when all promises in `input` and ones returned from `reducer` are fulfilled, or rejects if any of the promises reject. The fulfilled value is the result of the reduction.\n\n#### input\n\nType: `Iterable<Promise|any>`\n\nIterated over serially in the `reducer` function.\n\n#### reducer(previousValue, currentValue, index)\n\nType: `Function`\n\nExpected to return a value. If a `Promise` is returned, it's awaited before continuing with the next iteration.\n\n#### initialValue\n\nType: `unknown`\n\nValue to use as `previousValue` in the first `reducer` invocation.\n\n## Related\n\n- [p-each-series](https://github.com/sindresorhus/p-each-series) - Iterate over promises serially\n- [p-map-series](https://github.com/sindresorhus/p-map-series) - Map over promises serially\n- [p-map](https://github.com/sindresorhus/p-map) - Map over promises concurrently\n- [More…](https://github.com/sindresorhus/promise-fun)\n\n---\n\n<div align=\"center\">\n\t<b>\n\t\t<a href=\"https://tidelift.com/subscription/pkg/npm-p-reduce?utm_source=npm-p-reduce&utm_medium=referral&utm_campaign=readme\">Get professional support for this package with a Tidelift subscription</a>\n\t</b>\n\t<br>\n\t<sub>\n\t\tTidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.\n\t</sub>\n</div>\n","_attachments":{},"homepage":"https://github.com/sindresorhus/p-reduce#readme","bugs":{"url":"https://github.com/sindresorhus/p-reduce/issues"},"license":"MIT"}