JavaScript tips

Posted on 2018-03-07 in Trucs et astuces

Normalize an UTF-8 string

Rely on String.prototype.normalize().

const str = "Crème Brulée"
str.normalize('NFD').replace(/[\u0300-\u036f]/g, "")
> 'Creme Brulee'

Source: https://stackoverflow.com/questions/990904/remove-accents-diacritics-in-a-string-in-javascript/37511463#37511463