1
var baseToString = require('../internal/baseToString'),
2
unescapeHtmlChar = require('../internal/unescapeHtmlChar');
4
/** Used to match HTML entities and HTML characters. */
5
var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
6
reHasEscapedHtml = RegExp(reEscapedHtml.source);
9
* The inverse of `_.escape`; this method converts the HTML entities
10
* `&`, `<`, `>`, `"`, `'`, and ``` in `string` to their
11
* corresponding characters.
13
* **Note:** No other HTML entities are unescaped. To unescape additional HTML
14
* entities use a third-party library like [_he_](https://mths.be/he).
19
* @param {string} [string=''] The string to unescape.
20
* @returns {string} Returns the unescaped string.
23
* _.unescape('fred, barney, & pebbles');
24
* // => 'fred, barney, & pebbles'
26
function unescape(string) {
27
string = baseToString(string);
28
return (string && reHasEscapedHtml.test(string))
29
? string.replace(reEscapedHtml, unescapeHtmlChar)
33
module.exports = unescape;