"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isHostValid = exports.isEachUniqueHostValid = exports.isValidContactFromName = exports.isValidContactBody = void 0;
const tslib_1 = require("tslib");
const validator_1 = tslib_1.__importDefault(require("validator"));
const config_1 = require("../../initializers/config");
const constants_1 = require("../../initializers/constants");
const misc_1 = require("./misc");
function isHostValid(host) {
    const isURLOptions = {
        require_host: true,
        require_tld: true
    };
    if (config_1.CONFIG.WEBSERVER.HOSTNAME === 'localhost') {
        isURLOptions.require_tld = false;
    }
    return (0, misc_1.exists)(host) && validator_1.default.isURL(host, isURLOptions) && host.split('://').length === 1;
}
exports.isHostValid = isHostValid;
function isEachUniqueHostValid(hosts) {
    return (0, misc_1.isArray)(hosts) &&
        hosts.every(host => {
            return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host);
        });
}
exports.isEachUniqueHostValid = isEachUniqueHostValid;
function isValidContactBody(value) {
    return (0, misc_1.exists)(value) && validator_1.default.isLength(value, constants_1.CONSTRAINTS_FIELDS.CONTACT_FORM.BODY);
}
exports.isValidContactBody = isValidContactBody;
function isValidContactFromName(value) {
    return (0, misc_1.exists)(value) && validator_1.default.isLength(value, constants_1.CONSTRAINTS_FIELDS.CONTACT_FORM.FROM_NAME);
}
exports.isValidContactFromName = isValidContactFromName;
//# sourceMappingURL=servers.js.map