react / wstein / node_modules / jest-cli / node_modules / lodash.template / node_modules / lodash.escape / index.js
80677 views/**1* lodash 3.0.0 (Custom Build) <https://lodash.com/>2* Build: `lodash modern modularize exports="npm" -o ./`3* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>4* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>5* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors6* Available under MIT license <https://lodash.com/license>7*/8var baseToString = require('lodash._basetostring');910/** Used to match HTML entities and HTML characters. */11var reUnescapedHtml = /[&<>"'`]/g,12reHasUnescapedHtml = RegExp(reUnescapedHtml.source);1314/** Used to map characters to HTML entities. */15var htmlEscapes = {16'&': '&',17'<': '<',18'>': '>',19'"': '"',20"'": ''',21'`': '`'22};2324/**25* Used by `_.escape` to convert characters to HTML entities.26*27* @private28* @param {string} chr The matched character to escape.29* @returns {string} Returns the escaped character.30*/31function escapeHtmlChar(chr) {32return htmlEscapes[chr];33}3435/**36* Converts the characters "&", "<", ">", '"', "'", and '`', in `string` to37* their corresponding HTML entities.38*39* **Note:** No other characters are escaped. To escape additional characters40* use a third-party library like [_he_](https://mths.be/he).41*42* Though the ">" character is escaped for symmetry, characters like43* ">" and "/" don't require escaping in HTML and have no special meaning44* unless they're part of a tag or unquoted attribute value.45* See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)46* (under "semi-related fun fact") for more details.47*48* Backticks are escaped because in Internet Explorer < 9, they can break out49* of attribute values or HTML comments. See [#102](https://html5sec.org/#102),50* [#108](https://html5sec.org/#108), and [#133](https://html5sec.org/#133) of51* the [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.52*53* When working with HTML you should always quote attribute values to reduce54* XSS vectors. See [Ryan Grove's article](http://wonko.com/post/html-escaping)55* for more details.56*57* @static58* @memberOf _59* @category String60* @param {string} [string=''] The string to escape.61* @returns {string} Returns the escaped string.62* @example63*64* _.escape('fred, barney, & pebbles');65* // => 'fred, barney, & pebbles'66*/67function escape(string) {68// Reset `lastIndex` because in IE < 9 `String#replace` does not.69string = baseToString(string);70return (string && reHasUnescapedHtml.test(string))71? string.replace(reUnescapedHtml, escapeHtmlChar)72: string;73}7475module.exports = escape;767778