isArrayLike.js 830 B

12345678910111213141516171819202122232425262728293031323334
  1. var isFunction = require('./isFunction'),
  2. isLength = require('./isLength');
  3. /**
  4. * Checks if `value` is array-like. A value is considered array-like if it's
  5. * not a function and has a `value.length` that's an integer greater than or
  6. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  7. *
  8. * @static
  9. * @memberOf _
  10. * @since 4.0.0
  11. * @category Lang
  12. * @param {*} value The value to check.
  13. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  14. * @example
  15. *
  16. * _.isArrayLike([1, 2, 3]);
  17. * // => true
  18. *
  19. * _.isArrayLike(document.body.children);
  20. * // => true
  21. *
  22. * _.isArrayLike('abc');
  23. * // => true
  24. *
  25. * _.isArrayLike(_.noop);
  26. * // => false
  27. */
  28. function isArrayLike(value) {
  29. return value != null && isLength(value.length) && !isFunction(value);
  30. }
  31. module.exports = isArrayLike;