2017-05-15 20:22:03 +00:00
|
|
|
import expressValidator = require('express-validator')
|
|
|
|
// TODO: use .validator when express-validator typing will have validator field
|
|
|
|
const validator = expressValidator['validator']
|
2016-08-21 08:08:40 +00:00
|
|
|
|
2017-05-15 20:22:03 +00:00
|
|
|
import { isArray } from './misc'
|
2016-12-28 14:49:23 +00:00
|
|
|
|
|
|
|
function isHostValid (host) {
|
|
|
|
return validator.isURL(host) && host.split('://').length === 1
|
2016-08-21 08:08:40 +00:00
|
|
|
}
|
|
|
|
|
2016-11-14 19:03:04 +00:00
|
|
|
function isEachUniqueHostValid (hosts) {
|
2017-05-15 20:22:03 +00:00
|
|
|
return isArray(hosts) &&
|
2016-11-14 19:03:04 +00:00
|
|
|
hosts.length !== 0 &&
|
|
|
|
hosts.every(function (host) {
|
2016-12-28 14:49:23 +00:00
|
|
|
return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host)
|
2016-08-21 08:08:40 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-05-15 20:22:03 +00:00
|
|
|
export {
|
|
|
|
isEachUniqueHostValid,
|
|
|
|
isHostValid
|
|
|
|
}
|