/**
 * Converts the given string to title case.
 * If the given string is undefined, returns undefined.
 *
 * @param {string | undefined} str - The string to convert.
 * @return {string | undefined} The converted string, or undefined if the given string is undefined.
 */
export class StringHelper {
  static toTitleCase(str: string | undefined): string | undefined {
    if (!str) {
      return undefined;
    }

    return str.replace(/\w\S*/g, function (txt) {
      return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
    });
  }
}
