Slugify a String with Multi-lingual Support
(Last modified: )
Read more at: How to generate an ID from element text
Other methods:
- Don’t maintain the same slug (crypto)
- Don’t properly slug any non English characters
- Don’t take into account other characters (like emojis)
const string = '123 #^&%@<code>.text-small</code> 是不 Sábado 😀🎉';
const slugify = string.replace(/[^a-zA-Z0-9-_\u00A0-\uFFEF\s-]/g, '-').replace(/[\s-]+/g, '-');
// slugify = '123-text-small-是不-Sábado-😀🎉'