Travis build: 743 [ci skip]
This commit is contained in:
18
README.md
18
README.md
@ -4088,24 +4088,22 @@ isArray([1]); // true
|
|||||||
|
|
||||||
Checks if the provided argument is array-like (i.e. is iterable).
|
Checks if the provided argument is array-like (i.e. is iterable).
|
||||||
|
|
||||||
Use `Array.from()` and a `try... catch` block to check if the provided argument is array-like.
|
Check that the object is not a function or `null` and that its `length` property is a non-negative integer below `Number.MAX_SAFE_INTEGER`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const isArrayLike = arr => {
|
const isArrayLike = val =>
|
||||||
try {
|
val != null &&
|
||||||
Array.from(arr);
|
typeof val != 'function' &&
|
||||||
return true;
|
val.length > -1 &&
|
||||||
} catch (e) {
|
val.length % 1 == 0 &&
|
||||||
return false;
|
val.length <= Number.MAX_SAFE_INTEGER;
|
||||||
}
|
|
||||||
};
|
|
||||||
```
|
```
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary>Examples</summary>
|
<summary>Examples</summary>
|
||||||
|
|
||||||
```js
|
```js
|
||||||
isArrayLike(document.querySelector('.className')); // true
|
isArrayLike(document.querySelectorAll('.className')); // true
|
||||||
isArrayLike('abc'); // true
|
isArrayLike('abc'); // true
|
||||||
isArrayLike(null); // false
|
isArrayLike(null); // false
|
||||||
```
|
```
|
||||||
|
|||||||
@ -853,15 +853,13 @@ hexToRGB('#fff'); // 'rgb(255, 255, 255)'
|
|||||||
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="isarray">isArray</h3></div><div class="section double-padded"><p>Checks if the given argument is an array.</p><p>Use <code>Array.isArray()</code> to check if a value is classified as an array.</p><pre><code class="language-js">const isArray = val => !!val && Array.isArray(val);
|
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="isarray">isArray</h3></div><div class="section double-padded"><p>Checks if the given argument is an array.</p><p>Use <code>Array.isArray()</code> to check if a value is classified as an array.</p><pre><code class="language-js">const isArray = val => !!val && Array.isArray(val);
|
||||||
</code></pre><pre><code class="language-js">isArray(null); // false
|
</code></pre><pre><code class="language-js">isArray(null); // false
|
||||||
isArray([1]); // true
|
isArray([1]); // true
|
||||||
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="isarraylike">isArrayLike</h3></div><div class="section double-padded"><p>Checks if the provided argument is array-like (i.e. is iterable).</p><p>Use <code>Array.from()</code> and a <code>try... catch</code> block to check if the provided argument is array-like.</p><pre><code class="language-js">const isArrayLike = arr => {
|
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="isarraylike">isArrayLike</h3></div><div class="section double-padded"><p>Checks if the provided argument is array-like (i.e. is iterable).</p><p>Check that the object is not a function or <code>null</code> and that its <code>length</code> property is a non-negative integer below <code>Number.MAX_SAFE_INTEGER</code>.</p><pre><code class="language-js">const isArrayLike = val =>
|
||||||
try {
|
val != null &&
|
||||||
Array.from(arr);
|
typeof val != 'function' &&
|
||||||
return true;
|
val.length > -1 &&
|
||||||
} catch (e) {
|
val.length % 1 == 0 &&
|
||||||
return false;
|
val.length <= Number.MAX_SAFE_INTEGER;
|
||||||
}
|
</code></pre><pre><code class="language-js">isArrayLike(document.querySelectorAll('.className')); // true
|
||||||
};
|
|
||||||
</code></pre><pre><code class="language-js">isArrayLike(document.querySelector('.className')); // true
|
|
||||||
isArrayLike('abc'); // true
|
isArrayLike('abc'); // true
|
||||||
isArrayLike(null); // false
|
isArrayLike(null); // false
|
||||||
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="isboolean">isBoolean</h3></div><div class="section double-padded"><p>Checks if the given argument is a native boolean element.</p><p>Use <code>typeof</code> to check if a value is classified as a boolean primitive.</p><pre><code class="language-js">const isBoolean = val => typeof val === 'boolean';
|
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="isboolean">isBoolean</h3></div><div class="section double-padded"><p>Checks if the given argument is a native boolean element.</p><p>Use <code>typeof</code> to check if a value is classified as a boolean primitive.</p><pre><code class="language-js">const isBoolean = val => typeof val === 'boolean';
|
||||||
|
|||||||
@ -5,8 +5,12 @@ Checks if the provided argument is array-like (i.e. is iterable).
|
|||||||
Check that the object is not a function or `null` and that its `length` property is a non-negative integer below `Number.MAX_SAFE_INTEGER`.
|
Check that the object is not a function or `null` and that its `length` property is a non-negative integer below `Number.MAX_SAFE_INTEGER`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const isArrayLike = val =>
|
const isArrayLike = val =>
|
||||||
val != null && typeof val != 'function' && val.length > -1 && val.length % 1 == 0 && val.length <= Number.MAX_SAFE_INTEGER;
|
val != null &&
|
||||||
|
typeof val != 'function' &&
|
||||||
|
val.length > -1 &&
|
||||||
|
val.length % 1 == 0 &&
|
||||||
|
val.length <= Number.MAX_SAFE_INTEGER;
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user