@gecut/utilities
Version:
The ultimate utility toolkit from Gecut Company, crafted with TypeScript for optimal speed and efficiency. Designed to boost productivity with a suite of fast and optimized tools.
20 lines • 724 B
JavaScript
export const isNumber = (value) => {
return ((typeof value === 'number' && isFinite(value)) ||
(typeof value === 'string' && value.trim() !== '' && !isNaN(Number(value))));
};
export const sanitizeNumber = (data) => {
return Number(data ?? 0);
};
export const clamp = (min, current, max) => {
return Math.min(max, Math.max(min, current));
};
export const randomNumber = (max, min = 0) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
};
export const randomFloor = (max, min = 0, fixed = 1) => {
const keyNumber = fixed * 10;
return randomNumber(max * keyNumber, min * keyNumber) / keyNumber;
};
//# sourceMappingURL=number.js.map