Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Like `Promise.all()` but for `Map` and `Object`

License

NotificationsYou must be signed in to change notification settings

sindresorhus/p-props

Repository files navigation

LikePromise.all() but forMap andObject

Useful when you need to run multiple promises concurrently and keep track of the fulfilled values by name.

Install

npm install p-props

Usage

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'}*/

API

pProps(map, mapper?, options?)

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.

map

Type:Map | object

Resolves entry values that are promises. Other values are passed through.

mapper(value, key)

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.

options

Type:object

See thep-map options.

Related

  • p-all - Run promise-returning & async functions concurrently with optional limited concurrency
  • p-map - Map over promises concurrently
  • More…

[8]ページ先頭

©2009-2025 Movatter.jp