Source

validators/createKeyValidator.js

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var validateCaseInsensitiveKey_1 = __importDefault(require("./validateCaseInsensitiveKey"));
var isArr_1 = __importDefault(require("../array/isArr"));
/**
 * Create a validator of the case-insensitive key
 *
 * e.g. const isStatusDraft = createKeyValidator<PublishableStatus, StatusDraft>(STATUS_DRAFT)
 *
 * @param target Target string constant, or array of validators.
 * @category validators
 * @module createKeyValidator
 */
function createKeyValidator(target) {
    return function (type) {
        if ((0, isArr_1.default)(target))
            return target.some(function (validate) { return validate(type); });
        return (0, validateCaseInsensitiveKey_1.default)(target, type);
    };
}
exports.default = createKeyValidator;