Capitalize a String
Converts the first letter of a given string to uppercase while keeping the rest lowercase (unless otherwise specified).
capitalizeString
The capitalizeString function converts the first letter of a given string to uppercase while keeping the rest lowercase. It provides options to capitalize each word's first letter, capitalize the entire string, or preserve the casing of the rest of the string.
Function Signature
function capitalizeString(string: string, options?: CapitalizeOptions): stringParameters
string(string): The string to capitalize.options(CapitalizeOptions, optional): Customization options:capitalizeEachFirst(boolean): Capitalizes the first letter of each word. Defaults tofalse.capitalizeAll(boolean): Converts the entire string to uppercase. Defaults tofalse.lowerCaseRest(boolean): Ensures all characters except the first are lowercase. Defaults totrue.
Return Value
string: The capitalized string.
Example Usage
playground.ts
Types
CapitalizeOptions
interface CapitalizeOptions {
capitalizeEachFirst?: boolean;
capitalizeAll?: boolean;
lowerCaseRest?: boolean;
}See Also
- convertStringCase - For more string case conversion options.
Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)
