method makes it a breeze, given its 'NFD'
option. This option allows you to convert the string to a normalized Unicode format, which separates the base characters from the diacritical marks.
But that's not all. Having separated the base characters from the diacritical marks, you can then use String.prototype.replace()
to remove diacritical marks from the string. This can be done by using a regular expression to match the diacritical marks in the given Unicode range (u0300
) and replacing them with empty strings.
const removeAccents = str => str.normalize('NFD').replace(/[\u0300-\u036f]/g, ''); removeAccents('Antoine de Saint-Exupéry'); // 'Antoine de Saint-Exupery'