fix toTitleCase

This commit is contained in:
2025-09-08 00:58:02 +03:00
parent a9612ad992
commit 6495d1c4a3

View File

@@ -15,11 +15,12 @@ export function toArray<T>(input?: T | T[] | null): T[] {
}
export function toTitleCase(str?: string) {
if (!str) return '';
return str.replace(
/\w\S*/g,
(text: string) =>
text.charAt(0).toUpperCase() + text.substring(1).toLowerCase(),
return (
str
?.toLowerCase()
.replace(/[^-'\s]+/g, (match) =>
match.replace(/^./, (first) => first.toUpperCase()),
) ?? ""
);
}