Add is.emptyOrWhitespace() (#21)

This commit is contained in:
Brandon Smith 2017-10-17 16:46:58 -04:00 committed by Giora Guttsait
parent 615932d6c2
commit cdd4829edf
3 changed files with 13 additions and 0 deletions

View file

@ -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".