Sha256: aee6c381b9303b6ec91e5303feecc62a6a190919996e3838832681916dacbe99

Contents?: true

Size: 1.41 KB

Versions: 264

Compression:

Stored size: 1.41 KB

Contents

var escapeHtmlChar = require('./_escapeHtmlChar'),
    toString = require('./toString');

/** Used to match HTML entities and HTML characters. */
var reUnescapedHtml = /[&<>"']/g,
    reHasUnescapedHtml = RegExp(reUnescapedHtml.source);

/**
 * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
 * corresponding HTML entities.
 *
 * **Note:** No other characters are escaped. To escape additional
 * characters use a third-party library like [_he_](https://mths.be/he).
 *
 * Though the ">" character is escaped for symmetry, characters like
 * ">" and "/" don't need escaping in HTML and have no special meaning
 * unless they're part of a tag or unquoted attribute value. See
 * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
 * (under "semi-related fun fact") for more details.
 *
 * When working with HTML you should always
 * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
 * XSS vectors.
 *
 * @static
 * @since 0.1.0
 * @memberOf _
 * @category String
 * @param {string} [string=''] The string to escape.
 * @returns {string} Returns the escaped string.
 * @example
 *
 * _.escape('fred, barney, & pebbles');
 * // => 'fred, barney, &amp; pebbles'
 */
function escape(string) {
  string = toString(string);
  return (string && reHasUnescapedHtml.test(string))
    ? string.replace(reUnescapedHtml, escapeHtmlChar)
    : string;
}

module.exports = escape;

Version data entries

264 entries across 262 versions & 29 rubygems

Version Path
clapton-0.0.12 lib/clapton/javascripts/node_modules/lodash/escape.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/lodash/escape.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/lodash/escape.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/lodash/escape.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/lodash/escape.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/lodash/escape.js
clapton-0.0.6 lib/clapton/javascripts/node_modules/lodash/escape.js
clapton-0.0.5 lib/clapton/javascripts/node_modules/lodash/escape.js
clapton-0.0.4 lib/clapton/javascripts/node_modules/lodash/escape.js
clapton-0.0.3 lib/clapton/javascripts/node_modules/lodash/escape.js
clapton-0.0.2 lib/clapton/javascripts/node_modules/lodash/escape.js
clapton-0.0.1 lib/clapton/javascripts/node_modules/lodash/escape.js
immosquare-cleaner-0.1.47 node_modules/lodash/escape.js
immosquare-cleaner-0.1.46 node_modules/lodash/escape.js
immosquare-cleaner-0.1.45 node_modules/lodash/escape.js
immosquare-cleaner-0.1.44 node_modules/lodash/escape.js
boring_generators-0.14.0 tmp/templates/app_template/node_modules/lodash/escape.js
immosquare-cleaner-0.1.43 node_modules/lodash/escape.js
immosquare-cleaner-0.1.42 node_modules/lodash/escape.js
immosquare-cleaner-0.1.41 node_modules/lodash/escape.js