@thinice/clamp
v0.1.4
Published
Clamps a number between min and max values
Readme
@thinice/clamp
Clamps a number between min and max values.
Installation
npm install @thinice/clampUsage
import { clamp } from "@thinice/clamp";
clamp(5, 0, 10); // 5
clamp(15, 0, 10); // 10
clamp(-5, 0, 10); // 0
clamp(7.5, 0, 10); // 7.5Errors
Throws if min > max:
clamp(5, 10, 0); // Error: min must be less than or equal to maxThrows if any argument is NaN:
clamp(NaN, 0, 10); // Error: clamp arguments must not be NaNSource
https://github.com/thinicejs/utils/tree/main/packages/clamp
