From ffd6c5867fbbeeb19f12574f818863c8e5a8216a Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Wed, 12 Feb 2025 19:53:05 +0100 Subject: [PATCH] Fix "coerceIn" for calls with max < min Previously the min value was ignored in case the max value was less than the min value. E.g. coerceIn(5, 0, -1) would be -1 instead of 0 --- src/lib/HelperFunctions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/HelperFunctions.ts b/src/lib/HelperFunctions.ts index 9561089b..3cac3606 100644 --- a/src/lib/HelperFunctions.ts +++ b/src/lib/HelperFunctions.ts @@ -38,6 +38,6 @@ export const getValueFromObject = (obj: Record, key: string): T return keys.reduce((acc, curr) => acc?.[curr], obj) as T; }; -export const coerceIn = (value: number, min: number, max: number): number => Math.min(Math.max(value, min), max); +export const coerceIn = (value: number, min: number, max: number): number => Math.max(Math.min(value, max), min); export const noOp = () => {};