NPM Smell 🍑💨

trivial and outdated NPM packages

is-whitespace outdated npm logo

Checks if a string only contains whitespace characters.

Weekly Downloads
1,102,827
Dependencies
0
Latest Release
9 years ago
This dependency re-creates a native JavaScript API. It is recommended to use the native API instead
Outdated
natively supported
since 11 years (chrome, firefox, safari, nodejs)

About

This dependency checks if a given string only contains whitespace characters. This can be done natively with the String.prototype.trim method.

Usage

"  ".trim().length === 0; // true
"\n\t".trim().length === 0; // true
"\r\n".trim().length === 0; // true
"\t".trim().length === 0; // true
"foo".trim().length === 0; // false

or in a function:

function isWhitespace(str) {
    return str.trim().length === 0;
}

isWhitespace("  "); // true
isWhitespace("\n\t"); // true
isWhitespace("\r\n"); // true
isWhitespace("\t"); // true
isWhitespace("foo"); // false