Skip to content

Instantly share code, notes, and snippets.

@bevacqua
Created September 10, 2014 15:13
Show Gist options
  • Save bevacqua/83d98737ffd3b5509212 to your computer and use it in GitHub Desktop.
Save bevacqua/83d98737ffd3b5509212 to your computer and use it in GitHub Desktop.
he browser shim
function encodeHtml (text) {
if (!text) {
return text;
}
var div = document.createElement('div');
div.innerText = div.textContent = text;
return div.innerHTML;
}
function decodeHtml (html) {
if (!html) {
return html;
}
var div = document.createElement('div');
div.innerHTML = html;
return div.innerText || div.textContent;
}
encodeHtml.options = decodeHtml.options = {};
module.exports = {
encode: encodeHtml,
escape: encodeHtml,
decode: decodeHtml,
unescape: decodeHtml,
version: '1.0.0-browser'
};
@mathiasbynens
Copy link

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