File size: 360 Bytes
5dd2af5 |
1 2 3 4 5 6 7 8 9 10 |
export const getValidNumber = (something: any, minValue: number, maxValue: number, defaultValue: number) => {
const strValue = `${something || defaultValue}`
const numValue = Number(strValue)
const isValid = !isNaN(numValue) && isFinite(numValue)
if (!isValid) {
return defaultValue
}
return Math.max(minValue, Math.min(maxValue, numValue))
} |