Skip to content

Commit a48312e

Browse files
committed
new helper
1 parent aeefa07 commit a48312e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

dashi/src/lib/utils/mapObject.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export function mapObject<
2+
S extends Record<string, V1>,
3+
V1 = unknown,
4+
V2 = unknown,
5+
>(
6+
obj: S,
7+
transformValue: (value: V1, key: string | number) => V2,
8+
): Record<string, V2> {
9+
const obj2: { [k: string]: V2 } = {};
10+
Object.getOwnPropertyNames(obj).forEach((key) => {
11+
obj2[key] = transformValue(obj[key], key);
12+
});
13+
return obj2;
14+
}

0 commit comments

Comments
 (0)