UNPKG

diginext-utils

Version:
24 lines 627 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.clamp = clamp; /** * 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 * ``` */ function clamp(value, min, max) { const result = Math.max(min, Math.min(max, value)); return Number.isFinite(result) ? result : 0; } //# sourceMappingURL=clamp.js.map