Lowercases then capitalizes the first letter of every word

export const capitalize = (str: string): string => {
return str.toLowerCase().replace(/(?:^|\s|-)\S/g, (match) => match.toUpperCase());
};
  • Parameters

    • str: string

    Returns string

    A new string with every word capitalized