{"id":13469653,"url":"https://github.com/slorber/combine-promises","last_synced_at":"2025-04-12T22:34:32.018Z","repository":{"id":53083705,"uuid":"355457855","full_name":"slorber/combine-promises","owner":"slorber","description":"Like Promise.all(array) but with an object instead of an array.","archived":false,"fork":false,"pushed_at":"2023-08-17T10:48:48.000Z","size":170,"stargazers_count":205,"open_issues_count":3,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-04T02:07:33.788Z","etag":null,"topics":["async","await","ecmascript","functional-js","functional-programming","javascript","promise","promises"],"latest_commit_sha":null,"homepage":"https://sebastienlorber.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/slorber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-07T07:50:11.000Z","updated_at":"2025-04-03T18:03:18.000Z","dependencies_parsed_at":"2024-06-18T14:06:45.575Z","dependency_job_id":null,"html_url":"https://github.com/slorber/combine-promises","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slorber%2Fcombine-promises","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slorber%2Fcombine-promises/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slorber%2Fcombine-promises/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slorber%2Fcombine-promises/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slorber","download_url":"https://codeload.github.com/slorber/combine-promises/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248641887,"owners_count":21138289,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","await","ecmascript","functional-js","functional-programming","javascript","promise","promises"],"created_at":"2024-07-31T15:01:48.771Z","updated_at":"2025-04-12T22:34:31.994Z","avatar_url":"https://github.com/slorber.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslorber%2Fcombine-promises","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslorber%2Fcombine-promises","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslorber%2Fcombine-promises/lists"}