Add is.emptyArray/is.nonEmptyArray and for other types #53

This commit is contained in:
Arfat Salman 2018-07-12 03:18:35 +05:30
parent b2bb3e7d37
commit 75c4a387ee
3 changed files with 168 additions and 51 deletions

View file

@ -160,6 +160,67 @@ is.boundFunction(function () {});
##### .sharedArrayBuffer(value)
##### .dataView(value)
#### Emptiness
##### .emptyString(value)
Returns `true` if the value is an empty string. `false` otherwise.
##### .nonEmptyString(value)
Returns `true` if the value is string, and the length > 0. `false` when the string is empty.
##### .emptyStringOrWhitespace(value)
Returns `true` if `is.emptyString(value)` or a string that is all whitespace.
##### .emptyArray(value)
Returns `true` if the value is an array and the `length` is 0.
##### .nonEmptyArray(value)
Returns `true` if the value is an array and the `length` is > 0.
##### .emptyObject(value)
Returns `true` if the value is an object and `Object.keys(value)` length is 0.
Please note that `Object.keys` returns only enumerable properties. Hence something like this can happen -
```js
const object1 = {};
Object.defineProperty(object1, 'property1', {
value: 42,
writable: true,
enumerable: false,
configurable: true
});
is.emptyObject(object1);
// => true
```
##### .nonEmptyObject(value)
Returns `true` if the value is an object and length of `Object.keys(value)` is > 0. `false` if it is 0.
##### .emptySet(value)
Returns `true` if the value is an empty Set (`size` is 0). `false` if it is not zero.
##### .nonEmptySet(Value)
Returns `true` of the value is a Set and it's `size` is > 0. `false` if it is `size` is 0.
##### .emptyMap(value)
Returns `true` if the value is an empty Map (`size` is 0). `false` if it is not zero.
##### .nonEmptyMap(value)
Returns `true` if the value is a Map and its `size` is > 0. `false` if is 0.
#### Miscellaneous
##### .directInstanceOf(value, class)
@ -295,14 +356,6 @@ Returns `true` if `value` is an even integer.
Returns `true` if `value` is an odd integer.
##### .empty(value)
Returns `true` if `value` is falsy or an empty string, array, object, map, or set.
##### .emptyOrWhitespace(value)
Returns `true` if `is.empty(value)` or a string that is all whitespace.
##### .any(predicate, ...values)
Returns `true` if **any** of the input `values` returns true in the `predicate`: