mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-26 23:23:06 +00:00
5b0c122f5d
List of user emails GitOrigin-RevId: 28a8e405812932ba7ebd8043a4dc9d3c573a68b2
22 lines
455 B
TypeScript
22 lines
455 B
TypeScript
import mapKeys from 'lodash/mapKeys'
|
|
|
|
export interface NormalizedObject<T> {
|
|
[p: string]: T
|
|
}
|
|
|
|
type Data<T> = T[]
|
|
type Config = Partial<{
|
|
idAttribute: string
|
|
}>
|
|
|
|
export function normalize<T>(
|
|
data: Data<T>,
|
|
config: Config = {}
|
|
): NormalizedObject<T> | undefined {
|
|
const { idAttribute = 'id' } = config
|
|
const mapped = mapKeys(data, idAttribute)
|
|
|
|
return Object.prototype.hasOwnProperty.call(mapped, 'undefined')
|
|
? undefined
|
|
: mapped
|
|
}
|