tailwind-ui-library/components/utils/slug-to-normal-text.ts
2026-03-04 17:35:14 +01:00

16 lines
400 B
TypeScript

export default function twuiSlugToNormalText(str?: string) {
if (!str) return "";
return str
.toLowerCase()
.replace(/ /g, "-")
.replace(/[^a-z0-9\-]/g, "-")
.replace(/-{2,}/g, "-")
.replace(/[-]/g, " ")
.split(" ")
.map(
(word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
)
.join(" ");
}