16 lines
396 B
TypeScript
16 lines
396 B
TypeScript
export default function slugToNormalText(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(" ");
|
|
}
|