mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57: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
|
* // => 5
|
||||||
*/
|
*/
|
||||||
function clamp(number, min, max) {
|
function clamp(number, min, max) {
|
||||||
number = +number;
|
number = toNumber(number);
|
||||||
if (number === number) {
|
if (number === number) {
|
||||||
if (max === undefined) {
|
if (max === undefined) {
|
||||||
max = min;
|
max = min;
|
||||||
min = undefined;
|
min = undefined;
|
||||||
}
|
}
|
||||||
if (max !== undefined) {
|
if (max !== undefined) {
|
||||||
max = +max;
|
max = toNumber(max);
|
||||||
max = max === max ? max : 0;
|
max = max === max ? max : 0;
|
||||||
number = number <= max ? number : max;
|
number = number <= max ? number : max;
|
||||||
}
|
}
|
||||||
if (min !== undefined) {
|
if (min !== undefined) {
|
||||||
min = +min;
|
min = toNumber(min);
|
||||||
min = min === min ? min : 0;
|
min = min === min ? min : 0;
|
||||||
number = number >= min ? number : min;
|
number = number >= min ? number : min;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user