14 lines
470 B
TypeScript
14 lines
470 B
TypeScript
export function slugify(text: string) {
|
||
if (!text) return "";
|
||
const trMap: { [key: string]: string } = {
|
||
'ç': 'c', 'ğ': 'g', 'ı': 'i', 'ö': 'o', 'ş': 's', 'ü': 'u',
|
||
'Ç': 'C', 'Ğ': 'G', 'İ': 'I', 'Ö': 'O', 'Ş': 'S', 'Ü': 'U'
|
||
};
|
||
const normalized = text.replace(/[çğıöşüÇĞİÖŞÜ]/g, (match) => trMap[match]);
|
||
return normalized
|
||
.toLowerCase()
|
||
.replace(/[^a-z0-9 -]/g, '')
|
||
.replace(/\s+/g, '-')
|
||
.replace(/-+/g, '-');
|
||
}
|