Last active
October 4, 2020 17:38
-
-
Save nathanielmata/4d2045a978642f57dcd29deca29751ff to your computer and use it in GitHub Desktop.
replace reserved characters with HTML Entity
This file contains 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
function escapeHtml(unsafe) { | |
const unsafeCharList = { | |
"&": "&", | |
"<": "<", | |
">": ">", | |
"'": "'", | |
'"': """, | |
} | |
return unsafe.replace(/[&<>\'"']/g, function(match) { | |
return unsafeCharList[match]; | |
}) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment