Skip to content

mya-ake/mapped-promise-all

Repository files navigation

mapped-promise-all

npm version License: MIT CI

Provides a mapping of the response of Promise.all to an object.

Install

$ npm i mapped-promise-all
// or
$ yarn add mapped-promise-all

Usage

import { mappedPromiseAll } from 'mapped-promise-all';

const getUser = async () => ({
  name: 'user',
  email: 'sample@example.com',
});

const getItems = async () => [
  { id: 1, name: 'item 1' },
  { id: 2, name: 'item 2' },
];

mappedPromiseAll({
  user: getUser(),
  items: getItems(),
}).then(({ user, items }) => {
  // do something
});

// async/await
const { user, items } = await mappedPromiseAll({
  user: getUser(),
  items: getItems(),
});
// do something

Contribution

If you find a bug or want to contribute to the code or documentation, you can help by submitting an issue or a pull request.

License

MIT