1
0
Fork 0
peertube/server/helpers/custom-validators/pods.ts

32 lines
696 B
TypeScript
Raw Normal View History

2017-06-05 19:53:49 +00:00
import * as validator from 'validator'
2017-06-10 20:15:25 +00:00
import { isArray, exists } from './misc'
2016-12-28 14:49:23 +00:00
2017-06-10 20:15:25 +00:00
function isHostValid (host: string) {
return exists(host) && validator.isURL(host) && host.split('://').length === 1
}
2017-06-10 20:15:25 +00:00
function isEachUniqueHostValid (hosts: string[]) {
2017-05-15 20:22:03 +00:00
return isArray(hosts) &&
hosts.length !== 0 &&
2017-07-11 15:04:57 +00:00
hosts.every(host => {
2016-12-28 14:49:23 +00:00
return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host)
})
}
// ---------------------------------------------------------------------------
2017-05-15 20:22:03 +00:00
export {
isEachUniqueHostValid,
isHostValid
}
2017-06-10 20:15:25 +00:00
declare global {
namespace ExpressValidator {
export interface Validator {
isEachUniqueHostValid
isHostValid
}
}
}