isEmpty
Checks whether a given value is considered empty. Supports strings, arrays, plain objects, Maps, and Sets.
Import
Section titled “Import”import { isEmpty } from "1o1-utils";import { isEmpty } from "1o1-utils/is-empty";Signature
Section titled “Signature”function isEmpty({ value }: IsEmptyParams): booleanParameters
Section titled “Parameters”| Name | Type | Required | Description |
|---|---|---|---|
value | unknown | Yes | The value to check |
Returns
Section titled “Returns”boolean — true if the value is considered empty.
What counts as empty:
nullandundefined- Empty string (
"") - Empty array (
[]) - Empty
MapandSet - Plain object with no own enumerable properties (
{})
Examples
Section titled “Examples”isEmpty({ value: "" }); // => trueisEmpty({ value: [] }); // => trueisEmpty({ value: {} }); // => trueisEmpty({ value: null }); // => trueisEmpty({ value: new Map() }); // => true
isEmpty({ value: "hello" }); // => falseisEmpty({ value: [1, 2] }); // => falseisEmpty({ value: 0 }); // => falseisEmpty({ value: false }); // => falseEdge Cases
Section titled “Edge Cases”- Numbers (including
0) and booleans are never empty. - Only plain objects (prototype is
Object.prototypeornull) are checked for emptiness. - Class instances and other non-plain objects return
false.
Also known as
Section titled “Also known as”is empty, is blank, has value, null check, empty check
Prompt suggestion
Section titled “Prompt suggestion”I'm using 1o1-utils (npm: https://www.npmjs.com/package/1o1-utils, GitHub: https://github.com/pedrotroccoli/1o1-utils, LLM context: https://pedrotroccoli.github.io/1o1-utils/llms.txt). Show me how to use isEmpty to validate form fields before submission