Created
November 15, 2017 19:07
-
-
Save loicbisiere/b5dec1c8b8e8a06bb8008dd43f380543 to your computer and use it in GitHub Desktop.
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
String.prototype.decodeHTML = function() { | |
var map = {"gt":">" /* , … */}; | |
return this.replace(/&(#(?:x[0-9a-f]+|\d+)|[a-z]+);?/gi, function($0, $1) { | |
if ($1[0] === "#") { | |
return String.fromCharCode($1[1].toLowerCase() === "x" ? parseInt($1.substr(2), 16) : parseInt($1.substr(1), 10)); | |
} else { | |
return map.hasOwnProperty($1) ? map[$1] : $0; | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment