Last active
March 3, 2025 22:08
-
-
Save electerious/ca30857394e25d50a8c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
escapeHTML = (html = '') => { | |
// Ensure that html is a string | |
html += '' | |
// Escape all critical characters | |
html = html.replace(/&/g, '&') | |
.replace(/</g, '<') | |
.replace(/>/g, '>') | |
.replace(/"/g, '"') | |
.replace(/'/g, ''') | |
.replace(/`/g, '`') | |
return html | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
Output: