-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
_isArrayLike.js
35 lines (33 loc) · 1.04 KB
/
_isArrayLike.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import _curry1 from './_curry1';
import _isArray from './_isArray';
import _isString from './_isString';
/**
* Tests whether or not an object is similar to an array.
*
* @private
* @category Type
* @category List
* @sig * -> Boolean
* @param {*} x The object to test.
* @return {Boolean} `true` if `x` has a numeric length property and extreme indices defined; `false` otherwise.
* @example
*
* _isArrayLike([]); //=> true
* _isArrayLike(true); //=> false
* _isArrayLike({}); //=> false
* _isArrayLike({length: 10}); //=> false
* _isArrayLike({0: 'zero', 9: 'nine', length: 10}); //=> true
*/
var _isArrayLike = _curry1(function isArrayLike(x) {
if (_isArray(x)) { return true; }
if (!x) { return false; }
if (typeof x !== 'object') { return false; }
if (_isString(x)) { return false; }
if (x.nodeType === 1) { return !!x.length; }
if (x.length === 0) { return true; }
if (x.length > 0) {
return x.hasOwnProperty(0) && x.hasOwnProperty(x.length - 1);
}
return false;
});
export default _isArrayLike;