UNPKG

@technobuddha/library

Version:
40 lines (39 loc) 877 B
const find = /[\u00A0–—‘’‹›“”«»©®¼½¾…€™←→⇐⇒⇔☹☺]/ug; const replace = 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 */ export function correctMSWord(input) { return input.replace(find, a => replace[a]); } export default correctMSWord;