64 lines
923 B
JavaScript
64 lines
923 B
JavaScript
// via https://github.com/jonschlinkert/unescape/blob/98d1e52/index.js
|
|
|
|
const chars = {
|
|
'"': '"',
|
|
'"': '"',
|
|
|
|
''': '\'',
|
|
''': '\'',
|
|
|
|
'&': '&',
|
|
'&': '&',
|
|
|
|
'>': '>',
|
|
'>': '>',
|
|
|
|
'<': '<',
|
|
'<': '<',
|
|
|
|
'¢': '¢',
|
|
'¢': '¢',
|
|
|
|
'©': '©',
|
|
'©': '©',
|
|
|
|
'€': '€',
|
|
'€': '€',
|
|
|
|
'£': '£',
|
|
'£': '£',
|
|
|
|
'®': '®',
|
|
'®': '®',
|
|
|
|
'¥': '¥',
|
|
'¥': '¥',
|
|
|
|
' ': ' '
|
|
}
|
|
|
|
let regex
|
|
|
|
/**
|
|
* Convert HTML entities to HTML characters.
|
|
*
|
|
* @param {String} `str` String with HTML entities to un-escape.
|
|
* @return {String}
|
|
*/
|
|
|
|
function unescape (str) {
|
|
regex = regex || toRegex(chars)
|
|
return str.replace(regex, m => chars[m])
|
|
}
|
|
|
|
function toRegex (chars) {
|
|
var keys = Object.keys(chars).join('|')
|
|
return new RegExp('(' + keys + ')', 'g')
|
|
}
|
|
|
|
/**
|
|
* Expose `unescape`
|
|
*/
|
|
|
|
export { unescape }
|