isIndex.cjs 877 B

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