Slug generation

Hello,

I was wondering if there is a built-in slugify function, but it doesn’t seem so.

This is what I use to generate a slug

{{String($json.nom)
.replace(/[øØ]/g, 'o')
.replace(/[æÆ]/g, 'ae')
.replace(/[ßẞ]/g, 'ss')
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
.replace(/\b\w'/g, "")
.replace(/ẞ/g, 'ß')
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/-+/g, '-')
.replace(/^-|-$/g, '')}}

It allows to turn something like L'été, les événements débordent d'énergie créative!
into ete-les-evenements-debordent-energie-creative to create a slug.

Hope that helps,

Cheers,
Joachim

3 Likes

This may be slightly simplified now using the expression transformation function replaceSpecialChars() - Data transformation functions for strings - n8n Documentation

A slugify function would be a good feature request though

2 Likes

Thank you for the tip !