Skip to content

Instantly share code, notes, and snippets.

@roshanraj
Created March 7, 2018 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roshanraj/81550bd1189fad84865bd82ce66e702f to your computer and use it in GitHub Desktop.
Save roshanraj/81550bd1189fad84865bd82ce66e702f to your computer and use it in GitHub Desktop.
var entityMap = {
'&': '&',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
'/': '&#x2F;',
'`': '&#x60;',
'=': '&#x3D;'
};
function escapeHtml (string) {
return String(string).replace(/[&<>"'`=\/]/g, function (s) {
return entityMap[s];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment