Skip to main content

upperCase()

upperCase(str): string

Converts string to upper case with space-separated words.


Parameters​

str: string | null | undefined​

The string to convert.


Returns: string​

The upper cased string with words separated by spaces.


See Also​

String.toUpperCase() - MDN


Since​

2.0.0


Performance​

O(n) β€” charCode word splitting for short ASCII, regex for long/Unicode/emoji.


Also known as​

upperCase (Lodash, es-toolkit) · ❌ (Remeda, Radashi, Ramda, Effect, Modern Dash, Antfu)


Example​

upperCase('--Foo-Bar--');  // => 'FOO BAR'
upperCase('fooBar'); // => 'FOO BAR'
upperCase('__foo_bar__'); // => 'FOO BAR'

How it works?​

Converts string to space-separated uppercase words. Splits on case boundaries, underscores, hyphens, and emojis. Supports Unicode.

Conversion Examples​

InputOutput
'--Foo-Bar--''FOO BAR'
'fooBar''FOO BAR'
'__foo_bar__''FOO BAR'

Process​


Use Cases​

Convert to upper case words πŸ“Œβ€‹

Convert string to space-separated uppercase words. Useful for headers, labels, or constants display.

upperCase('fooBar');       // => 'FOO BAR'
upperCase('__foo_bar__'); // => 'FOO BAR'
upperCase('--Foo-Bar--'); // => 'FOO BAR'

Format header text​

Format identifiers as uppercase display text.

const header = upperCase('contentType');
// => 'CONTENT TYPE'