Files
portabase/src/utils/slugify.ts
T

14 lines
648 B
TypeScript
Raw Normal View History

2025-07-26 14:43:59 +02:00
export const slugify = (text: string) => {
return text
.toString()
.normalize('NFKD') // Normalize accents
.replace(/[\u0300-\u036f]/g, '') // Remove diacritics
.toLowerCase()
.trim()
.replace(/\_/g, '-') // _ → dash
.replace(/\s+/g, '-') // spaces → dash
.replace(/[^\w\-]+/g, '') // Remove non-word chars
.replace(/\-\-+/g, '-') // multiple dashes → one
.replace(/^-+/, '') // Remove leading dash
.replace(/-+$/, ''); // Remove trailing dash
};