Because sometimes your promises are buried deeper than your ex's Instagram photos. This utility helps you resolve them all, no matter where they're hiding! 🕵️♂️
- Resolves promises in deeply nested objects and arrays
- Works just like
Promise.all
but for objects (because objects deserve love too!) - Handles arrays, objects, and any combination thereof
- Preserves your object structure (unlike your New Year's resolutions)
- TypeScript-friendly documentation included! 🎉
npm install promise-all-object
# or if you're a yarn person (we don't judge)
yarn add promise-all-object
const { promiseAllObject } = require('./promise-tools')
// Simple object with promises
const input = {
name: Promise.resolve('John'),
age: Promise.resolve(30)
}
const result = await promiseAllObject(input)
// result = { name: 'John', age: 30 }
const input = {
user: Promise.resolve({
profile: {
name: Promise.resolve('John'),
posts: Promise.resolve([
{ title: Promise.resolve('Hello') }
])
}
})
}
const result = await promiseAllObject(input)
// Everything is resolved! 🎉
const input = [Promise.resolve(1), Promise.resolve(2)]
const result = await promiseAllObject(input)
// result = [1, 2]
try {
const input = {
success: Promise.resolve('yay'),
failure: Promise.reject(new Error('oops'))
}
await promiseAllObject(input)
} catch (error) {
console.log('Something went wrong! Time to blame the intern.')
}
We've got tests! Because we're professionals (most of the time).
# Run the tests
npm test
# Run with coverage (to impress your boss)
npm test -- --coverage
Our tests check:
- Promise resolution at all depths
- Array handling
- Object handling
- Error propagation
- Edge cases (null, undefined, etc.)
- That your code actually works (shocking, right?)
Takes any input and resolves all promises within it, no matter how deeply nested they are. Like a treasure hunter, but for promises! 🗺️
Checks if something is a Promise. It's like a bouncer for your code, but instead of checking IDs, it checks for .then()
methods! 🚪
- Don't nest your promises too deep - even this utility can't save you from callback hell 😈
- Remember to use
try/catch
- promises can break your heart 💔 - This utility is recursive - it's promises all the way down! 🐢
- Still can't resolve your commitment issues
- Won't help you keep your promises to go to the gym
- Doesn't work on promises you made to your mother
MIT - Because sharing is caring! ❤️
Pull requests are welcome! Just remember:
- Add tests (we're not savages)
- Update the docs
- Don't break anything
- Maybe bring cookies? 🍪
If this package saved you from promise hell, consider:
- Giving it a star ⭐
- Telling your friends
- Naming your firstborn after it