Files
30-seconds-of-code/node_modules/graphql/jsutils/mapValue.js.flow
2019-08-20 15:52:05 +02:00

21 lines
497 B
Plaintext

// @flow strict
import { type ObjMap } from './ObjMap';
import objectEntries from '../polyfills/objectEntries';
/**
* Creates an object map with the same keys as `map` and values generated by
* running each value of `map` thru `fn`.
*/
export default function mapValue<T, V>(
map: ObjMap<T>,
fn: (value: T, key: string) => V,
): ObjMap<V> {
const result = Object.create(null);
for (const [key, value] of objectEntries(map)) {
result[key] = fn(value, key);
}
return result;
}