@catho/quantum
Version:
Catho react components
35 lines (34 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var valueValidator = function valueValidator(props, propName, componentName) {
var value = props[propName];
var max = props.max,
min = props.min;
var errorMessage = "".concat(propName, " prop supplied to ").concat(componentName, " is out of bounds. The ").concat(propName, " prop must be between ").concat(min, " and ").concat(max, ".");
var isNumber = function isNumber(val) {
return typeof val === 'number';
};
if (_typeof(value) === 'object') {
var from = value.from,
to = value.to;
if (!isNumber(from) || !isNumber(to)) {
return new Error("The 'from' and 'to' keys from ".concat(propName, " prop must be a Number."));
}
if (from < min || to > max) {
return new Error(errorMessage);
}
return null;
}
if (!isNumber(value) && value !== undefined) {
return new Error("".concat(propName, " prop must be a Number."));
}
if (value < min || value > max) {
return new Error(errorMessage);
}
return null;
};
var _default = exports["default"] = valueValidator;