Skip to content

Instantly share code, notes, and snippets.

@theJasonJones
Created December 1, 2016 17:46
Show Gist options
  • Save theJasonJones/75002bbcafa2ee73d598ac8780a15341 to your computer and use it in GitHub Desktop.
Save theJasonJones/75002bbcafa2ee73d598ac8780a15341 to your computer and use it in GitHub Desktop.
var decodeEntities = (function() {
// this prevents any overhead from creating the object each time
var element = document.createElement('div');
function decodeHTMLEntities (str) {
if(str && typeof str === 'string') {
// strip script/html tags
str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, '');
str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');
element.innerHTML = str;
str = element.textContent;
element.textContent = '';
}
return str;
}
return decodeHTMLEntities;
})();
@theJasonJones
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment