Skip to content

replaceAccentedCharacters

Mike Byrne edited this page Mar 14, 2023 · 1 revision

description

Introduced 3.1.0

Replace accented characters (Diacritics) with regular ASCII characters - so characters like é will be replaced by e.

A common use case is string matching searches where users may not enter accented characters but would expect to see results that include accented characters ; especially when it comes to names. For example, users may search Simon Bolivar but want to see results for Simón Bolívar.

requires

  • nothing

parameters

  • str - required - string to replace diacritics in

returns

  • string with accented characters replaced

example usage:

let str = replaceAccentedCharacters(`Hernán Cortés de Monroy y Pizarro Altamirano`); // 'Hernan Cortes de Monroy y Pizarro Altamirano'

Note some characters like ß as in the German straße (street) won't be replaced for ss - ß isn't an accented character, it is a character in its own right.