Add isEmpty
This commit is contained in:
22
snippets/isEmpty.md
Normal file
22
snippets/isEmpty.md
Normal file
@ -0,0 +1,22 @@
|
||||
### isEmpty
|
||||
|
||||
Returns true if the a value is an empty object, collection, map or set, has no enumerable properties or is any type that is not considered a collection.
|
||||
|
||||
Check if the provided value is `null` or if its `length` is equal to `0`.
|
||||
|
||||
```js
|
||||
const isEmpty = val => val == null || !(Object.keys(val) || val).length;
|
||||
```
|
||||
|
||||
```js
|
||||
isEmpty(new Map()); // true
|
||||
isEmpty(new Set()); // true
|
||||
isEmpty([]); // true
|
||||
isEmpty({}); // true
|
||||
isEmpty(''); // true
|
||||
isEmpty([1, 2]); // false
|
||||
isEmpty({ a: 1, b: 2 }); // false
|
||||
isEmpty('text'); // false
|
||||
isEmpty(123); // true - type is not considered a collection
|
||||
isEmpty(true); // true - type is not considered a collection
|
||||
```
|
||||
@ -93,6 +93,7 @@ isAbsoluteURL:string,utility,browser,url
|
||||
isArrayLike:type,array
|
||||
isBoolean:type
|
||||
isDivisible:math
|
||||
isEmpty:type,array,object,string
|
||||
isEven:math
|
||||
isFunction:type,function
|
||||
isLowerCase:string,utility
|
||||
|
||||
Reference in New Issue
Block a user