mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 04:09:12 +00:00
never return -0
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
/** Ensures a number stays within a minimum and maximum value */
|
||||
export function clamp(value: number, min: number, max: number) {
|
||||
const noNegativeZero = (n: number) => (Object.is(n, -0) ? 0 : n);
|
||||
|
||||
if (value < min) {
|
||||
return min;
|
||||
return noNegativeZero(min);
|
||||
}
|
||||
|
||||
if (value > max) {
|
||||
return max;
|
||||
return noNegativeZero(max);
|
||||
}
|
||||
return value;
|
||||
|
||||
return noNegativeZero(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user