import TextUtil from "./TextUtil";

export default class TextFormat {
  public static toFullName({
    firstName,
    lastName,
  }: {
    firstName?: string | null;
    lastName?: string | null;
  }): string {
    return [
      TextUtil.isEmpty(firstName) ? null : firstName,
      TextUtil.isEmpty(lastName) ? null : lastName,
    ]
      .filter(Boolean)
      .join(" ");
  }

  public static toTitleCase(value?: string) {
    return (
      value
        ?.toLowerCase()
        .replace(/[^-'’\s]+/g, (match) =>
          match.replace(/^./, (first) => first.toUpperCase()),
        ) ?? ""
    );
  }
}
