Skip to main content

capitalize()

capitalize(str): string

Converts the first character to uppercase and the rest to lowercase.

note

Supports Unicode characters (accents, Cyrillic, etc.).


Parameters

str: string

The string to capitalize.


Returns: string

The capitalized string.


Since

2.0.0


Also known as

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


Example

capitalize('hello');  // => 'Hello'
capitalize('HELLO'); // => 'Hello'
capitalize('été'); // => 'Été'
capitalize('москва'); // => 'Москва'

How it works?

Converts the first character to uppercase and the rest to lowercase.

Examples

InputOutput
helloHello
HELLOHello
étéÉté
москваМосква

Unicode Support

Supports Unicode characters (accents, Cyrillic, etc.).


Use Cases

Format user names 📌

Ensure proper capitalization of names. Useful for display logic on profile pages.

const name = capitalize('john'); // 'John'

Normalize input labels

Standardize form field labels or button text.

const label = capitalize('submit'); // 'Submit'
const button = capitalize('CANCEL'); // 'Cancel' (if it lowercases first)

Display enum values as readable text

Convert constant-style enum values into human-readable labels for UI display.

const statuses = ['PENDING_REVIEW', 'IN_PROGRESS', 'COMPLETED'];
const labels = statuses.map((s) =>
capitalize(s.toLowerCase().replace(/_/g, ' '))
);
// ['Pending review', 'In progress', 'Completed']