UNPKG

p-props

Version:

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

10 lines (8 loc) 469 B
import pMap from 'p-map'; export default async function pProps(input, mapper = (value => value), options = undefined) { const isMap = input instanceof Map; const entries = isMap ? [...input] : Object.entries(input); const values = await pMap(entries, async ([key, value]) => mapper(await value, key), options); const mappedEntries = entries.map(([key], index) => [key, values[index]]); return isMap ? new Map(mappedEntries) : Object.fromEntries(mappedEntries); }