📤 Deep resolve promises in objects.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
868 B

# 📤 Promise.object
`Promise.object` is `Promise.all` for objects, and it traverses deeply! It's also fully typed.
## Installation
```shell
npm install --save @codefeathers/promise.object
```
## Usage
```TS
import { promiseObject } from "@codefeathers/promise.object";
// --
const resolved = await Promise.object({
foo: Promise.resolve(5),
bar: {
baz: Promise.resolve([ 1, 2, 3 ])
}
});
console.log(resolved);
//-> { foo: 5, bar: { baz: [ 1, 2, 3 ] } }
```
We need to go _deeper_!
```JavaScript
Promise.object = require('@codefeathers/promise.object');
const { log } = console;
// --
const resolved = await Promise.object(
Promise.resolve({
foo: Promise.resolve({
bar: Promise.resolve(5)
})
})
);
console.log(resolved);
//-> { foo: { bar: 5 } }
```
## Credits
The original idea and challenge was from [@TRGWII](https://github.com/TRGWII).