_isArrayLike.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import _curry1 from "./_curry1.js";
  2. import _isArray from "./_isArray.js";
  3. import _isString from "./_isString.js";
  4. /**
  5. * Tests whether or not an object is similar to an array.
  6. *
  7. * @private
  8. * @category Type
  9. * @category List
  10. * @sig * -> Boolean
  11. * @param {*} x The object to test.
  12. * @return {Boolean} `true` if `x` has a numeric length property and extreme indices defined; `false` otherwise.
  13. * @example
  14. *
  15. * _isArrayLike([]); //=> true
  16. * _isArrayLike(true); //=> false
  17. * _isArrayLike({}); //=> false
  18. * _isArrayLike({length: 10}); //=> false
  19. * _isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true
  20. * _isArrayLike({nodeType: 1, length: 1}) // => false
  21. */
  22. var _isArrayLike =
  23. /*#__PURE__*/
  24. _curry1(function isArrayLike(x) {
  25. if (_isArray(x)) {
  26. return true;
  27. }
  28. if (!x) {
  29. return false;
  30. }
  31. if (typeof x !== 'object') {
  32. return false;
  33. }
  34. if (_isString(x)) {
  35. return false;
  36. }
  37. if (x.length === 0) {
  38. return true;
  39. }
  40. if (x.length > 0) {
  41. return x.hasOwnProperty(0) && x.hasOwnProperty(x.length - 1);
  42. }
  43. return false;
  44. });
  45. export default _isArrayLike;