Convert a string to constant case.
npm install @stdlib/string-constantcaseAlternatively,
- To load the package in a website via a
scripttag without installation and bundlers, use the ES Module available on theesmbranch. - If you are using Deno, visit the
denobranch. - For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the
umdbranch. - To use as a general utility for the command line, install the corresponding CLI package globally.
The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
var constantcase = require( '@stdlib/string-constantcase' );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'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'To use as a general utility, install the CLI package globally
npm install -g @stdlib/string-constantcase-cliUsage: constantcase [options] [<string>]
Options:
-h, --help Print this message.
-V, --version Print the package version.
--split sep Delimiter for stdin data. Default: '/\\r?\\n/'.
-
If the split separator is a regular expression, ensure that the
splitoption 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.
$ constantcase 'hello world'
HELLO_WORLDTo use as a standard stream,
$ echo -n 'beEp booP' | constantcase
BEEP_BOOPTo use as a standard stream,
$ echo -n 'isMobile' | constantcase
IS_MOBILEBy 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@stdlib/string-camelcase: convert a string to camel case.@stdlib/string-kebabcase: convert a string to kebab case.@stdlib/string-pascalcase: convert a string to Pascal case.@stdlib/string-snakecase: convert a string to snake case.
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2023. The Stdlib Authors.