mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Remove baseClamp.
This commit is contained in:
13
toLength.js
13
toLength.js
@@ -1,4 +1,3 @@
|
||||
import baseClamp from './.internal/baseClamp.js'
|
||||
import toInteger from './toInteger.js'
|
||||
|
||||
/** Used as references for the maximum length and index of an array. */
|
||||
@@ -30,7 +29,17 @@ const MAX_ARRAY_LENGTH = 4294967295
|
||||
* // => 3
|
||||
*/
|
||||
function toLength(value) {
|
||||
return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0
|
||||
if (!value) {
|
||||
return 0
|
||||
}
|
||||
value = toInteger(value)
|
||||
if (value < 0) {
|
||||
return 0
|
||||
}
|
||||
if (value > MAX_ARRAY_LENGTH) {
|
||||
return MAX_ARRAY_LENGTH
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
export default toLength
|
||||
|
||||
Reference in New Issue
Block a user