All files correct-ms-word.ts

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

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 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 411x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                 1x 21x 21x  
const find = /[\u00A0–—‘’‹›“”«»©®¼½¾…€™←→⇐⇒⇔☹☺]/gu;
const replace: Readonly<Record<string, string>> = Object.freeze({
  '\u00A0': ' ',
  '–': '-',
  '—': '-',
  '‘': "'",
  '’': "'",
  '‹': '<',
  '›': '>',
  '“': '"',
  '”': '"',
  '«': '<<',
  '»': '>>',
  '©': '(c)',
  '®': '(r)',
  '¼': '1/4',
  '½': '1/2',
  '¾': '3/4',
  '…': '...',
  '€': '(e)',
  '™': '(tm)',
  '←': '<--',
  '→': '-->',
  '⇐': '<==',
  '⇒': '==>',
  '⇔': '<=>',
  '☹': ':(',
  '☺': ':)',
});
 
/**
 * Correct character sequences that Microsoft Word changes to make it look prettier
 * @param input - The mangled string
 * @returns string with special characters corrected
 * @group String
 * @category Operations
 */
export function correctMSWord(input: string): string {
  return input.replaceAll(find, (a) => replace[a]);
}