UNPKG

typedash

Version:

modern, type-safe collection of utility functions

20 lines (18 loc) 591 B
'use strict'; // 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](); } exports.clamp = clamp; //# sourceMappingURL=out.js.map //# sourceMappingURL=index.cjs.map