Basically I found a slug function which looks like this:
function slug(string) => {
return string.toString().toLowerCase()
.replace(/\s+/g, '-')
.replace(/[^\w\-]+/g, '')
.replace(/\-\-+/g, '-')
.replace(/^-+/, '')
.replace(/-+$/, '');
};
However, it doesn't seem to work for Russian, Greek, ... characters. Basically they are removed at this step .replace(/[^\w\-]+/g, '')
which I don't want but I also want to remove other special characters which do not represent normal letters in some countries.
Example:
English
| Do you know it rains?
| do-you-know-it-rains
Czech
| víš, že prší?
| vis-ze-prsi
Romanian
| Ști că plouă?
| sti-ca-ploua
Russian
| ты знаешь, что идет дождь?
| ты-знаешь-что-идет-дождь
Note:
Basically for latin alphabet I will keep the letters but remove the diacritics, but for non-latin alphabet I will keep the letters as they are (I don't want to convert them into latin characters)