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.
escape('fred, barney, & pebbles')
// => 'fred, barney, & pebbles'
Name | Type | Attribute | Description |
---|---|---|---|
string | The string to escape. |
{ "comment": "/**\r\n * Converts the characters \"&\", \"<\", \">\", '\"', and \"'\" in `string` to their\r\n * corresponding HTML entities.\r\n *\r\n * **Note:** No other characters are escaped. To escape additional\r\n * characters use a third-party library like [_he_](https://mths.be/he).\r\n *\r\n * Though the \">\" character is escaped for symmetry, characters like\r\n * \">\" and \"/\" don't need escaping in HTML and have no special meaning\r\n * unless they're part of a tag or unquoted attribute value. See\r\n * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)\r\n * (under \"semi-related fun fact\") for more details.\r\n *\r\n * When working with HTML you should always\r\n * [quote attribute values](http://wonko.com/post/html-escaping) to reduce\r\n * XSS vectors.\r\n *\r\n * @since 0.1.0\r\n * @category String\r\n * @param {string} [string=''] The string to escape.\r\n * @returns {string} Returns the escaped string.\r\n * @see escapeRegExp, unescape\r\n * @example\r\n *\r\n * escape('fred, barney, & pebbles')\r\n * // => 'fred, barney, & pebbles'\r\n */", "meta": { "range": [ 1339, 1501 ], "filename": "escape.js", "lineno": 41, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo", "code": { "id": "astnode100002234", "name": "escape", "type": "FunctionDeclaration", "paramnames": [ "string" ] }, "vars": { "": null } }, "description": "Converts the characters \"&\", \"<\", \">\", '\"', and \"'\" in `string` to their\rcorresponding HTML entities.\r\r**Note:** No other characters are escaped. To escape additional\rcharacters use a third-party library like [_he_](https://mths.be/he).\r\rThough the \">\" character is escaped for symmetry, characters like\r\">\" and \"/\" don't need escaping in HTML and have no special meaning\runless they're part of a tag or unquoted attribute value. See\r[Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)\r(under \"semi-related fun fact\") for more details.\r\rWhen working with HTML you should always\r[quote attribute values](http://wonko.com/post/html-escaping) to reduce\rXSS vectors.", "since": "0.1.0", "tags": [ { "originalTitle": "category", "title": "category", "text": "String", "value": "String" } ], "params": [ { "type": { "names": [ "string" ] }, "optional": true, "defaultvalue": "''", "description": "The string to escape.", "name": "string" } ], "returns": [ { "type": { "names": [ "string" ] }, "description": "Returns the escaped string." } ], "see": [ "escapeRegExp, unescape" ], "examples": [ "escape('fred, barney, & pebbles')\r// => 'fred, barney, & pebbles'" ], "name": "escape", "longname": "escape", "kind": "function", "scope": "global", "___id": "T000002R000248", "___s": true, "filepath": "escape.js" }