mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 01:57:50 +00:00
Consolidate escape and unescape modules.
This commit is contained in:
12
unescape.js
12
unescape.js
@@ -1,5 +1,13 @@
|
||||
import toString from './toString.js';
|
||||
import unescapeHtmlChar from './.internal/unescapeHtmlChar.js';
|
||||
|
||||
/** Used to map HTML entities to characters. */
|
||||
const htmlUnescapes = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
''': "'"
|
||||
};
|
||||
|
||||
/** Used to match HTML entities and HTML characters. */
|
||||
const reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g;
|
||||
@@ -25,7 +33,7 @@ const reHasEscapedHtml = RegExp(reEscapedHtml.source);
|
||||
function unescape(string) {
|
||||
string = toString(string);
|
||||
return (string && reHasEscapedHtml.test(string))
|
||||
? string.replace(reEscapedHtml, unescapeHtmlChar)
|
||||
? string.replace(reEscapedHtml, entity => htmlUnescapes[entity])
|
||||
: string;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user