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

                                                                                

 
                                                  
                          

                                 
                                                                                 




                                                                              



                        








                                
import * as validator from 'validator'

import { isArray, exists } from './misc'

function isHostValid (host: string) {
  return exists(host) && validator.isURL(host) && host.split('://').length === 1
}

function isEachUniqueHostValid (hosts: string[]) {
  return isArray(hosts) &&
    hosts.length !== 0 &&
    hosts.every(function (host) {
      return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host)
    })
}

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

export {
  isEachUniqueHostValid,
  isHostValid
}

declare global {
  namespace ExpressValidator {
    export interface Validator {
      isEachUniqueHostValid
      isHostValid
    }
  }
}