Skip to content

isEmpty

Checks if a string is empty (""), null, or undefined.

This is a strict emptiness check — whitespace-only strings are not considered empty. Use isEmpty(value?.trim()) if you need to treat blank strings as empty.

Available since v2.0.3

import { isEmpty } from '@helpers4/string';
isEmpty(value: string | null | undefined): value is "" | null | undefined
ParameterTypeDescription
valuestring | null | undefinedThe string to check

value is "" | null | undefined — true if the string is "", null, or undefined

Returns true only for "". Whitespace-only strings are not considered empty.

isEmpty('')    // => true
isEmpty(' ')   // => false  (whitespace is content)
isEmpty('foo') // => false

Treat blank strings as empty by trimming first

Section titled “Treat blank strings as empty by trimming first”

Compose with .trim() when whitespace-only should also be considered empty.

isEmpty(''.trim())   // => true
isEmpty('   '.trim()) // => true
isEmpty('hi'.trim())  // => false

View source on GitHub