@kaloka-radia-nanda/is-empty
v0.1.1
Published
Tiny utility to check whether a JavaScript value is empty
Downloads
22
Maintainers
Readme
is-empty
Tiny utility to check whether a JavaScript value is considered empty in a consistent way.
Table of Contents
Install
npm install @kaloka-radia-nanda/is-emptyUsage
const isEmpty = require("@kaloka-radia-nanda/is-empty");
isEmpty(""); // true
isEmpty(" "); // true
isEmpty([]); // true
isEmpty({}); // true
isEmpty(null); // true
isEmpty("hello"); // false
isEmpty([1]); // false
isEmpty({ a: 1 }); // false
isEmpty(0); // false
isEmpty(false); // falseWhat does "empty" mean?
This library follows a clear and predictable definition of emptiness.
Considered empty (true)
nullundefined- Empty string (
"") - String with only whitespace (
" ") - Empty array (
[]) - Empty object (
{}) - Empty
MaporSet NaN- Invalid
Date
Not considered empty (false)
0false- Non-empty string
- Non-empty array or object
- Function
- Valid
Date
Supported Types
| Type | Behavior |
| -------- | ---------------------------- |
| string | Trimmed length === 0 |
| number | NaN is empty |
| array | length === 0 |
| object | No own enumerable properties |
| Map | size === 0 |
| Set | size === 0 |
| Date | Invalid date is empty |
API
isEmpty(value)
Checks whether a value is considered empty based on the rules above.
Returns true if empty, otherwise false.
Design Goals
- Zero dependencies
- Predictable behavior
- No magic or hidden rules
- Works in Node.js without configuration
Non-goals
This library intentionally does not:
- Guess business logic
- Treat
0orfalseas empty - Mutate input values
License
MIT LICENSE © 2026 Kaloka Radia Nanda
