From bbd5aa7ead5f1554a0872963f957effc26d8c630 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 17 Aug 2022 15:25:58 +0200 Subject: Reimplement a typed omit function --- shared/core-utils/common/object.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'shared/core-utils/common') diff --git a/shared/core-utils/common/object.ts b/shared/core-utils/common/object.ts index 49d209819..2330c9403 100644 --- a/shared/core-utils/common/object.ts +++ b/shared/core-utils/common/object.ts @@ -10,6 +10,19 @@ function pick (object: O, keys: K[]): Pick return result } +function omit (object: O, keys: K[]): Exclude { + const result: any = {} + const keysSet = new Set(keys) as Set + + for (const [ key, value ] of Object.entries(object)) { + if (keysSet.has(key)) continue + + result[key] = value + } + + return result +} + function getKeys (object: O, keys: K[]): K[] { return (Object.keys(object) as K[]).filter(k => keys.includes(k)) } @@ -30,6 +43,7 @@ function sortObjectComparator (key: string, order: 'asc' | 'desc') { export { pick, + omit, getKeys, sortObjectComparator } -- cgit v1.2.3