kopia lustrzana https://github.com/shoelace-style/shoelace
never return -0
rodzic
68ed69292c
commit
0df27cf730
|
@ -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);
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue