isSnakecase

Test if a value is a string in snake case.

Usage

var isSnakecase = require( '@stdlib/assert/is-snakecase' ); 

isSnakecase( value )

Tests if a value is a string in snake case.

var bool = isSnakecase( 'hello_world' ); // returns true bool = isSnakecase( 'Hello World' ); // returns false 

Notes

  • The function validates that a value is a string. For all other types, the function returns false.

Examples

var isSnakecase = require( '@stdlib/assert/is-snakecase' ); var bool = isSnakecase( 'foo_bar_baz' ); // returns true bool = isSnakecase( 'FOO_BAR' ); // returns false bool = isSnakecase( 'fooBar' ); // returns false bool = isSnakecase( 'beep-boop' ); // returns false bool = isSnakecase( null ); // returns false 

CLI

Usage

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

Examples

$ is-snakecase foo_bar true 

To use as a standard stream,

$ echo -n 'fooBar' | is-snakecase false 

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 'fooBar\tbeep_boop' | is-snakecase --split '\t' false true