aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/core-utils/common
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-08-17 15:25:58 +0200
committerChocobozzz <me@florianbigard.com>2022-08-17 15:25:58 +0200
commitbbd5aa7ead5f1554a0872963f957effc26d8c630 (patch)
treea32cad420cfabe4eab5df4e3f104fa34f734fa7d /shared/core-utils/common
parenta85d530384761a0af833caac9b38b9834517c9fa (diff)
downloadPeerTube-bbd5aa7ead5f1554a0872963f957effc26d8c630.tar.gz
PeerTube-bbd5aa7ead5f1554a0872963f957effc26d8c630.tar.zst
PeerTube-bbd5aa7ead5f1554a0872963f957effc26d8c630.zip
Reimplement a typed omit function
Diffstat (limited to 'shared/core-utils/common')
-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}