All files / Shared/Utils isEmpty.js

100% Statements 12/12
100% Branches 12/12
100% Functions 1/1
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                  1x 53x 44x 31x   17x 17x 43x     17x        
/**
 * - Checks for undefined or null
 * - Checks for string's lentgth
 * - Checks for array with no members
 * - Checks for object with no enumerable properties
 * @param  {any} value
 * @return {Boolean}
**/
 
const isEmpty = value => {
    if (typeof value === 'number' || typeof value === 'boolean') return false;
    if (typeof value === 'undefined' || value === null) return true;
    if (typeof value.length !== 'undefined') return value.length === 0;
 
    let objectProperties = 0;
    for (const property in value) {
        if (value.hasOwnProperty(property)) objectProperties ++;
    }
 
    return objectProperties === 0;
};
 
export default isEmpty;