Checks if the given string is present and is not empty or all whitespace.

Type signature

(x?: string) => boolean

Examples

nonEmpty("test with spaces");
// ⇒ true
Try in REPL
nonEmpty("   ");
// ⇒ false
Try in REPL
nonEmpty(null);
// ⇒ false
Try in REPL

Questions

  • How to check if a string is non-empty?
  • How to check if a string is not all whitespace?
  • How to check if a string is not null or undefined?

TypeScript sourceJavaScript source