UNPKG

@technobuddha/library

Version:
41 lines (39 loc) 889 B
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]); }