mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Add video filters to common video pages
This commit is contained in:
parent
2e80d256cc
commit
dd24f1bb0a
97 changed files with 2610 additions and 1896 deletions
47
client/src/app/helpers/utils/object.ts
Normal file
47
client/src/app/helpers/utils/object.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
function immutableAssign <A, B> (target: A, source: B) {
|
||||
return Object.assign({}, target, source)
|
||||
}
|
||||
|
||||
function removeElementFromArray <T> (arr: T[], elem: T) {
|
||||
const index = arr.indexOf(elem)
|
||||
if (index !== -1) arr.splice(index, 1)
|
||||
}
|
||||
|
||||
function sortBy (obj: any[], key1: string, key2?: string) {
|
||||
return obj.sort((a, b) => {
|
||||
const elem1 = key2 ? a[key1][key2] : a[key1]
|
||||
const elem2 = key2 ? b[key1][key2] : b[key1]
|
||||
|
||||
if (elem1 < elem2) return -1
|
||||
if (elem1 === elem2) return 0
|
||||
return 1
|
||||
})
|
||||
}
|
||||
|
||||
function intoArray (value: any) {
|
||||
if (!value) return undefined
|
||||
if (Array.isArray(value)) return value
|
||||
|
||||
if (typeof value === 'string') return value.split(',')
|
||||
|
||||
return [ value ]
|
||||
}
|
||||
|
||||
function toBoolean (value: any) {
|
||||
if (!value) return undefined
|
||||
|
||||
if (typeof value === 'boolean') return value
|
||||
|
||||
if (value === 'true') return true
|
||||
if (value === 'false') return false
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
export {
|
||||
sortBy,
|
||||
immutableAssign,
|
||||
removeElementFromArray,
|
||||
intoArray,
|
||||
toBoolean
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue