init commit
This commit is contained in:
18
shared/utils/src/object-from-entries.ts
Normal file
18
shared/utils/src/object-from-entries.ts
Normal file
@@ -0,0 +1,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;
|
||||
}
|
||||
Reference in New Issue
Block a user