vanilla-type-check
Version:
30 lines (29 loc) • 866 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var isArray_1 = require("./isArray");
var isDom_1 = require("./isDom");
var isPlainObject_1 = require("./isPlainObject");
/**
* Check if an object or an array is empty.
*
* @param value value to check
* @returns `true` if `obj` is an object with no enumerable keys or an empty array. `false` otherwise.
*/
function isEmpty(value) {
if (isArray_1.isArray(value)) {
return value.length === 0;
}
else if (isDom_1.isDom(value)) {
return value.children.length === 0;
}
else if (isPlainObject_1.isPlainObject(value)) {
for (var key in value) {
if (value.hasOwnProperty(key)) {
return false;
}
}
return true;
}
return false;
}
exports.isEmpty = isEmpty;