Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
String prototype function to remove accents
String.prototype.removeAccents = function(){
var t = this,
a = {
'œ' : 'oe',
'Œ' : 'Oe',
'æ' : 'ae',
'Æ' : 'Ae',
'[ÀÁÂÃÄÅĀĂǍẠẢẤẦẨẪẬẮẰẲẴẶǺĄ]' : 'A',
'[àáâãäåāăǎạảấầẩẫậắằẳẵặǻą]' : 'a',
'[ÇĆĈĊČ]' : 'C',
'[çćĉċč]' : 'c',
'[ÐĎĐ]' : 'D',
'[ďđ]' : 'd',
'[ÈÉÊËĒĔĖĘĚẸẺẼẾỀỂỄỆ]' : 'E',
'[èéêëēĕėęěẹẻẽếềểễệ]' : 'e',
'[ĜĞĠĢ]' : 'G',
'[ĝğġģ]' : 'g',
'[ĤĦ]' : 'H',
'[ĥħ]' : 'h',
'[ÌÍÎÏĨĪĬĮİǏỈỊ]' : 'I',
'[ìíîïĩīĭįıǐỉị]' : 'i',
'Ĵ' : 'J',
'ĵ' : 'j',
'Ķ' : 'K',
'ķ' : 'k',
'[ĹĻĽĿŁ]' : 'L',
'[ĺļľŀł]' : 'l',
'[ÑŃŅŇ]' : 'N',
'[ñńņňʼn]' : 'n',
'[ÒÓÔÕÖØŌŎŐƠǑǾỌỎỐỒỔỖỘỚỜỞỠỢ]' : 'O',
'[òóôõöøōŏőơǒǿọỏốồổỗộớờởỡợð]' : 'o',
'[ŔŖŘ]' : 'R',
'[ŕŗř]' : 'r',
'[ŚŜŞŠ]' : 'S',
'[śŝşš]' : 's',
'[ŢŤŦ]' : 'T',
'[ţťŧ]' : 't',
'[ÙÚÛÜŨŪŬŮŰŲƯǓǕǗǙǛỤỦỨỪỬỮỰ]' : 'U',
'[ùúûüũūŭůűųưǔǖǘǚǜụủứừửữự]' : 'u',
'[ŴẀẂẄ]' : 'W',
'[ŵẁẃẅ]' : 'w',
'[ÝŶŸỲỸỶỴ]' : 'Y',
'[ýÿŷỹỵỷỳ]' : 'y',
'[ŹŻŽ]' : 'Z',
'[źżž]' : 'z'
};
for(var i in a){
t = t.replace(new RegExp(i, "g"), a[i]);
}
return t;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment