mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 03:47:50 +00:00
Remove baseClamp.
This commit is contained in:
@@ -1,18 +0,0 @@
|
|||||||
/**
|
|
||||||
* The base implementation of `clamp` which doesn't coerce arguments.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {number} number The number to clamp.
|
|
||||||
* @param {number} lower The lower bound.
|
|
||||||
* @param {number} upper The upper bound.
|
|
||||||
* @returns {number} Returns the clamped number.
|
|
||||||
*/
|
|
||||||
function baseClamp(number, lower, upper) {
|
|
||||||
if (number === number) {
|
|
||||||
number = number <= upper ? number : upper
|
|
||||||
number = number >= lower ? number : lower
|
|
||||||
}
|
|
||||||
return number
|
|
||||||
}
|
|
||||||
|
|
||||||
export default baseClamp
|
|
||||||
13
clamp.js
13
clamp.js
@@ -1,4 +1,3 @@
|
|||||||
import baseClamp from './.internal/baseClamp.js'
|
|
||||||
import toNumber from './toNumber.js'
|
import toNumber from './toNumber.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,13 +18,17 @@ import toNumber from './toNumber.js'
|
|||||||
* // => 5
|
* // => 5
|
||||||
*/
|
*/
|
||||||
function clamp(number, lower, upper) {
|
function clamp(number, lower, upper) {
|
||||||
|
number = toNumber(number)
|
||||||
lower = toNumber(lower)
|
lower = toNumber(lower)
|
||||||
lower = lower === lower ? lower : 0
|
|
||||||
|
|
||||||
upper = toNumber(upper)
|
upper = toNumber(upper)
|
||||||
upper = upper === upper ? upper : 0
|
|
||||||
|
|
||||||
return baseClamp(toNumber(number), lower, upper)
|
lower = lower === lower ? lower : 0
|
||||||
|
upper = upper === upper ? upper : 0
|
||||||
|
if (number === number) {
|
||||||
|
number = number <= upper ? number : upper
|
||||||
|
number = number >= lower ? number : lower
|
||||||
|
}
|
||||||
|
return number
|
||||||
}
|
}
|
||||||
|
|
||||||
export default clamp
|
export default clamp
|
||||||
|
|||||||
14
endsWith.js
14
endsWith.js
@@ -1,4 +1,3 @@
|
|||||||
import baseClamp from './.internal/baseClamp.js'
|
|
||||||
import baseToString from './.internal/baseToString.js'
|
import baseToString from './.internal/baseToString.js'
|
||||||
import toInteger from './toInteger.js'
|
import toInteger from './toInteger.js'
|
||||||
import toString from './toString.js'
|
import toString from './toString.js'
|
||||||
@@ -29,11 +28,14 @@ function endsWith(string, target, position) {
|
|||||||
string = toString(string)
|
string = toString(string)
|
||||||
target = baseToString(target)
|
target = baseToString(target)
|
||||||
|
|
||||||
const length = string.length
|
const { length } = string
|
||||||
position = position === undefined
|
position = position === undefined ? length : toInteger(position)
|
||||||
? length
|
if (position < 0) {
|
||||||
: baseClamp(toInteger(position), 0, length)
|
position = 0
|
||||||
|
}
|
||||||
|
else if (position > length) {
|
||||||
|
position = length
|
||||||
|
}
|
||||||
const end = position
|
const end = position
|
||||||
position -= target.length
|
position -= target.length
|
||||||
return position >= 0 && string.slice(position, end) == target
|
return position >= 0 && string.slice(position, end) == target
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import baseClamp from './.internal/baseClamp.js'
|
|
||||||
import baseToString from './.internal/baseToString.js'
|
import baseToString from './.internal/baseToString.js'
|
||||||
import toInteger from './toInteger.js'
|
import toInteger from './toInteger.js'
|
||||||
import toString from './toString.js'
|
import toString from './toString.js'
|
||||||
@@ -27,10 +26,15 @@ import toString from './toString.js'
|
|||||||
*/
|
*/
|
||||||
function startsWith(string, target, position) {
|
function startsWith(string, target, position) {
|
||||||
string = toString(string)
|
string = toString(string)
|
||||||
position = position == null
|
|
||||||
? 0
|
|
||||||
: baseClamp(toInteger(position), 0, string.length)
|
|
||||||
|
|
||||||
|
const { length } = string
|
||||||
|
position = position == null ? 0 : toInteger(position)
|
||||||
|
if (position < 0) {
|
||||||
|
position = 0
|
||||||
|
}
|
||||||
|
else if (position > length) {
|
||||||
|
position = length
|
||||||
|
}
|
||||||
target = baseToString(target)
|
target = baseToString(target)
|
||||||
return string.slice(position, position + target.length) == target
|
return string.slice(position, position + target.length) == target
|
||||||
}
|
}
|
||||||
|
|||||||
13
toLength.js
13
toLength.js
@@ -1,4 +1,3 @@
|
|||||||
import baseClamp from './.internal/baseClamp.js'
|
|
||||||
import toInteger from './toInteger.js'
|
import toInteger from './toInteger.js'
|
||||||
|
|
||||||
/** Used as references for the maximum length and index of an array. */
|
/** Used as references for the maximum length and index of an array. */
|
||||||
@@ -30,7 +29,17 @@ const MAX_ARRAY_LENGTH = 4294967295
|
|||||||
* // => 3
|
* // => 3
|
||||||
*/
|
*/
|
||||||
function toLength(value) {
|
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
|
export default toLength
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import baseClamp from './.internal/baseClamp.js'
|
|
||||||
import toInteger from './toInteger.js'
|
import toInteger from './toInteger.js'
|
||||||
|
|
||||||
/** Used as references for various `Number` constants. */
|
/** Used as references for various `Number` constants. */
|
||||||
@@ -27,9 +26,17 @@ const MAX_SAFE_INTEGER = 9007199254740991
|
|||||||
* // => 3
|
* // => 3
|
||||||
*/
|
*/
|
||||||
function toSafeInteger(value) {
|
function toSafeInteger(value) {
|
||||||
|
if (!value) {
|
||||||
|
return value === 0 ? value : 0
|
||||||
|
}
|
||||||
|
value = toInteger(value)
|
||||||
|
if (value < -MAX_SAFE_INTEGER) {
|
||||||
|
return -MAX_SAFE_INTEGER
|
||||||
|
}
|
||||||
|
if (value > MAX_SAFE_INTEGER) {
|
||||||
|
return MAX_SAFE_INTEGER
|
||||||
|
}
|
||||||
return value
|
return value
|
||||||
? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
|
|
||||||
: (value === 0 ? value : 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default toSafeInteger
|
export default toSafeInteger
|
||||||
|
|||||||
Reference in New Issue
Block a user