mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Optimize _.escape, _.escapeRegExp, and _.unescape.
This commit is contained in:
19
lodash.js
19
lodash.js
@@ -7792,7 +7792,10 @@
|
|||||||
* // => 'fred, barney, & pebbles'
|
* // => 'fred, barney, & pebbles'
|
||||||
*/
|
*/
|
||||||
function escape(string) {
|
function escape(string) {
|
||||||
return string == null ? '' : String(string).replace(reUnescapedHtml, escapeHtmlChar);
|
string = string == null ? '' : String(string);
|
||||||
|
return (reUnescapedHtml.lastIndex = 0, reUnescapedHtml.test(string))
|
||||||
|
? string.replace(reUnescapedHtml, escapeHtmlChar)
|
||||||
|
: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -7810,7 +7813,10 @@
|
|||||||
* // => '\[lodash\]\(http://lodash\.com\)'
|
* // => '\[lodash\]\(http://lodash\.com\)'
|
||||||
*/
|
*/
|
||||||
function escapeRegExp(string) {
|
function escapeRegExp(string) {
|
||||||
return string == null ? '' : String(string).replace(reRegExpChars, '\\$&');
|
string = string == null ? '' : String(string);
|
||||||
|
return (reRegExpChars.lastIndex = 0, reRegExpChars.test(string))
|
||||||
|
? string.replace(reRegExpChars, '\\$&')
|
||||||
|
: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8401,11 +8407,10 @@
|
|||||||
* // => 'fred, barney & pebbles'
|
* // => 'fred, barney & pebbles'
|
||||||
*/
|
*/
|
||||||
function unescape(string) {
|
function unescape(string) {
|
||||||
if (string == null) {
|
string = string == null ? '' : String(string);
|
||||||
return '';
|
return (reEscapedHtml.lastIndex = 0, reEscapedHtml.test(string))
|
||||||
}
|
? string.replace(reEscapedHtml, unescapeHtmlChar)
|
||||||
string = String(string);
|
: string;
|
||||||
return string.indexOf(';') < 0 ? string : string.replace(reEscapedHtml, unescapeHtmlChar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user