Skip to content

Commit b1bfc08

Browse files
committed
fix(utils): Fix clamp return wrong value when value is smaller than min value
1 parent 02e20de commit b1bfc08

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

packages/common/utils/src/clamp.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { clamp } from './clamp';
22

33
describe('clamp', () => {
44
it('should work well when only given max value', () => {
5-
expect(clamp(3, 5)).toBe(3);
5+
expect(clamp(3, 5)).toBe(5);
66
expect(clamp(10, 6)).toBe(6);
77
expect(clamp(6, 10)).toBe(6);
88
});

packages/common/utils/src/clamp.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** @tossdocs-ignore */
22
export function clamp(value: number, bound1: number, bound2?: number) {
33
if (bound2 == null) {
4-
return Math.min(value, bound1);
4+
return Math.max(value, bound1);
55
}
66

77
if (bound2 < bound1) {

0 commit comments

Comments
 (0)