Remove baseClamp.

This commit is contained in:
John-David Dalton
2017-03-11 21:44:14 -08:00
parent fa8c607742
commit 3b302b822c
6 changed files with 45 additions and 38 deletions

View File

@@ -1,4 +1,3 @@
import baseClamp from './.internal/baseClamp.js'
import toInteger from './toInteger.js'
/** Used as references for various `Number` constants. */
@@ -27,9 +26,17 @@ const MAX_SAFE_INTEGER = 9007199254740991
* // => 3
*/
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
? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
: (value === 0 ? value : 0)
}
export default toSafeInteger