{"id":13465011,"url":"https://github.com/sindresorhus/escape-goat","last_synced_at":"2025-05-14T22:07:52.747Z","repository":{"id":21379504,"uuid":"92590590","full_name":"sindresorhus/escape-goat","owner":"sindresorhus","description":"\u0026🐐; Escape a string for use in HTML or the inverse","archived":false,"fork":false,"pushed_at":"2022-07-08T11:14:32.000Z","size":1749,"stargazers_count":533,"open_issues_count":0,"forks_count":32,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-28T16:05:38.766Z","etag":null,"topics":["caprine","escape","goat","goats","html","javascript","nodejs"],"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/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2017-05-27T10:06:31.000Z","updated_at":"2025-04-22T01:17:43.000Z","dependencies_parsed_at":"2022-08-07T10:00:25.087Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/escape-goat","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fescape-goat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fescape-goat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fescape-goat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fescape-goat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/escape-goat/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251389692,"owners_count":21581852,"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":["caprine","escape","goat","goats","html","javascript","nodejs"],"created_at":"2024-07-31T14:00:55.012Z","updated_at":"2025-05-14T22:07:47.735Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003ch1\u003e\n\t\u003cimg src=\"logo.jpg\" width=\"1280\" alt=\"escape-goat\"\u003e\n\u003c/h1\u003e\n\n\u003e Escape a string for use in HTML or the inverse\n\n## Install\n\n```\n$ npm install escape-goat\n```\n\n## Usage\n\n```js\nimport {htmlEscape, htmlUnescape} from 'escape-goat';\n\nhtmlEscape('🦄 \u0026 🐐');\n//=\u003e '🦄 \u0026amp; 🐐'\n\nhtmlUnescape('🦄 \u0026amp; 🐐');\n//=\u003e '🦄 \u0026 🐐'\n\nhtmlEscape('Hello \u003cem\u003eWorld\u003c/em\u003e');\n//=\u003e 'Hello \u0026lt;em\u0026gt;World\u0026lt;/em\u0026gt;'\n\nconst url = 'https://sindresorhus.com?x=\"🦄\"';\n\nhtmlEscape`\u003ca href=\"${url}\"\u003eUnicorn\u003c/a\u003e`;\n//=\u003e '\u003ca href=\"https://sindresorhus.com?x=\u0026quot;🦄\u0026quot;\"\u003eUnicorn\u003c/a\u003e'\n\nconst escapedUrl = 'https://sindresorhus.com?x=\u0026quot;🦄\u0026quot;';\n\nhtmlUnescape`URL from HTML: ${escapedUrl}`;\n//=\u003e 'URL from HTML: https://sindresorhus.com?x=\"🦄\"'\n```\n\n## API\n\n### htmlEscape(string)\n\nEscapes the following characters in the given `string` argument: `\u0026` `\u003c` `\u003e` `\"` `'`\n\nThe function also works as a [tagged template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) that escapes interpolated values.\n\n**Note:** This method of escaping is only safe when inserting data into normal tags like `body`, `div`, `p`, `b`, `td`, etc. Inserting `htmlEscape`'d data into tags like `script` and `style` **opens your app to [XSS vulnerabilities](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#rule-0-never-insert-untrusted-data-except-in-allowed-locations)**.\n\n### htmlUnescape(htmlString)\n\nUnescapes the following HTML entities in the given `htmlString` argument: `\u0026amp;` `\u0026lt;` `\u0026gt;` `\u0026quot;` `\u0026#39;`\n\nThe function also works as a [tagged template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) that unescapes interpolated values.\n\n## Tip\n\nEnsure you always quote your HTML attributes to prevent possible [XSS](https://en.wikipedia.org/wiki/Cross-site_scripting).\n\n## FAQ\n\n### Why yet another HTML escaping package?\n\nI couldn't find one I liked that was tiny, well-tested, and had both escape and unescape methods.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fescape-goat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fescape-goat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fescape-goat/lists"}