1

Hi in my aura component below code is used to replace all accented characters with English equivalents but I have update aura component version after which String.prototype function is no longer supported please help with its alternative how to replace all accented characters

var input = component.get('v.newSalesOrder.Invoice_Message__c');
    
  /*  var languageMap = component.get("v.languageMap");
    
    String.prototype.portuguese=function(){
        return this.replace(/[^A-Za-z0-9\[\] ]/g,
                            function(a){
                                return languageMap.portuguese_map[a]||a}
                           )
    };
    component.set('v.newSalesOrder.Invoice_Message__c', input.portugueze());  

var languageMap = component.get("v.languageMap");
    
    languageMap.portuguese_map={
        "Á":"A", "á":"a", "Â":"A", "â":"a", "À":"A", "à":"a", "Å":"A", "å":"a", "Ã":"A", "ã":"a",
        "Ä":"A", "ä":"a", "Æ":" ", "æ":" ", "É":"E", "é":"e", "Ê":"E", "ê":"e", "È":"E", "è":"e",
        "Ë":"E", "ë":"e", "Ð":" ", "ð":" ", "Í":"I", "í":"i", "Î":"I", "î":"i", "Ì":"I", "ì":"i",
        "Ï":"I", "ï":"i", "Ó":"O", "ó":"o", "Ô":"O", "ô":"o", "Ò":"O", "ò":"o", "Ø":" ", "ø":" ",
        "Õ":"O", "õ":"o", "Ö":"O", "ö":"o", "Ú":"U", "ú":"u", "Û":"U", "û":"u", "Ù":"U", "ù":"u",
        "Ü":"U", "ü":"u", "Ç":"C", "ç":"c", "Ñ":"N", "ñ":"n", "Ý":"Y", "ý":"y", "\"":" ", "<":" ",
        ">":" ", "&":" ", "®":" ", "©":" ", "Þ":" ", "þ":" ", "ß":" ", "=":" "
    };        
    component.set("v.languageMap",languageMap);
},
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
priya dhawan
  • 13
  • 1
  • 3
  • This post might help: https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript – Babis.amas Dec 09 '21 at 09:35
  • _"String.prototype function is no longer supported"_ - so just rewrite it to a normal, stand-alone function then? – CBroe Dec 09 '21 at 09:35

2 Answers2

6
function Convert(string){
  return string.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
}
console.log(Convert("Ë À Ì Â Í Ã Î Ä Ï Ç Ò È Ó É Ô Ê Õ Ö ê Ù ë Ú î Û ï Ü ô Ý õ â "))

Output:

"E A I A I A I A I C O E O E O E O O e U e U i U i U o Y o a "
picocode
  • 113
  • 2
  • 7
0

I had the same need for a project and found myself creating a package for it. https://github.com/PatricNox/SpecialToNormal

import normalizeSpecialCharacters from "specialtonormal";


var input = component.get('v.newSalesOrder.Invoice_Message__c');
component.set('v.newSalesOrder.Invoice_Message__c', normalizeSpecialCharacters(input.portugueze()));  
PatricNox
  • 3,306
  • 1
  • 17
  • 25