isDigitString

Test whether a string contains only numeric digits.

Usage

var isDigitString = require( '@stdlib/assert/is-digit-string' );

isDigitString( value )

Tests whether a string contains only numeric digits.

var bool = isDigitString( '0123456789' );
// returns true

Notes

  • For non-string values, the function returns false.

Examples

var isDigitString = require( '@stdlib/assert/is-digit-string' );

var out = isDigitString( '0123456789' );
// returns true

out = isDigitString( '' );
// returns false

out = isDigitString( '0xffffff' );
// returns false

out = isDigitString( 123 );
// returns false

CLI

Usage

Usage: is-digit-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\n0123456' | is-digit-string --split /\r?\n/
    # Escaped...
    $ echo -n $'beEp booP\n0123456' | is-digit-string --split /\\r?\\n/
    
  • The implementation ignores trailing delimiters.

Examples

$ is-digit-string 0123456789
true

To use as a standard stream,

$ echo -n '0123456789' | is-digit-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 'beep\t123' | is-digit-string --split '\t'
false
true
Did you find this page helpful?