@qntm-code/utils
Version:
A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.
33 lines (32 loc) • 807 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isEmpty = void 0;
const isNullOrUndefined_js_1 = require("./isNullOrUndefined.js");
const typeOf_js_1 = require("./typeOf.js");
/**
* Checks if a given value is empty
*/
function isEmpty(value) {
if ((0, isNullOrUndefined_js_1.isNullOrUndefined)(value)) {
return true;
}
const type = (0, typeOf_js_1.typeOf)(value);
switch (type) {
case 'set':
case 'map': {
return value.size === 0;
}
}
switch (typeof value) {
case 'object': {
return !Object.keys(value).length;
}
case 'string': {
return !value.trim();
}
default: {
return false;
}
}
}
exports.isEmpty = isEmpty;