fix toTitleCase
This commit is contained in:
11
lib/utils.ts
11
lib/utils.ts
@@ -15,11 +15,12 @@ export function toArray<T>(input?: T | T[] | null): T[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function toTitleCase(str?: string) {
|
export function toTitleCase(str?: string) {
|
||||||
if (!str) return '';
|
return (
|
||||||
return str.replace(
|
str
|
||||||
/\w\S*/g,
|
?.toLowerCase()
|
||||||
(text: string) =>
|
.replace(/[^-'’\s]+/g, (match) =>
|
||||||
text.charAt(0).toUpperCase() + text.substring(1).toLowerCase(),
|
match.replace(/^./, (first) => first.toUpperCase()),
|
||||||
|
) ?? ""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user