diff options
| author | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
|---|---|---|
| committer | rxliuli <rxliuli@gmail.com> | 2025-11-04 05:03:50 +0800 |
| commit | bce557cc2dc767628bed6aac87301a1be7c5431b (patch) | |
| tree | b51a051228d01fe3306cd7626d4a96768aadb944 /shared/utils/src/object-from-entries.ts | |
init commit
Diffstat (limited to 'shared/utils/src/object-from-entries.ts')
| -rw-r--r-- | shared/utils/src/object-from-entries.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/shared/utils/src/object-from-entries.ts b/shared/utils/src/object-from-entries.ts new file mode 100644 index 0000000..80d3cdb --- /dev/null +++ b/shared/utils/src/object-from-entries.ts @@ -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; +} |
