1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 1x 1x 130x | const chars = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''', '\xA0': ' ', '×': '×', }; const regex = new RegExp(`(${Object.keys(chars).join('|')})`, ['g']); export default function escapeHTML(str) { return str.replace(regex, c => chars[c]); } |