1 function slugify(value) {
2 return value
3 .toString()
4 .normalize('NFD') // split an accented letter in the base letter and the accent
5 .replace(/[\u0300-\u036f]/g, '') // remove all the accents
6 .toLowerCase()
7 .replace(/[^a-z0-9 -]/g, '') // replace all chars that are not letters, numbers and spaces
8 .trim()
9 .replace(/\s+/g, '-');}
10 slugify('Hello world'); // 'hello-world'