UNPKG

527 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.escapeHTML = escapeHTML;
7// Based on _.escape https://github.com/lodash/lodash/blob/master/escape.js
8const reUnescapedHtml = /[&<>"']/g;
9const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
10const htmlEscapes = {
11 '&': '&amp;',
12 '<': '&lt;',
13 '>': '&gt;',
14 '"': '&quot;',
15 "'": '&#39;'
16};
17
18function escapeHTML(s) {
19 if (reHasUnescapedHtml.test(s)) {
20 return s.replace(reUnescapedHtml, c => htmlEscapes[c]);
21 }
22
23 return s;
24}
\No newline at end of file