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
| const escapeHtml = (str) => { let arr = [ 'le': '<=', 'lt': '>=', 'gt': '>', 'ge': '<', 'amp': '&', 'quot': '"', 'lsquo': '‘', 'rsquo': '’', 'ldquo': '“', 'rdquo': '”', 'middot': '·', 'nbsp': ' ', 'iexcl': '¡', 'cent': '¢', 'pound': '£', 'mdash': '—', 'hellip': '…', 'infinity': '∞' ] if (str && str.replace) { return str.replace(/&(le|lt|gt|ge|amp|quot|lsquo|rsquo|ldquo|rdquo|middot|nbsp|iexcl|cent|pound|mdash|hellip|infinity);/ig, (all, t) => { return arr[t] }) } else { return str } }
|