aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/core-utils
diff options
context:
space:
mode:
Diffstat (limited to 'shared/core-utils')
-rw-r--r--shared/core-utils/common/object.ts14
1 files changed, 14 insertions, 0 deletions
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 <O extends object, K extends keyof O> (object: O, keys: K[]): Pick
10 return result 10 return result
11} 11}
12 12
13function omit <O extends object, K extends keyof O> (object: O, keys: K[]): Exclude<O, K> {
14 const result: any = {}
15 const keysSet = new Set(keys) as Set<string>
16
17 for (const [ key, value ] of Object.entries(object)) {
18 if (keysSet.has(key)) continue
19
20 result[key] = value
21 }
22
23 return result
24}
25
13function getKeys <O extends object, K extends keyof O> (object: O, keys: K[]): K[] { 26function getKeys <O extends object, K extends keyof O> (object: O, keys: K[]): K[] {
14 return (Object.keys(object) as K[]).filter(k => keys.includes(k)) 27 return (Object.keys(object) as K[]).filter(k => keys.includes(k))
15} 28}
@@ -30,6 +43,7 @@ function sortObjectComparator (key: string, order: 'asc' | 'desc') {
30 43
31export { 44export {
32 pick, 45 pick,
46 omit,
33 getKeys, 47 getKeys,
34 sortObjectComparator 48 sortObjectComparator
35} 49}