From 6495d1c4a3989db04a9a03d1bd364a08baa38e6b Mon Sep 17 00:00:00 2001 From: Karli Date: Mon, 8 Sep 2025 00:58:02 +0300 Subject: [PATCH] fix toTitleCase --- lib/utils.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/utils.ts b/lib/utils.ts index 3448c2b..392a129 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -15,11 +15,12 @@ export function toArray(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()), + ) ?? "" ); }