Skip to content

isNotBlank

Checks if a string is not blank — non-empty and contains at least one non-whitespace character. null and undefined are considered blank and return false.

Uses String.prototype.trim() internally. See isBlank for the full list of characters considered whitespace (includes non-breaking space, en/em space, ideographic space, etc.).

Available since v2.0.3

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

boolean — true if the string has at least one non-whitespace character; false for blank, null, or undefined

Returns true only when the string contains at least one non-whitespace character.

isNotBlank('foo')  // => true
isNotBlank(' x ')  // => true
isNotBlank('')     // => false
isNotBlank('   ')  // => false
isNotBlank('\t')   // => false

Use as a predicate in .filter() to keep only strings with real content.

const tags = ['typescript', '  ', '', 'helpers'];
tags.filter(isNotBlank)
// => ['typescript', 'helpers']

View source on GitHub