five-server
Version:
Development Server with Live Reload Capability. (Maintained Fork of Live Server)
53 lines • 1.66 kB
JavaScript
;
/**
* @package escape-html (https://www.npmjs.com/package/escape-html)
*
* @copyright
* Copyright(c) 2012-2013 TJ Holowaychuk
* Copyright(c) 2015 Andreas Lubbe
* Copyright(c) 2015 Tiancheng "Timothy" Gu
*
* @license {@link https://github.com/component/escape-html/blob/master/LICENSE MIT}
*
* @description modified version of escape-html@1.0.3 (https://github.com/component/escape-html/blob/master/index.js)
*/
Object.defineProperty(exports, "__esModule", { value: true });
const matchHtmlRegExp = /["'&<>]/;
/** Escape special characters in the given string of text. */
const escapeHtml = (str) => {
const match = matchHtmlRegExp.exec(str);
if (!match)
return str;
let escape;
let html = '';
let index = 0;
let lastIndex = 0;
for (index = match.index; index < str.length; index++) {
switch (str.charCodeAt(index)) {
case 34: // "
escape = '"';
break;
case 38: // &
escape = '&';
break;
case 39: // '
escape = ''';
break;
case 60: // <
escape = '<';
break;
case 62: // >
escape = '>';
break;
default:
continue;
}
if (lastIndex !== index)
html += str.substring(lastIndex, index);
lastIndex = index + 1;
html += escape;
}
return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
};
exports.default = escapeHtml;
//# sourceMappingURL=escape-html.js.map