time-to-botec/js/node_modules/@stdlib/string/constantcase/README.md
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00

5.0 KiB

constantcase

Returns a string converted to a constant case.

Usage

var constantcase = require( '@stdlib/string/constantcase' );

constantcase( str )

Converts a string to constant case.

var str = constantcase( 'foo bar' );
// returns 'FOO_BAR'

str = constantcase( 'foo bar baz' );
// returns 'FOO_BAR_BAZ'

str = constantcase( 'foo_bar' );
// returns 'FOO_BAR'

Examples

var constantcase = require( '@stdlib/string/constantcase' );

var str = 'Hello World!';
var out = constantcase( str );
// returns 'HELLO_WORLD'

str = 'I am a tiny little teapot';
out = constantcase( str );
// returns 'I_AM_A_TINY_LITTLE_TEAPOT'

str = 'with big problems';
out = constantcase( str );
// returns 'WITH_BIG_PROBLEMS'

str = 'To be, or not to be: that is the question.';
out = constantcase( str );
// returns 'TO_BE_OR_NOT_TO_BE_THAT_IS_THE_QUESTION'

str = 'isMobile';
out = constantcase( str );
// returns 'IS_MOBILE'

CLI

Usage

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

Examples

$ constantcase 'hello world'
HELLO_WORLD

To use as a standard stream,

$ echo -n 'beEp booP' | constantcase
BEEP_BOOP

To use as a standard stream,

$ echo -n 'isMobile' | constantcase
IS_MOBILE

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_boop\tisMobile' | constantcase --split '\t'
BEEP_BOOP
IS_MOBILE

See Also