{"_id":"combine-promises","_rev":"3249625","name":"combine-promises","description":"[![NPM](https://img.shields.io/npm/dm/combine-promises.svg)](https://www.npmjs.com/package/combine-promises) [![CI](https://github.com/slorber/combine-promises/actions/workflows/main.yml/badge.svg)](https://github.com/slorber/combine-promises/actions/work","dist-tags":{"latest":"1.2.0"},"maintainers":[{"name":"slorber","email":""}],"time":{"modified":"2024-03-21T09:13:18.000Z","created":"2021-04-07T09:19:44.795Z","1.2.0":"2023-08-17T10:37:36.671Z","1.1.0":"2021-04-07T09:29:14.623Z","1.0.0":"2021-04-07T09:19:44.795Z"},"users":{},"author":{"name":"slorber"},"repository":{"type":"git","url":"https://github.com/slorber/combine-promises.git"},"versions":{"1.2.0":{"name":"combine-promises","author":{"name":"slorber"},"version":"1.2.0","license":"MIT","main":"dist/index.js","typings":"dist/index.d.ts","module":"dist/combine-promises.esm.js","engines":{"node":">=10"},"repository":{"type":"git","url":"https://github.com/slorber/combine-promises.git"},"scripts":{"start":"tsdx watch","build":"tsdx build","test":"tsdx test","lint":"tsdx lint","prepare":"tsdx build","size":"size-limit","analyze":"size-limit --why"},"peerDependencies":{},"husky":{"hooks":{"pre-commit":"tsdx lint"}},"prettier":{"printWidth":80,"semi":true,"singleQuote":true,"trailingComma":"es5"},"size-limit":[{"path":"dist/combine-promises.cjs.production.min.js","limit":"150 B"},{"path":"dist/combine-promises.esm.js","limit":"150 B"}],"devDependencies":{"@size-limit/preset-small-lib":"^4.10.2","husky":"^6.0.0","size-limit":"^4.10.2","tsdx":"^0.14.1","tslib":"^2.2.0","typescript":"^4.2.3"},"description":"[![NPM](https://img.shields.io/npm/dm/combine-promises.svg)](https://www.npmjs.com/package/combine-promises) [![CI](https://github.com/slorber/combine-promises/actions/workflows/main.yml/badge.svg)](https://github.com/slorber/combine-promises/actions/work","licenseText":"MIT License\n\nCopyright (c) 2021 Sébastien Lorber\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"combine-promises@1.2.0","dist":{"shasum":"5f2e68451862acf85761ded4d9e2af7769c2ca6a","size":4364,"noattachment":false,"key":"/combine-promises/-/combine-promises-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/combine-promises/download/combine-promises-1.2.0.tgz"},"_npmUser":{"name":"slorber","email":"lorber.sebastien@gmail.com"},"directories":{},"maintainers":[{"name":"slorber","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/combine-promises_1.2.0_1692268656450_0.9490421174842931"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-08-17T10:37:36.671Z","publish_time":1692268656671,"_source_registry_name":"default","_cnpm_publish_time":1692268656671},"1.1.0":{"name":"combine-promises","author":{"name":"slorber"},"version":"1.1.0","license":"MIT","main":"dist/index.js","typings":"dist/index.d.ts","module":"dist/combine-promises.esm.js","engines":{"node":">=10"},"scripts":{"start":"tsdx watch","build":"tsdx build","test":"tsdx test","lint":"tsdx lint","prepare":"tsdx build","size":"size-limit","analyze":"size-limit --why"},"peerDependencies":{},"husky":{"hooks":{"pre-commit":"tsdx lint"}},"prettier":{"printWidth":80,"semi":true,"singleQuote":true,"trailingComma":"es5"},"size-limit":[{"path":"dist/combine-promises.cjs.production.min.js","limit":"150 B"},{"path":"dist/combine-promises.esm.js","limit":"150 B"}],"devDependencies":{"@size-limit/preset-small-lib":"^4.10.2","husky":"^6.0.0","size-limit":"^4.10.2","tsdx":"^0.14.1","tslib":"^2.2.0","typescript":"^4.2.3"},"description":"[![NPM](https://img.shields.io/npm/dm/combine-promises.svg)](https://www.npmjs.com/package/combine-promises) ![Size min](https://img.shields.io/bundlephobia/min/combine-promises.svg) ![Size minzip](https://img.shields.io/bundlephobia/minzip/combine-promis","licenseText":"MIT License\n\nCopyright (c) 2021 Sébastien Lorber\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"combine-promises@1.1.0","dist":{"shasum":"72db90743c0ca7aab7d0d8d2052fd7b0f674de71","size":4086,"noattachment":false,"key":"/combine-promises/-/combine-promises-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/combine-promises/download/combine-promises-1.1.0.tgz"},"_npmUser":{"name":"slorber","email":"lorber.sebastien@gmail.com"},"directories":{},"maintainers":[{"name":"slorber","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/combine-promises_1.1.0_1617787754506_0.3351942175691145"},"_hasShrinkwrap":false,"publish_time":1617787754623,"_cnpm_publish_time":1617787754623,"_cnpmcore_publish_time":"2021-12-17T03:51:33.680Z"},"1.0.0":{"version":"1.0.0","license":"MIT","main":"dist/index.js","typings":"dist/index.d.ts","engines":{"node":">=10"},"scripts":{"start":"tsdx watch","build":"tsdx build","test":"tsdx test","lint":"tsdx lint","prepare":"tsdx build","size":"size-limit","analyze":"size-limit --why"},"peerDependencies":{},"husky":{"hooks":{"pre-commit":"tsdx lint"}},"prettier":{"printWidth":80,"semi":true,"singleQuote":true,"trailingComma":"es5"},"name":"combine-promises","author":{"name":"slorber"},"module":"dist/combine-promises.esm.js","size-limit":[{"path":"dist/combine-promises.cjs.production.min.js","limit":"10 KB"},{"path":"dist/combine-promises.esm.js","limit":"10 KB"}],"devDependencies":{"@size-limit/preset-small-lib":"^4.10.2","husky":"^6.0.0","size-limit":"^4.10.2","tsdx":"^0.14.1","tslib":"^2.2.0","typescript":"^4.2.3"},"description":"Like Promise.all(array) but with an object.","licenseText":"MIT License\n\nCopyright (c) 2021 Sébastien Lorber\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"combine-promises@1.0.0","dist":{"shasum":"589d181d01d4fa197b46ea95af9e5c790b175c4e","size":3939,"noattachment":false,"key":"/combine-promises/-/combine-promises-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/combine-promises/download/combine-promises-1.0.0.tgz"},"_npmUser":{"name":"slorber","email":"lorber.sebastien@gmail.com"},"directories":{},"maintainers":[{"name":"slorber","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/combine-promises_1.0.0_1617787184624_0.5888021116578597"},"_hasShrinkwrap":false,"publish_time":1617787184795,"_cnpm_publish_time":1617787184795,"_cnpmcore_publish_time":"2021-12-17T03:51:33.884Z"}},"readme":"# Combine-Promises\n\n[![NPM](https://img.shields.io/npm/dm/combine-promises.svg)](https://www.npmjs.com/package/combine-promises)\n[![CI](https://github.com/slorber/combine-promises/actions/workflows/main.yml/badge.svg)](https://github.com/slorber/combine-promises/actions/workflows/main.yml)\n![Size min](https://img.shields.io/bundlephobia/min/combine-promises.svg)\n![Size minzip](https://img.shields.io/bundlephobia/minzip/combine-promises.svg)\n\nLike `Promise.all([])` but for objects.\n\n```ts\nimport combinePromises from 'combine-promises';\n\nconst { user, company } = await combinePromises({\n  user: fetchUser(),\n  company: fetchCompany(),\n});\n```\n\nWhy:\n\n- Insensitive to destructuring order\n- Simpler async functional code\n\nFeatures:\n\n- TypeScript support\n- Lightweight\n- Feature complete\n- Well-tested\n- ESM / CJS\n\n--- \n\n# Sponsor\n\n**[ThisWeekInReact.com](https://thisweekinreact.com)**: the best newsletter to stay up-to-date with the React ecosystem:\n\n[![ThisWeekInReact.com banner](https://user-images.githubusercontent.com/749374/136185889-ebdb67cd-ec78-4655-b88b-79a6c134acd2.png)](https://thisweekinreact.com)\n\n---\n\n## Install\n\n```\nnpm install combine-promises\n// OR\nyarn add combine-promises\n```\n\n## TypeScript support\n\nGood, native and strict TypeScript support:\n\n- Return type correctly inferred from the input object\n- All object values should be async\n- Only accept objects (reject arrays, null, undefined...)\n\n```ts\nconst result: { user: User; company: Company } = await combinePromises({\n  user: fetchUser(),\n  company: fetchCompany(),\n});\n```\n\n## Insensitive to destructuring order\n\nA common error with `Promise.all` is to have a typo in the destructuring order.\n\n```js\n// Bad: destructuring order reversed\nconst [company, user] = await Promise.all([fetchUser(), fetchCompany()]);\n```\n\nThis becomes more dangerous as size of the promises array grows.\n\nWith `combinePromises`, you are using explicit names instead of array indices, which makes the code more robust and not sensitive to destructuring order:\n\n```js\n// Good: we don't care about the order anymore\nconst { company, user } = await combinePromises({\n  user: fetchUser(),\n  company: fetchCompany(),\n});\n```\n\n## Simpler async functional code\n\nSuppose you have an object representing a friendship like `{user1: \"userId-1\", user2: \"userId-2\"}`, and you want to transform it to `{user1: User, user2: User}`.\n\nYou can easily do that:\n\n```js\nimport combinePromises from 'combine-promises';\nimport { mapValues } from 'lodash'; // can be replaced by vanilla ES if you prefer\n\nconst friendsIds = { user1: 'userId-1', user2: 'userId-2' };\n\nconst friends = await combinePromises(mapValues(friendsIds, fetchUserById));\n```\n\nWithout this library: good luck to keep your code simple.\n\n## Inspirations\n\nName inspired by [combineReducers](https://redux.js.org/api/combinereducers) from Redux.\n","_attachments":{},"license":"MIT"}