forked from UKSOURCE/hailearning.edu.vn
21 lines
507 B
TypeScript
21 lines
507 B
TypeScript
/**
|
|
* Simple slugify helper (Vietnamese-friendly) to match CMS behavior:
|
|
* - lowercased
|
|
* - diacritics removed (NFD)
|
|
* - "đ" -> "d"
|
|
* - strict: keep [a-z0-9 -] only, then collapse spaces/hyphens
|
|
*/
|
|
export function toSlug(input: string): string {
|
|
return (input || "")
|
|
.trim()
|
|
.toLowerCase()
|
|
.normalize("NFD")
|
|
.replace(/[\u0300-\u036f]/g, "")
|
|
.replace(/đ/g, "d")
|
|
.replace(/[^a-z0-9\s-]/g, "")
|
|
.replace(/\s+/g, "-")
|
|
.replace(/-+/g, "-")
|
|
.replace(/^-|-$/g, "");
|
|
}
|
|
|