export function slugify(text: string, sep = '-'): string {
return text
.normalize('NFKD') // separate base chars + accents
.replace(/[̀-ͯ]/g, '') // strip combining marks
.toLowerCase()
.replace(/[^a-z0-9]+/g, sep) // non-alnum → sep
.replace(new RegExp(`^${sep}+|${sep}+$`, 'g'), '') // trim
.replace(new RegExp(`${sep}{2,}`, 'g'), sep); // collapse runs
}
slugify('Hello, World!'); // 'hello-world'
slugify('Café au lait — délicieux'); // 'cafe-au-lait-delicieux'
slugify('TypeScript 5.3 & Beyond'); // 'typescript-5-3-beyond'
Create a free account and build your private vault. Share publicly whenever you want.