Skip to main content

isEmpty

Checks whether the given value is empty.

The following are considered empty:

  • null, undefined
  • An empty string ''
  • An array with a length of 0
  • A Map or Set with a size of 0
  • A plain object with no own enumerable string keys (an object whose prototype is Object.prototype or null)

All other values (numbers, booleans, functions, Date, class instances, etc.) are considered non-empty and return false.

info

Unlike lodash, 0, false, etc. are not treated as empty values.


Code​

🔗 View source code


Interface​

typescript
function isEmpty(value: unknown): boolean;

Usage​

typescript
import { isEmpty } from '@modern-kit/utils';

isEmpty(null); // true
isEmpty(''); // true
isEmpty([]); // true
isEmpty({}); // true
isEmpty(new Map()); // true

isEmpty(' '); // false
isEmpty([0]); // false
isEmpty({ a: undefined }); // false
isEmpty(0); // false
isEmpty(false); // false