| 12345678910111213141516171819202122232425 |
- /**
- * String utility functions
- */
- /**
- * Convert a string to a slug format
- * Removes special characters, replaces spaces with hyphens, and converts to lowercase
- *
- * @param text The text to convert to slug format
- * @returns The slugified text
- */
- export function slugify(text: string): string {
- return text
- .toString()
- .normalize('NFD') // Split accented characters
- .replace(/[\u0300-\u036F]/g, '') // Remove diacritics
- .toLowerCase()
- .trim()
- .replace(/\s+/g, '-') // Replace spaces with -
- .replace(/[^\w-]+/g, '') // Remove all non-word chars
- .replace(/--+/g, '-') // Replace multiple - with single -
- .replace(/^-+/, '') // Trim - from start of text
- .replace(/-+$/, '') // Trim - from end of text
- .substring(0, 30) // Limit to 30 characters
- }
|