]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/helpers/custom-validators/pods.ts
Type functions
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / pods.ts
1 import * as validator from 'validator'
2
3 import { isArray, exists } from './misc'
4
5 function isHostValid (host: string) {
6 return exists(host) && validator.isURL(host) && host.split('://').length === 1
7 }
8
9 function isEachUniqueHostValid (hosts: string[]) {
10 return isArray(hosts) &&
11 hosts.length !== 0 &&
12 hosts.every(function (host) {
13 return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host)
14 })
15 }
16
17 // ---------------------------------------------------------------------------
18
19 export {
20 isEachUniqueHostValid,
21 isHostValid
22 }
23
24 declare global {
25 namespace ExpressValidator {
26 export interface Validator {
27 isEachUniqueHostValid
28 isHostValid
29 }
30 }
31 }