From ea33f87e590dd6f010590ecfc5d5b07dcabe0c64 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 31 May 2022 00:02:58 +0200 Subject: feat(master): add server package --- master/server/src/utility.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 master/server/src/utility.ts (limited to 'master/server/src/utility.ts') diff --git a/master/server/src/utility.ts b/master/server/src/utility.ts new file mode 100644 index 0000000..6a02575 --- /dev/null +++ b/master/server/src/utility.ts @@ -0,0 +1,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; +} -- cgit v1.2.3-18-g5258