You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
759 B

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