Last change
on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | var toString = require('./toString'),
|
---|
| 2 | unescapeHtmlChar = require('./_unescapeHtmlChar');
|
---|
| 3 |
|
---|
| 4 | /** Used to match HTML entities and HTML characters. */
|
---|
| 5 | var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
|
---|
| 6 | reHasEscapedHtml = RegExp(reEscapedHtml.source);
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * The inverse of `_.escape`; this method converts the HTML entities
|
---|
| 10 | * `&`, `<`, `>`, `"`, and `'` in `string` to
|
---|
| 11 | * their corresponding characters.
|
---|
| 12 | *
|
---|
| 13 | * **Note:** No other HTML entities are unescaped. To unescape additional
|
---|
| 14 | * HTML entities use a third-party library like [_he_](https://mths.be/he).
|
---|
| 15 | *
|
---|
| 16 | * @static
|
---|
| 17 | * @memberOf _
|
---|
| 18 | * @since 0.6.0
|
---|
| 19 | * @category String
|
---|
| 20 | * @param {string} [string=''] The string to unescape.
|
---|
| 21 | * @returns {string} Returns the unescaped string.
|
---|
| 22 | * @example
|
---|
| 23 | *
|
---|
| 24 | * _.unescape('fred, barney, & pebbles');
|
---|
| 25 | * // => 'fred, barney, & pebbles'
|
---|
| 26 | */
|
---|
| 27 | function unescape(string) {
|
---|
| 28 | string = toString(string);
|
---|
| 29 | return (string && reHasEscapedHtml.test(string))
|
---|
| 30 | ? string.replace(reEscapedHtml, unescapeHtmlChar)
|
---|
| 31 | : string;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | module.exports = unescape;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.