1 import validator from 'validator'
2 import { exists, isArray } from './misc'
3 import { isTestInstance } from '../core-utils'
4 import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
6 function isHostValid (host: string) {
12 // We validate 'localhost', so we don't have the top level domain
13 if (isTestInstance()) {
14 isURLOptions.require_tld = false
17 return exists(host) && validator.isURL(host, isURLOptions) && host.split('://').length === 1
20 function isEachUniqueHostValid (hosts: string[]) {
21 return isArray(hosts) &&
23 return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host)
27 function isValidContactBody (value: any) {
28 return exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.CONTACT_FORM.BODY)
31 function isValidContactFromName (value: any) {
32 return exists(value) && validator.isLength(value, CONSTRAINTS_FIELDS.CONTACT_FORM.FROM_NAME)
35 // ---------------------------------------------------------------------------
39 isValidContactFromName,
40 isEachUniqueHostValid,