UNPKG

@age/quantum

Version:
47 lines (35 loc) 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } 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 = valueValidator; exports.default = _default;