Accent Removal
Hello toddle community . I would like to design a function that does the following : removeAccents = (str ) = > { return str .replace ( / [ à á â ã ä å ] /g , 'a ' ) .replace ( / [ è é ê ë ] /g , 'e ' ) .replace ( / [ ì í î ï ] /g , 'i ' ) .replace ( / [ ò ó ô õ ö ] /g , 'o ' ) .replace ( / [ ù ú û ü ] /g , 'u ' ) .replace ( / [ ý ÿ ] /g , 'y ' ) .replace ( / [ ñ ] /g , 'n ' ) .replace ( / [ ç ] /g , 'c ' ) ; } ; But this is impossible without the use of several nested “ReplaceAll ” . Do you have any suggestions ? Thank you ! ✅1✅1@Erik Beuschau helped me out when this happened to me I wasn ’t able to reproduce it when it happened to me so trying to see if you remember how it happened Yes , i replaced the content of my custom function from this : function removeAccents(args, ctx) {
const accents = [
{ from: /[äâà]/g, to: 'a' },
{ from: /[éèê]/g, to: 'e' },
{ from: /[ïî]/g, to: 'i' },
{ from: /[ôö]/g, to: 'o' },
{ from: /[ûü]/g, to: 'u' }
];
// Vérifie si la chaîne existe dans args
if (!args.text || typeof args.text !== "string") {
return "";
}
return accents.reduce((acc, rule) => acc.replace(rule.from, rule.to), args.text);
}to this : function removeAccents(args, ctx) {
if (!args.text || typeof args.text !== "string") {
return "";
}
return args.text.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
}