@qntm-code/utils
Version:
A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.
29 lines (28 loc) • 627 B
JavaScript
import { isNullOrUndefined } from './isNullOrUndefined.js';
import { typeOf } from './typeOf.js';
/**
* Checks if a given value is empty
*/
export function isEmpty(value) {
if (isNullOrUndefined(value)) {
return true;
}
const type = 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;
}
}
}