export const objectMap = async <
T extends object = object,
R extends any | [
string,
any,
] = any,
>(
obj: T,
fn: (key: string, value: T[keyof T]) => Promise<R>,
): Promise<Record<string, R>> =>
Object.fromEntries(
await Promise.all(
Object.entries(obj).map(async ([k, v]) => {
const res = await fn(k, v);
if (Array.isArray(res) && res.length === 2) {
return res;
}
else {
return [k, res];
}
}),
),
);