/**
 * @fileoverview added by tsickle
 * Generated from: form/validators.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
/*!
 * Copyright 2020 VMware, Inc.
 * SPDX-License-Identifier: BSD-2-Clause
 */
import { Validators } from '@angular/forms';
/**
 * validators used for form control validations.
 */
var /**
 * validators used for form control validations.
 */
FormValidators = /** @class */ (function () {
    function FormValidators() {
    }
    /**
     * A wrapper that validates that a control's value is defined before running the validator function.
     *
     * @param validator The validator function to run if the control's value is defined.
     */
    /**
     * A wrapper that validates that a control's value is defined before running the validator function.
     *
     * @param {?} validator The validator function to run if the control's value is defined.
     * @return {?}
     */
    FormValidators.createNullSafeValidator = /**
     * A wrapper that validates that a control's value is defined before running the validator function.
     *
     * @param {?} validator The validator function to run if the control's value is defined.
     * @return {?}
     */
    function (validator) {
        /** @type {?} */
        var res = (/**
         * @param {?} control
         * @return {?}
         */
        function (control) {
            if (Validators.required(control)) {
                return null;
            }
            return validator(control);
        });
        return res;
    };
    /**
     * Create a validator that requires a number to be within a range.
     * Also checks that the value is numeric
     * Accepts a translation key to display proper error messaging
     */
    /**
     * Create a validator that requires a number to be within a range.
     * Also checks that the value is numeric
     * Accepts a translation key to display proper error messaging
     * @param {?} min
     * @param {?} max
     * @param {?=} translationKey
     * @return {?}
     */
    FormValidators.isNumberInRange = /**
     * Create a validator that requires a number to be within a range.
     * Also checks that the value is numeric
     * Accepts a translation key to display proper error messaging
     * @param {?} min
     * @param {?} max
     * @param {?=} translationKey
     * @return {?}
     */
    function (min, max, translationKey) {
        if (translationKey === void 0) { translationKey = 'vcd.cc.warning.numRange'; }
        /** @type {?} */
        var res = FormValidators.createNullSafeValidator((/**
         * @param {?} control
         * @return {?}
         */
        function (control) {
            var _a;
            /** @type {?} */
            var isNumber = !isNaN(parseFloat(control.value)) && isFinite(control.value);
            return control.value >= min && control.value <= max && isNumber ? null : (_a = {}, _a[translationKey] = true, _a);
        }));
        return res;
    };
    return FormValidators;
}());
/**
 * validators used for form control validations.
 */
export { FormValidators };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdG9ycy5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0B2Y2QvdWktY29tcG9uZW50cy8iLCJzb3VyY2VzIjpbImZvcm0vdmFsaWRhdG9ycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFLQSxPQUFPLEVBQTRCLFVBQVUsRUFBRSxNQUFNLGdCQUFnQixDQUFDOzs7O0FBS3RFOzs7O0lBQUE7SUE0QkEsQ0FBQztJQTNCRzs7OztPQUlHOzs7Ozs7O0lBQ0ksc0NBQXVCOzs7Ozs7SUFBOUIsVUFBK0IsU0FBc0M7O1lBQzNELEdBQUc7Ozs7UUFBRyxVQUFDLE9BQW9CO1lBQzdCLElBQUksVUFBVSxDQUFDLFFBQVEsQ0FBQyxPQUFPLENBQUMsRUFBRTtnQkFDOUIsT0FBTyxJQUFJLENBQUM7YUFDZjtZQUNELE9BQU8sU0FBUyxDQUFDLE9BQU8sQ0FBQyxDQUFDO1FBQzlCLENBQUMsQ0FBQTtRQUNELE9BQU8sR0FBRyxDQUFDO0lBQ2YsQ0FBQztJQUVEOzs7O09BSUc7Ozs7Ozs7Ozs7SUFDSSw4QkFBZTs7Ozs7Ozs7O0lBQXRCLFVBQXVCLEdBQVcsRUFBRSxHQUFXLEVBQUUsY0FBMEM7UUFBMUMsK0JBQUEsRUFBQSwwQ0FBMEM7O1lBQ2pGLEdBQUcsR0FBRyxjQUFjLENBQUMsdUJBQXVCOzs7O1FBQUMsVUFBQyxPQUFZOzs7Z0JBQ3RELFFBQVEsR0FBRyxDQUFDLEtBQUssQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLEtBQUssQ0FBQyxDQUFDLElBQUksUUFBUSxDQUFDLE9BQU8sQ0FBQyxLQUFLLENBQUM7WUFDN0UsT0FBTyxPQUFP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