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