UNPKG

diginext-utils

Version:
21 lines 534 B
/** * Clamps a number between a minimum and maximum value. * Returns 0 if the result is not finite. * * @param value - The value to clamp * @param min - The minimum value * @param max - The maximum value * @returns The clamped value * * @example * ```ts * clamp(15, 0, 10); // 10 * clamp(-5, 0, 10); // 0 * clamp(5, 0, 10); // 5 * ``` */ export function clamp(value, min, max) { const result = Math.max(min, Math.min(max, value)); return Number.isFinite(result) ? result : 0; } //# sourceMappingURL=clamp.js.map