blog.hangerthem.com/utils/slug.ts

12 lines
No EOL
297 B
TypeScript

/**
* Converts a string into a URL-friendly slug.
* @param text - The input string to be converted into a slug.
* @returns A URL-friendly slug string.
*/
export function slugify(text: string): string {
return text
.toLowerCase()
.trim()
.replace(/\s+/g, '-')
.replace(/[^\w-]/g, '')
}