/
TON618OFF
/
FinalPWHTML
Обзор
Документация
Войти
/
TON618OFF
/
FinalPWHTML
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
node_modules/es-escape-html/src/index.js
61 строка
2 KB
TON618OFF
не ну это ваще
23 июн 2024, 00:30
23 июн 2024, 00:30
e27ae20
Код
Авторство
О чём код?
const matchHtmlRegExp = /["'&<>]/; /** * Escape special characters in the given string of text, such that it can be interpolated in HTML content. * This function will escape the following characters: `"`, `'`, `&`, `<`, and `>`. * * *Note* that the escaped value is only suitable for being interpolated into HTML as the text content of * elements in which the tag does not have different escaping mechanisms (it cannot be placed inside * `<style>` or `<script>`, for example, as those content bodies are not HTML, but CSS and JavaScript, * respectively; these are known as "raw text elements" in the HTML standard). * * *Note* when using the escaped value within a tag, it is only suitable as the value of an attribute, * where the value is quoted with either a double quote character (`"`) or a single quote character (`'`). * * @param {string} str The string to escape for inserting into HTML * @return {string} * @public */ export function 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; }