main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[d24f17c] | 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 |
|
---|
| 23 | var _isArrayLike =
|
---|
| 24 | /*#__PURE__*/
|
---|
| 25 | _curry1(function isArrayLike(x) {
|
---|
| 26 | if (_isArray(x)) {
|
---|
| 27 | return true;
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | if (!x) {
|
---|
| 31 | return false;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | if (typeof x !== 'object') {
|
---|
| 35 | return false;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | if (_isString(x)) {
|
---|
| 39 | return false;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | if (x.length === 0) {
|
---|
| 43 | return true;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | if (x.length > 0) {
|
---|
| 47 | return x.hasOwnProperty(0) && x.hasOwnProperty(x.length - 1);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | return false;
|
---|
| 51 | });
|
---|
| 52 |
|
---|
| 53 | export default _isArrayLike; |
---|
Note:
See
TracBrowser
for help on using the repository browser.