1 /** Used as references for various `Number` constants. */
2 var MAX_SAFE_INTEGER = 9007199254740991;
4 /** Used to detect unsigned integer values. */
5 var reIsUint = /^(?:0|[1-9]\d*)$/;
8 * Checks if `value` is a valid array-like index.
11 * @param {*} value The value to check.
12 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
13 * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
15 function isIndex(value, length) {
16 value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
17 length = length == null ? MAX_SAFE_INTEGER : length;
18 return value > -1 && value % 1 == 0 && value < length;
21 module.exports = isIndex;