21 lines
644 B
JavaScript
21 lines
644 B
JavaScript
|
/**
|
||
|
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
|
||
|
* of an array-like value.
|
||
|
*/
|
||
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
||
|
|
||
|
/**
|
||
|
* Checks if `value` is a valid array-like length.
|
||
|
*
|
||
|
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
||
|
*
|
||
|
* @private
|
||
|
* @param {*} value The value to check.
|
||
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
||
|
*/
|
||
|
function isLength(value) {
|
||
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
||
|
}
|
||
|
|
||
|
module.exports = isLength;
|