utils.ts 460 B

1234567891011121314
  1. const fromEntries = (xs: [string | number | symbol, any][]) =>
  2. xs.reduce((acc, [key, value]) => ({ ...acc, [key]: value }), {});
  3. export function PromiseAllObj(obj: {
  4. [k: string]: any;
  5. }): Promise<{ [k: string]: any }> {
  6. return Promise.all(
  7. Object.entries(obj).map(([key, val]) =>
  8. val instanceof Promise
  9. ? val.then((res) => [key, res])
  10. : new Promise((res) => res([key, val]))
  11. )
  12. ).then((res: any[]) => fromEntries(res));
  13. }