Features
The string-utils
library offers a set of functions to handle common string operations.
toCapitalizedWords
Converts a string to capitalized words. Ideal for formatting headers or titles.
export function toCapitalizedWords(name?: string): string {
if (name === undefined) {
return '';
}
const words = name.toLowerCase().match(/[A-Za-z][a-z]*/g) || [];
return words.map(capitalize).join(' ');
}
// Usage example
const title = toCapitalizedWords('hello world'); // 'Hello World'