Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / isIndex.js
1 /** Used to detect unsigned integer values. */
2 var reIsUint = /^\d+$/;
3
4 /**
5  * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
6  * of an array-like value.
7  */
8 var MAX_SAFE_INTEGER = 9007199254740991;
9
10 /**
11  * Checks if `value` is a valid array-like index.
12  *
13  * @private
14  * @param {*} value The value to check.
15  * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
16  * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
17  */
18 function isIndex(value, length) {
19   value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
20   length = length == null ? MAX_SAFE_INTEGER : length;
21   return value > -1 && value % 1 == 0 && value < length;
22 }
23
24 module.exports = isIndex;