All files / string remove-diacritics.ts

100% Statements 2/2
100% Branches 0/0
100% Functions 1/1
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 142x                     9x    
const DIACRITICS_PATTERN = /\p{M}/gv;
 
/**
 * Removes the accents of a text (`Été` → `Ete`), to search or sort without them. `ø`, `ß` or `æ` stay.
 *
 * @param input - The text.
 * @returns The text without combining marks.
 * @example
 * removeDiacritics('Crème brûlée à Évian'); // 'Creme brulee a Evian'
 */
export function removeDiacritics(input: string): string {
  return input.normalize('NFD').replaceAll(DIACRITICS_PATTERN, '');
}