ohctechv3/.svn/pristine/15/15b2f7acf80e5568156fa5d0e6241f5d768206b4.svn-base
2024-10-28 15:03:36 +05:30

58 lines
1.6 KiB
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.getTypeByValue = getTypeByValue;
function getTypeByValue(value) {
const valueType = typeof value;
switch (valueType) {
case 'number':
if (Number.isNaN(value)) {
return 'NaN';
}
if (!Number.isFinite(value)) {
return 'Infinity';
}
if (value !== Math.floor(value)) {
return 'float';
}
return 'number';
case 'object':
if (value === null) {
return 'null';
}
return value.constructor.name;
default:
return valueType;
}
}
// IE 11 support
function ponyfillIsInteger(x) {
// eslint-disable-next-line no-restricted-globals
return typeof x === 'number' && isFinite(x) && Math.floor(x) === x;
}
const isInteger = Number.isInteger || ponyfillIsInteger;
function requiredInteger(props, propName, componentName, location) {
const propValue = props[propName];
if (propValue == null || !isInteger(propValue)) {
const propType = getTypeByValue(propValue);
return new RangeError(`Invalid ${location} \`${propName}\` of type \`${propType}\` supplied to \`${componentName}\`, expected \`integer\`.`);
}
return null;
}
function validator(props, propName, ...other) {
const propValue = props[propName];
if (propValue === undefined) {
return null;
}
return requiredInteger(props, propName, ...other);
}
function validatorNoop() {
return null;
}
validator.isRequired = requiredInteger;
validatorNoop.isRequired = validatorNoop;
var _default = exports.default = process.env.NODE_ENV === 'production' ? validatorNoop : validator;