Convert a string to a URL-safe slug. Handles accents, spaces, and special characters.
export function slugify(str: string): string {
return str
.trim()
.toLowerCase()
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-|-$/g, '');
}Takes a string and returns a URL-safe slug. Strips accents (é → e), replaces spaces and punctuation with hyphens, trims leading/trailing hyphens.
slugify('Hello World!') returns 'hello-world'. Use for URLs, file names, or IDs.
slugify('My Blog Post'); // 'my-blog-post'