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.
--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 $'beEp booP\n100001110' | is-binary-string --split /\r?\n/ # Escaped... $ echo -n $'beEp booP\n100001110' | is-binary-string --split /\\r?\\n/
The implementation ignores trailing delimiters.
Examples
$ is-binary-string 01234
false
To use as a standard stream,
$ echo -n '0110' | is-binary-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 '0110\t1234' | is-binary-string --split '\t'
true
false