Files
Satoshi Qazi Muhammed a9d1026736 chore(papi): keep the upstream sources in upstream-src/
The pezkuwi-dev build treats any package with a src/ directory as its
own: it requires our license header on every file and builds it. These
are upstream files that must stay byte-identical to the source embedded
in dist/, so they live in upstream-src/ instead, which neither the build
nor the root tsconfig picks up.
2026-10-19 21:17:25 +04:00

30 lines
772 B
TypeScript

export function mapObject<K extends string | number | symbol, I, O>(
input: Record<K, I>,
mapper: (i: I, k: K) => O,
): Record<K, O>
export function mapObject<K extends string | number | symbol, I, O>(
input: Record<K, I>,
mapper: (i: I, k?: K) => O,
): Record<K, O> {
return Object.fromEntries(
Object.entries(input).map(
([key, value]: any) => [key, mapper(value, key)] as const,
),
) as any
}
export type StringRecord<T> = {
[Sym: symbol]: never
[Num: number]: never
[Str: string]: T
}
export const mapStringRecord = <I, O>(
input: StringRecord<I>,
mapper: (value: I, key: string) => O,
): StringRecord<O> =>
Object.fromEntries(
Object.entries(input).map(([key, value]) => [key, mapper(value, key)]),
) as StringRecord<O>