summaryrefslogtreecommitdiff
path: root/master/server/src/utility.ts
blob: 6a0257505ef1ca0f4908764568259570339eb4e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export function filter_object<
	ObjectType,
	Key extends keyof ObjectType,
	Value extends ObjectType[keyof ObjectType]
>(
	obj: ObjectType,
	filter_cb: (key: Key, value: Value) => boolean
) {
	const entries = Object.entries(obj);

	const filtered = entries.filter(([ str_key, any_value ]) => {
		return filter_cb(str_key as Key, any_value as Value);
	});

	return Object.fromEntries(filtered) as ObjectType;
}