diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-19 09:24:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-25 11:24:11 +0200 |
commit | dd24f1bb0a4b252e5342b251ba36853364da7b8e (patch) | |
tree | 41a9506d07413f056fb90425705e258f96fdc77d /client/src/app/helpers/utils/object.ts | |
parent | 2e80d256cc75b4b02c8efc3d3e4cdf57ddf401a8 (diff) | |
download | PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.gz PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.zst PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.zip |
Add video filters to common video pages
Diffstat (limited to 'client/src/app/helpers/utils/object.ts')
-rw-r--r-- | client/src/app/helpers/utils/object.ts | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/client/src/app/helpers/utils/object.ts b/client/src/app/helpers/utils/object.ts new file mode 100644 index 000000000..1ca4a23ac --- /dev/null +++ b/client/src/app/helpers/utils/object.ts | |||
@@ -0,0 +1,47 @@ | |||
1 | function immutableAssign <A, B> (target: A, source: B) { | ||
2 | return Object.assign({}, target, source) | ||
3 | } | ||
4 | |||
5 | function removeElementFromArray <T> (arr: T[], elem: T) { | ||
6 | const index = arr.indexOf(elem) | ||
7 | if (index !== -1) arr.splice(index, 1) | ||
8 | } | ||
9 | |||
10 | function sortBy (obj: any[], key1: string, key2?: string) { | ||
11 | return obj.sort((a, b) => { | ||
12 | const elem1 = key2 ? a[key1][key2] : a[key1] | ||
13 | const elem2 = key2 ? b[key1][key2] : b[key1] | ||
14 | |||
15 | if (elem1 < elem2) return -1 | ||
16 | if (elem1 === elem2) return 0 | ||
17 | return 1 | ||
18 | }) | ||
19 | } | ||
20 | |||
21 | function intoArray (value: any) { | ||
22 | if (!value) return undefined | ||
23 | if (Array.isArray(value)) return value | ||
24 | |||
25 | if (typeof value === 'string') return value.split(',') | ||
26 | |||
27 | return [ value ] | ||
28 | } | ||
29 | |||
30 | function toBoolean (value: any) { | ||
31 | if (!value) return undefined | ||
32 | |||
33 | if (typeof value === 'boolean') return value | ||
34 | |||
35 | if (value === 'true') return true | ||
36 | if (value === 'false') return false | ||
37 | |||
38 | return undefined | ||
39 | } | ||
40 | |||
41 | export { | ||
42 | sortBy, | ||
43 | immutableAssign, | ||
44 | removeElementFromArray, | ||
45 | intoArray, | ||
46 | toBoolean | ||
47 | } | ||