isBlankString

Test if a value is a blank string.

Usage

var isBlankString = require( '@stdlib/assert/is-blank-string' );

isBlankString( value )

Tests if a value is a blank string (i.e., an empty string or a string consisting only of whitespace characters).

var bool = isBlankString( '   ' );
// returns true

bool = isBlankString( '' );
// returns true

bool = isBlankString( 0 );
// returns false

Examples

var isBlankString = require( '@stdlib/assert/is-blank-string' );

var out = isBlankString( '   ' );
// returns true

out = isBlankString( '\t\t\t' );
// returns true

out = isBlankString( '\r\n' );
// returns true

out = isBlankString( '' );
// returns true

out = isBlankString( 'beep boop' );
// returns false

out = isBlankString( null );
// returns false

CLI

Usage

Usage: is-blank-string [options] [<string>]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.
         --split sep           Delimiter for stdin data. Default: '/\\r?\\n/'.

Notes

  • If the split separator is a regular expression, ensure that the split option is either properly escaped or enclosed in quotes.

    # Not escaped...
    $ echo -n $'\nisMobile' | is-blank-string --split /\r?\n/
    # Escaped...
    $ echo -n $'\nisMobile' | is-blank-string --split /\\r?\\n/
    
  • The implementation ignores trailing delimiters.

Examples

$ is-blank-string baz
false

To use as a standard stream,

$ echo -n ' \t ' | is-blank-string
true

By default, when used as a standard stream, the implementation assumes newline-delimited data. To specify an alternative delimiter, set the split option.

$ echo -n '\t123' | is-blank-string --split '\t'
true
false
Did you find this page helpful?