2021-07-20 07:15:15 -05:00
|
|
|
import { exists, isArray } from './misc'
|
2019-11-28 04:37:32 -06:00
|
|
|
import { FollowState } from '@shared/models'
|
|
|
|
|
|
|
|
function isFollowStateValid (value: FollowState) {
|
|
|
|
if (!exists(value)) return false
|
|
|
|
|
|
|
|
return value === 'pending' || value === 'accepted'
|
|
|
|
}
|
|
|
|
|
2021-07-20 07:15:15 -05:00
|
|
|
function isRemoteHandleValid (value: string) {
|
|
|
|
if (!exists(value)) return false
|
|
|
|
if (typeof value !== 'string') return false
|
|
|
|
|
|
|
|
return value.includes('@')
|
|
|
|
}
|
|
|
|
|
|
|
|
function isEachUniqueHandleValid (handles: string[]) {
|
|
|
|
return isArray(handles) &&
|
|
|
|
handles.every(handle => {
|
|
|
|
return isRemoteHandleValid(handle) && handles.indexOf(handle) === handles.lastIndexOf(handle)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-11-28 04:37:32 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2021-07-20 07:15:15 -05:00
|
|
|
isFollowStateValid,
|
|
|
|
isRemoteHandleValid,
|
|
|
|
isEachUniqueHandleValid
|
2019-11-28 04:37:32 -06:00
|
|
|
}
|