refactor: move encode HTML function into separate module (#4591)

Co-authored-by: Alexandr <qwerty541zxc@gmail.com>
This commit is contained in:
Alexandr Garbuzov
2025-10-17 21:26:37 +03:00
committed by GitHub
co-authored by Alexandr
parent af1d8cad6f
commit b240a06e7b
9 changed files with 30 additions and 24 deletions
+19
View File
@@ -0,0 +1,19 @@
// @ts-check
/**
* Encode string as HTML.
*
* @see https://stackoverflow.com/a/48073476/10629172
*
* @param {string} str String to encode.
* @returns {string} Encoded string.
*/
const encodeHTML = (str) => {
return str
.replace(/[\u00A0-\u9999<>&](?!#)/gim, (i) => {
return "&#" + i.charCodeAt(0) + ";";
})
.replace(/\u0008/gim, "");
};
export { encodeHTML };