I needed to convert a text for this project that I'm working on. I have used several functions to do this using Javascript. But today I decided to take another look and this is the best solution for this task that I found on Github Create slug from string in Javascript
And here is the code if you want to implement it.
const slugify = text =>
text
.toString()
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase()
.trim()
.replace(/\s+/g, '-')
.replace(/[^\w-]+/g, '')
.replace(/--+/g, '-')