keyValMap.d.ts 611 B

1234567891011121314151617181920212223
  1. import type { ObjMap } from './ObjMap';
  2. /**
  3. * Creates a keyed JS object from an array, given a function to produce the keys
  4. * and a function to produce the values from each item in the array.
  5. * ```ts
  6. * const phoneBook = [
  7. * { name: 'Jon', num: '555-1234' },
  8. * { name: 'Jenny', num: '867-5309' }
  9. * ]
  10. *
  11. * // { Jon: '555-1234', Jenny: '867-5309' }
  12. * const phonesByName = keyValMap(
  13. * phoneBook,
  14. * entry => entry.name,
  15. * entry => entry.num
  16. * )
  17. * ```
  18. */
  19. export declare function keyValMap<T, V>(
  20. list: ReadonlyArray<T>,
  21. keyFn: (item: T) => string,
  22. valFn: (item: T) => V,
  23. ): ObjMap<V>;