import mapKeys from 'lodash/mapKeys' export interface NormalizedObject { [p: string]: T } type Data = T[] type Config = Partial<{ idAttribute: string }> export function normalize( data: Data, config: Config = {} ): NormalizedObject | undefined { const { idAttribute = 'id' } = config const mapped = mapKeys(data, idAttribute) return Object.prototype.hasOwnProperty.call(mapped, 'undefined') ? undefined : mapped }