1 import * as validator from 'validator'
2 import 'express-validator'
4 import { isArray, exists } from './misc'
5 import { isTestInstance } from '../core-utils'
6 import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
8 function isHostValid (host: string) {
14 // We validate 'localhost', so we don't have the top level domain
15 if (isTestInstance()) {
16 isURLOptions.require_tld = false
19 return exists(host) && validator.isURL(host, isURLOptions) && host.split('://').length === 1
22 function isEachUniqueHostValid (hosts: string[]) {
23 return isArray(hosts) &&
26 return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host)
30 function isValidContactBody (value: any) {
31 return exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.CONTACT_FORM.BODY)
34 function isValidContactFromName (value: any) {
35 return exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.CONTACT_FORM.FROM_NAME)
38 // ---------------------------------------------------------------------------
42 isValidContactFromName,
43 isEachUniqueHostValid,