isLength.js 644 B

1234567891011121314151617181920
  1. /**
  2. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  3. * of an array-like value.
  4. */
  5. var MAX_SAFE_INTEGER = 9007199254740991;
  6. /**
  7. * Checks if `value` is a valid array-like length.
  8. *
  9. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  10. *
  11. * @private
  12. * @param {*} value The value to check.
  13. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  14. */
  15. function isLength(value) {
  16. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  17. }
  18. module.exports = isLength;