mapValue.js.flow 498 B

123456789101112131415161718192021
  1. // @flow strict
  2. import objectEntries from '../polyfills/objectEntries';
  3. import { type ObjMap } from './ObjMap';
  4. /**
  5. * Creates an object map with the same keys as `map` and values generated by
  6. * running each value of `map` thru `fn`.
  7. */
  8. export default function mapValue<T, V>(
  9. map: ObjMap<T>,
  10. fn: (value: T, key: string) => V,
  11. ): ObjMap<V> {
  12. const result = Object.create(null);
  13. for (const [key, value] of objectEntries(map)) {
  14. result[key] = fn(value, key);
  15. }
  16. return result;
  17. }