forked from microsoft/TypeScript-DOM-lib-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecord.ts
More file actions
26 lines (25 loc) · 756 Bytes
/
Copy pathrecord.ts
File metadata and controls
26 lines (25 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
export function filterMapRecord<T extends object, V>(
object: Record<string, T> | undefined,
mapper: (key: string, value: T) => V | undefined,
forNamespace?: boolean,
): Record<string, V> | undefined {
if (!object) {
return;
}
const result = {} as Record<string, V>;
for (const [key, value] of Object.entries(object)) {
const mdnKey =
forNamespace || ("static" in value && value.static)
? `${key}_static`
: key;
const newValue = mapper(mdnKey, value);
if (newValue !== undefined) {
result[key] = newValue;
}
}
return result;
}
// eslint-disable-next-line @typescript-eslint/ban-types
export function isEmptyRecord(o: object | undefined): boolean {
return !o || !Object.keys(o).length;
}