UNPKG

typedash

Version:

modern, type-safe collection of utility functions

18 lines (17 loc) 579 B
// src/functions/clamp/clamp.ts function clamp(value, range, options) { const [min, max] = range; if (min > max) { throw new RangeError(`Invalid range: [${min},${max}]`); } const { inclusive = true } = options ?? {}; return { true: () => Math.max(min, Math.min(max, value)), false: () => Math.max(min + 1, Math.min(max - 1, value)), min: () => Math.max(min, Math.min(max - 1, value)), max: () => Math.max(min + 1, Math.min(max, value)) }[inclusive](); } export { clamp }; //# sourceMappingURL=out.js.map //# sourceMappingURL=chunk-RP6ATS4O.js.map