mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
Enhance clamp with toNumber to allow binary and octal strings.
This commit is contained in:
committed by
John-David Dalton
parent
1d58823405
commit
ec8ccbcc55
@@ -11264,19 +11264,19 @@
|
||||
* // => 5
|
||||
*/
|
||||
function clamp(number, min, max) {
|
||||
number = +number;
|
||||
number = toNumber(number);
|
||||
if (number === number) {
|
||||
if (max === undefined) {
|
||||
max = min;
|
||||
min = undefined;
|
||||
}
|
||||
if (max !== undefined) {
|
||||
max = +max;
|
||||
max = toNumber(max);
|
||||
max = max === max ? max : 0;
|
||||
number = number <= max ? number : max;
|
||||
}
|
||||
if (min !== undefined) {
|
||||
min = +min;
|
||||
min = toNumber(min);
|
||||
min = min === min ? min : 0;
|
||||
number = number >= min ? number : min;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user