isBinaryString

Test if a value is a binary string.

Usage

var isBinaryString = require( '@stdlib/assert/is-binary-string' );

isBinaryString( value )

Tests if a value is a binary string; i.e., a character sequence of 1's and 0's.

var bool = isBinaryString( '1000101' );
// returns true

bool = isBinaryString( 'beep' );
// returns false

bool = isBinaryString( '' );
// returns false

Examples

var isBinaryString = require( '@stdlib/assert/is-binary-string' );

var bool = isBinaryString( '1' );
// returns true

bool = isBinaryString( '0' );
// returns true

bool = isBinaryString( '101010101001' );
// returns true

bool = isBinaryString( '' );
// returns false

bool = isBinaryString( 'beep' );
// returns false

bool = isBinaryString( null );
// returns false

CLI

Usage

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

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.

Examples

$ is-binary-string 01234
false

To use as a standard stream,

$ echo -n '0110' | is-binary-string
true
Did you find this page helpful?