Spaces:
Paused
Paused
Download src/utils/validators/getValidNumber.mts from jbilcke-hf/VideoChain-API: direct link, hf CLI and curl.
- Browser
- Download file 360 Bytes
-
https://huggingface.co/spaces/jbilcke-hf/VideoChain-API/resolve/cd4ee95e1e76fb32012ff8216dcaad5839176a8a/src/utils/validators/getValidNumber.mts
- Command line
-
hf download hf://spaces/jbilcke-hf/VideoChain-API@cd4ee95e1e76fb32012ff8216dcaad5839176a8a/src/utils/validators/getValidNumber.mts
-
curl -L -o getValidNumber.mts https://huggingface.co/spaces/jbilcke-hf/VideoChain-API/resolve/cd4ee95e1e76fb32012ff8216dcaad5839176a8a/src/utils/validators/getValidNumber.mts
360 Bytes
| 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)) | |
| } |