summaryrefslogtreecommitdiff
path: root/shared/utils/src/object-from-entries.ts
blob: 80d3cdb435ac33e75e5bfa48a4b0ed261157eae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// TODO: rdar://78109780 (Update to Node 16)
/**
 * Create an object from an iterable of key/value pairs.
 *
 * @param entries The key value pairs (ex. [['a', 1], ['b', 2]])
 * @return        The created object
 */
export function fromEntries<V>(entries: Iterable<readonly [PropertyKey, V]>): {
    [k: string]: V;
} {
    const result: Record<PropertyKey, V> = {};

    for (const [key, value] of entries) {
        result[key] = value;
    }

    return result;
}