mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
22 lines
661 B
JavaScript
22 lines
661 B
JavaScript
![]() |
/**
|
||
|
* Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer)
|
||
|
* of an array-like value.
|
||
|
*/
|
||
|
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
|
||
|
|
||
|
/**
|
||
|
* Checks if `value` is a valid array-like index.
|
||
|
*
|
||
|
* @private
|
||
|
* @param {*} value The value to check.
|
||
|
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
||
|
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
||
|
*/
|
||
|
function isIndex(value, length) {
|
||
|
value = +value;
|
||
|
length = length == null ? MAX_SAFE_INTEGER : length;
|
||
|
return value > -1 && value % 1 == 0 && value < length;
|
||
|
}
|
||
|
|
||
|
module.exports = isIndex;
|