@zerodep/is-empty
v2.0.7
Published
A utility to check if a value is empty
Downloads
18
Readme
@zerodep/is-empty
A simple, performant utility to determine if a value is null
, undefined
or an empty array, string, object, Map, Set, WeakMap or WeakSet.
Full documentation is available at the zerodep.app page.
Examples
All @zerodep packages support both ESM and CJS.
import { isEmpty } from '@zerodep/is-empty';
// or
const { isEmpty } = require('@zerodep/is-empty');
Positive Response
isEmpty([]); // true
isEmpty(''); // true
isEmpty(null); // true
isEmpty({}); // true
isEmpty(new Map()); // true
isEmpty(new Set()); // true
isEmpty(new WeakMap()); // true
isEmpty(new WeakSet()); // true
isEmpty(undefined); // true
Negative Response
isEmpty(['a', 'b', 'c']); // false
isEmpty(1000n); // false
isEmpty(true); // false
isEmpty(new Date()); // false
isEmpty(new Error('message')); // false
isEmpty(3.14); // false
isEmpty(() => 'function'); // false
isEmpty(42); // false
isEmpty(
new Map([
['a', 1],
['b', 2],
])
); // false
isEmpty({ an: 'object' }); // false
isEmpty(new Promise(() => {})); // false
isEmpty(/[regex]+/gi); // false
isEmpty(new Set([1, 2, 3])); // false
isEmpty('a string'); // false
isEmpty(Symbol()); // false
isEmpty(new Int32Array(2)); // false