1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 09:49:20 +02:00
Peertube/client/src/app/helpers/utils/object.ts
2023-08-28 16:17:31 +02:00

37 lines
795 B
TypeScript

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 splitIntoArray (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
if (value === '1') return true
if (value === '0') return false
return undefined
}
export {
immutableAssign,
removeElementFromArray,
splitIntoArray,
toBoolean
}