1
|
var isInteger = require('./isInteger');
|
2
|
|
3
|
/** Used as references for various `Number` constants. */
|
4
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
5
|
|
6
|
/**
|
7
|
* Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
|
8
|
* double precision number which isn't the result of a rounded unsafe integer.
|
9
|
*
|
10
|
* **Note:** This method is based on
|
11
|
* [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
|
12
|
*
|
13
|
* @static
|
14
|
* @memberOf _
|
15
|
* @since 4.0.0
|
16
|
* @category Lang
|
17
|
* @param {*} value The value to check.
|
18
|
* @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
|
19
|
* @example
|
20
|
*
|
21
|
* _.isSafeInteger(3);
|
22
|
* // => true
|
23
|
*
|
24
|
* _.isSafeInteger(Number.MIN_VALUE);
|
25
|
* // => false
|
26
|
*
|
27
|
* _.isSafeInteger(Infinity);
|
28
|
* // => false
|
29
|
*
|
30
|
* _.isSafeInteger('3');
|
31
|
* // => false
|
32
|
*/
|
33
|
function isSafeInteger(value) {
|
34
|
return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
|
35
|
}
|
36
|
|
37
|
module.exports = isSafeInteger;
|