"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get getRegisteredValidatorNames () {
        return getNames;
    },
    get getRegisteredValidators () {
        return getValues;
    },
    get getValidator () {
        return _getItem;
    },
    get hasValidator () {
        return hasItem;
    },
    get registerValidator () {
        return _register;
    }
});
const _staticRegister = require("../utils/staticRegister");
const _errors = require("../helpers/errors");
const { register, getItem, hasItem, getNames, getValues } = (0, _staticRegister.staticRegister)('validators');
/**
 * Retrieve validator function.
 *
 * @param {string} name Validator identification.
 * @returns {Function} Returns validator function.
 */ function _getItem(name) {
    if (typeof name === 'function') {
        return name;
    }
    if (!hasItem(name)) {
        (0, _errors.throwWithCause)(`No registered validator found under "${name}" name`);
    }
    return getItem(name);
}
/**
 * Register validator under its alias.
 *
 * @param {string|Function} name Validator's alias or validator function with its descriptor.
 * @param {Function} [validator] Validator function.
 */ function _register(name, validator) {
    if (typeof name !== 'string') {
        validator = name;
        name = validator.VALIDATOR_TYPE;
    }
    register(name, validator);
}
