{"id":13536661,"url":"https://github.com/component/escape-html","last_synced_at":"2025-05-14T19:02:24.701Z","repository":{"id":4311855,"uuid":"5444800","full_name":"component/escape-html","owner":"component","description":"Escape string for use in HTML","archived":false,"fork":false,"pushed_at":"2022-09-16T12:09:21.000Z","size":32,"stargazers_count":470,"open_issues_count":2,"forks_count":66,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-31T18:05:31.537Z","etag":null,"topics":["escape","html","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/component.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-08-16T21:30:20.000Z","updated_at":"2025-03-25T21:04:20.000Z","dependencies_parsed_at":"2022-09-05T11:01:32.426Z","dependency_job_id":null,"html_url":"https://github.com/component/escape-html","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fescape-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fescape-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fescape-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/component%2Fescape-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/component","download_url":"https://codeload.github.com/component/escape-html/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457809,"owners_count":20941906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["escape","html","javascript"],"created_at":"2024-08-01T09:00:46.646Z","updated_at":"2025-04-07T19:04:40.087Z","avatar_url":"https://github.com/component.png","language":"JavaScript","readme":"# escape-html\n\n[![NPM Version][npm-version-image]][npm-url]\n[![NPM Downloads][npm-downloads-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\n  Escape string for use in HTML\n\nThis module exports a single function, `escapeHtml`, that is used to escape\na string of content such that it can be interpolated in HTML content.\n\n## Installation\n\nThis is a [Node.js](https://nodejs.org/en/) module available through the\n[npm registry](https://www.npmjs.com/). Installation is done using the\n[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```bash\n$ npm install escape-html\n```\n\n## API\n\n### escapeHtml(string)\n\nEscape special characters in the given string of text, such that it can be\ninterpolated in HTML content.\n\nThis function will escape the following characters: `\"`, `'`, `\u0026`, `\u003c`, and\n`\u003e`.\n\n**Note** that the escaped value is only suitable for being interpolated into\nHTML as the text content of elements in which the tag does not have different\nescaping mechanisms (it cannot be placed inside `\u003cstyle\u003e` or `\u003cscript\u003e`, for\nexample, as those content bodies are not HTML, but CSS and JavaScript,\nrespectively; these are known as \"raw text elements\" in the HTML standard).\n\n**Note** when using the escaped value within a tag, it is only suitable as\nthe value of an attribute, where the value is quoted with either a double\nquote character (`\"`) or a single quote character (`'`).\n\n## Example\n\nThe `escapeHtml` function is designed to accept a string input of text and\nreturn an escaped value to interpolate into HTML.\n\n```js\nvar escapeHtml = require('escape-html')\n\n// example values\nvar desc = 'I \u003cb\u003ethink\u003c/b\u003e this is good.'\nvar fullName = 'John \"Johnny\" Smith'\n\n// example passing in text into a html attribute\nconsole.dir('\u003cinput name=\"full_name\" value=\"' + escapeHtml(fullName) + '\"\u003e')\n// -\u003e '\u003cinput name=\"full_name\" value=\"John \u0026quot;Johnny\u0026quot; Smith\"\u003e'\n\n// example passing in text in html body\nconsole.dir('\u003ctextarea name=\"desc\"\u003e' + escapeHtml(desc) + '\u003c/textarea\u003e')\n// -\u003e '\u003ctextarea name=\"desc\"\u003eI \u0026lt;b\u0026gt;think\u0026lt;/b\u0026gt; this is good.\u003c/textarea\u003e'\n```\n\n## Benchmark\n\n```\n$ npm run-script bench\n\n\u003e escape-html@1.0.3 bench nodejs-escape-html\n\u003e node benchmark/index.js\n\n\n  http_parser@1.0\n  node@0.10.33\n  v8@3.14.5.9\n  ares@1.9.0-DEV\n  uv@0.10.29\n  zlib@1.2.3\n  modules@11\n  openssl@1.0.1j\n\n  1 test completed.\n  2 tests completed.\n  3 tests completed.\n\n  no special characters    x 19,435,271 ops/sec ±0.85% (187 runs sampled)\n  single special character x  6,132,421 ops/sec ±0.67% (194 runs sampled)\n  many special characters  x  3,175,826 ops/sec ±0.65% (193 runs sampled)\n```\n\n## License\n\n[MIT](LICENSE)\n\n[coveralls-image]: https://badgen.net/coveralls/c/github/component/escape-html/master\n[coveralls-url]: https://coveralls.io/r/component/escape-html?branch=master\n[npm-downloads-image]: https://badgen.net/npm/dm/escape-html\n[npm-url]: https://npmjs.org/package/escape-html\n[npm-version-image]: https://badgen.net/npm/v/escape-html\n[travis-image]: https://badgen.net/travis/component/escape-html/master\n[travis-url]: https://travis-ci.org/component/escape-html\n","funding_links":[],"categories":["JavaScript","Utilities"],"sub_categories":["React Components"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomponent%2Fescape-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomponent%2Fescape-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomponent%2Fescape-html/lists"}