Javascript - Efficiently replace all accented characters in a string

const strip_accents = (str) => str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');

Two things are happening here:

  1. normalize()ing to NFD Unicode normal form decomposes combined graphemes into the combination of simple ones. The è of Crème ends up expressed as e + ̀.
  2. Using a regex character class to match the U+0300 → U+036F range, it is now trivial to globally get rid of the diacritics, which the Unicode standard conveniently groups as the Combining Diacritical Marks Unicode block.

Same with another syntax:

str.normalize('NFKD').replace(/\p{Diacritic}/gu, '');