aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/helpers/custom-validators/follows.ts
blob: 8f65552c33ba48525972c0f6859076852b97dda6 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                        







                                                    













                                                                                                   


                                                                              


                         
 
import { exists, isArray } from './misc'
import { FollowState } from '@shared/models'

function isFollowStateValid (value: FollowState) {
  if (!exists(value)) return false

  return value === 'pending' || value === 'accepted'
}

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)
    })
}

// ---------------------------------------------------------------------------

export {
  isFollowStateValid,
  isRemoteHandleValid,
  isEachUniqueHandleValid
}