"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.makeValidator = void 0;

/**
 * Make a custom PropType validator, with the usual "MyProp()" and
 * "MyProp.isRequired()" behavior.
 *
 * @param isValid {Function}
 * @param errMsg {String}
 * @private
 */
var makeValidator = function makeValidator(isValid, errMsg) {
  var propTypeValidator = function propTypeValidator(required) {
    return function (props, propName, componentName) {
      var invalid = function invalid() {
        return Error("Invalid prop ".concat(propName, " supplied to ").concat(componentName, ". ").concat(errMsg));
      };

      var val = props[propName];

      if (val === null || val === undefined) {
        return required ? invalid() : null;
      } else {
        return !isValid(val) ? invalid() : null;
      }
    };
  };

  var validator = propTypeValidator(false);
  validator.isRequired = propTypeValidator(true);
  return validator;
};

exports.makeValidator = makeValidator;