]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/core-utils/common/object.ts
Move test functions outside extra-utils
[github/Chocobozzz/PeerTube.git] / shared / core-utils / common / object.ts
CommitLineData
c55e3d72
C
1function pick <O extends object, K extends keyof O> (object: O, keys: K[]): Pick<O, K> {
2 const result: any = {}
3
4 for (const key of keys) {
5 if (Object.prototype.hasOwnProperty.call(object, key)) {
6 result[key] = object[key]
7 }
8 }
9
10 return result
11}
12
13function sortObjectComparator (key: string, order: 'asc' | 'desc') {
14 return (a: any, b: any) => {
15 if (a[key] < b[key]) {
16 return order === 'asc' ? -1 : 1
17 }
18
19 if (a[key] > b[key]) {
20 return order === 'asc' ? 1 : -1
21 }
22
23 return 0
24 }
25}
26
27export {
28 pick,
29 sortObjectComparator
30}