summaryrefslogtreecommitdiff
path: root/master/server/src/utility.ts
blob: f0061f70b613556c3c6afa8d1e90dae665a2500b (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;
}