- Notifications
You must be signed in to change notification settings - Fork12
Like `Promise.all()` but for `Map` and `Object`
License
sindresorhus/p-props
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Like
Promise.all()
but forMap
andObject
Useful when you need to run multiple promises concurrently and keep track of the fulfilled values by name.
npm install p-props
importpPropsfrom'p-props';importgotfrom'got';constfetch=asyncurl=>{const{body}=awaitgot(url);returnbody;};constsites={ava:fetch('https://avajs.dev'),todomvc:fetch('https://todomvc.com'),github:fetch('https://github.com'),foo:'bar'};console.log(awaitpProps(sites));/*{ava: '<!doctype …',todomvc: '<!doctype …',github: '<!doctype …',foo: 'bar'}*/
Returns aPromise
that is fulfilled when all promises inmap
and ones returned frommapper
are fulfilled, or rejects if any of the promises reject. The fulfilled value is the same asmap
, but with a fulfilled version of each entry value, or the fulfilled value returned frommapper
, if defined.
Type:Map | object
Resolves entry values that are promises. Other values are passed through.
Type:Function
Receives the current value and key as parameters. If a value is aPromise
,mapper
will receive the value thisPromise
resolves to. Expected to return aPromise
or value.
Type:object
See thep-map
options.
About
Like `Promise.all()` but for `Map` and `Object`