Capitalize first letter or each word. Simple string helpers.
export function capitalize(str: string): string {
return str ? str.charAt(0).toUpperCase() + str.slice(1).toLowerCase() : '';
}
export function titleCase(str: string): string {
return str
.replace(/_|\s+/g, ' ')
.split(' ')
.map((w) => capitalize(w))
.join(' ');
}
First letter uppercase, rest lowercase. Handles empty string.
Each word capitalized. Replaces underscores and multiple spaces with single space.
titleCase('hello_world'); // 'Hello World'