Merge branch 'master' into master_add_domElement
This commit is contained in:
commit
1cce236405
3 changed files with 41 additions and 0 deletions
6
index.js
6
index.js
|
|
@ -171,4 +171,10 @@ is.domElement = x => {
|
||||||
|
|
||||||
is.infinite = x => x === Infinity || x === -Infinity;
|
is.infinite = x => x === Infinity || x === -Infinity;
|
||||||
|
|
||||||
|
const isEmptyStringOrArray = x => (is.string(x) || is.array(x)) && x.length === 0;
|
||||||
|
const isEmptyObject = x => !is.map(x) && !is.set(x) && is.object(x) && Object.keys(x).length === 0;
|
||||||
|
const isEmptyMapOrSet = x => (is.map(x) || is.set(x)) && x.size === 0;
|
||||||
|
|
||||||
|
is.empty = x => !x || isEmptyStringOrArray(x) || isEmptyObject(x) || isEmptyMapOrSet(x);
|
||||||
|
|
||||||
module.exports = is;
|
module.exports = is;
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,11 @@ Returns `true` if `value` is a DOM Element.
|
||||||
|
|
||||||
Check if `value` is `Infinity` or `-Infinity`.
|
Check if `value` is `Infinity` or `-Infinity`.
|
||||||
|
|
||||||
|
##### .empty(value)
|
||||||
|
|
||||||
|
Returns `true` if `value` is falsy or an empty string, array, object, map, or set.
|
||||||
|
|
||||||
|
|
||||||
## FAQ
|
## FAQ
|
||||||
|
|
||||||
### Why yet another type checking module?
|
### Why yet another type checking module?
|
||||||
|
|
@ -180,6 +185,7 @@ The most common mistakes I noticed in these modules was using `instanceof` for t
|
||||||
- [is-array-sorted](https://github.com/sindresorhus/is-array-sorted) - Check if an Array is sorted
|
- [is-array-sorted](https://github.com/sindresorhus/is-array-sorted) - Check if an Array is sorted
|
||||||
- [is-error-constructor](https://github.com/sindresorhus/is-error-constructor) - Check if a value is an error constructor
|
- [is-error-constructor](https://github.com/sindresorhus/is-error-constructor) - Check if a value is an error constructor
|
||||||
- [is-empty-iterable](https://github.com/sindresorhus/is-empty-iterable) - Check if an Iterable is empty
|
- [is-empty-iterable](https://github.com/sindresorhus/is-empty-iterable) - Check if an Iterable is empty
|
||||||
|
- [is-blob](https://github.com/sindresorhus/is-blob) - Check if a value is a Blob - File-like object of immutable, raw data
|
||||||
|
|
||||||
|
|
||||||
## Created by
|
## Created by
|
||||||
|
|
|
||||||
29
test.js
29
test.js
|
|
@ -398,3 +398,32 @@ test('is.domElement', t => {
|
||||||
test('is.infinite', t => {
|
test('is.infinite', t => {
|
||||||
testType(t, 'infinite', ['number']);
|
testType(t, 'infinite', ['number']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('is.empty', t => {
|
||||||
|
t.true(m.empty(null));
|
||||||
|
t.true(m.empty(undefined));
|
||||||
|
|
||||||
|
t.true(m.empty(false));
|
||||||
|
t.false(m.empty(true));
|
||||||
|
|
||||||
|
t.true(m.empty(''));
|
||||||
|
t.false(m.empty('🦄'));
|
||||||
|
|
||||||
|
t.true(m.empty([]));
|
||||||
|
t.false(m.empty(['🦄']));
|
||||||
|
|
||||||
|
t.true(m.empty({}));
|
||||||
|
t.false(m.empty({unicorn: '🦄'}));
|
||||||
|
|
||||||
|
const tempMap = new Map();
|
||||||
|
t.true(m.empty(tempMap));
|
||||||
|
|
||||||
|
tempMap.set('unicorn', '🦄');
|
||||||
|
t.false(m.empty(tempMap));
|
||||||
|
|
||||||
|
const tempSet = new Set();
|
||||||
|
t.true(m.empty(tempSet));
|
||||||
|
|
||||||
|
tempSet.add(1);
|
||||||
|
t.false(m.empty(tempSet));
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue