Add is.empty() (#16)

This commit is contained in:
Kodie Grantham 2017-10-06 02:39:36 -05:00 committed by Sindre Sorhus
parent ee8f5d16f8
commit 46e886d10b
3 changed files with 40 additions and 0 deletions

View file

@ -163,4 +163,10 @@ is.inRange = (x, range) => {
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;