Add is.emptyOrWhitespace() (#21)
This commit is contained in:
parent
615932d6c2
commit
cdd4829edf
3 changed files with 13 additions and 0 deletions
2
index.js
2
index.js
|
|
@ -183,11 +183,13 @@ const isAbsoluteMod2 = value => x => is.integer(x) && Math.abs(x % 2) === value;
|
|||
is.even = isAbsoluteMod2(0);
|
||||
is.odd = isAbsoluteMod2(1);
|
||||
|
||||
const isWhiteSpaceString = x => is.string(x) && /\S/.test(x) === false;
|
||||
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);
|
||||
is.emptyOrWhitespace = x => is.empty(x) || isWhiteSpaceString(x);
|
||||
|
||||
const predicateOnArray = (method, predicate, values) => {
|
||||
// `values` is the calling function's "arguments object".
|
||||
|
|
|
|||
|
|
@ -182,6 +182,10 @@ Returns `true` if `value` is an odd integer.
|
|||
|
||||
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)
|
||||
|
||||
|
|
|
|||
7
test.js
7
test.js
|
|
@ -468,6 +468,13 @@ test('is.empty', t => {
|
|||
t.false(m.empty(tempSet));
|
||||
});
|
||||
|
||||
test('is.emptyOrWhitespace', t => {
|
||||
t.true(m.emptyOrWhitespace(''));
|
||||
t.true(m.emptyOrWhitespace(' '));
|
||||
t.false(m.emptyOrWhitespace('🦄'));
|
||||
t.false(m.emptyOrWhitespace('unicorn'));
|
||||
});
|
||||
|
||||
test('is.any', t => {
|
||||
t.true(m.any(m.string, {}, true, '🦄'));
|
||||
t.true(m.any(m.object, false, {}, 'unicorns'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue