A lightweight, fully typed library providing utilities for working with JavaScript promises.
- 📦 Tiny and dependency-free
- 🔒 Type-safe – written in TypeScript
- ⚡ Works with ESM and CommonJS
- 🛠 Provides helpers for combining and managing promises
npm install promise-sos
# or
yarn add promise-sosA helper function that extends Promise.all by allowing you to pass an object of promises (instead of an array).
It returns a promise that resolves to an object with the same keys, but with the promises replaced by their resolved values.
import { promiseAllObject } from 'promise-sos';
const promisesObject = {
promiseA: Promise.resolve('resolved promiseA'),
promiseB: Promise.resolve('resolved promiseB'),
someValue: 1234,
flag: true
};
const result = await promiseAllObject(promisesObject);
console.log(result);
// {
// promiseA: 'resolved promiseA',
// promiseB: 'resolved promiseB',
// someValue: 1234,
// flag: true
// }import { promiseAllObject } from 'promise-sos';
const promisesObject = {
promiseA: Promise.reject(new Error('rejected promiseA')),
promiseB: Promise.resolve('resolved promiseB')
};
try {
const result = await promiseAllObject(promisesObject);
} catch (error) {
console.error(error);
// Error: rejected promiseA
}promisesMap: An object whose values may be promises or regular values.- Returns: A promise resolving to an object with the same keys, with all promises unwrapped.
- Throws:
TypeErrorif input is not a non-empty plain object.- Any error from a rejected promise.
MIT © Inaki Arroyo