&🐐; Escape a string for use in HTML or the inverse
Installations
npm install escape-goat
Score
99.4
Supply Chain
84.1
Quality
75.6
Maintenance
100
Vulnerability
100
License
Developer
sindresorhus
Developer Guide
Module System
ESM
Min. Node Version
>=12
Typescript Support
No
Node Version
14.16.1
NPM Version
6.14.10
Statistics
521 Stars
31 Commits
32 Forks
7 Watching
1 Branches
9 Contributors
Updated on 26 Nov 2024
Bundle Size
744.00 B
Minified
356.00 B
Minified + Gzipped
Languages
JavaScript (87.04%)
TypeScript (12.96%)
Total Downloads
Cumulative downloads
Total Downloads
1,291,616,675
Last day
-11%
1,169,887
Compared to previous day
Last week
-0.8%
7,031,793
Compared to previous week
Last month
13.4%
28,789,044
Compared to previous month
Last year
-1.2%
294,906,916
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Escape a string for use in HTML or the inverse
Install
$ npm install escape-goat
Usage
1import {htmlEscape, htmlUnescape} from 'escape-goat'; 2 3htmlEscape('🦄 & 🐐'); 4//=> '🦄 & 🐐' 5 6htmlUnescape('🦄 & 🐐'); 7//=> '🦄 & 🐐' 8 9htmlEscape('Hello <em>World</em>'); 10//=> 'Hello <em>World</em>' 11 12const url = 'https://sindresorhus.com?x="🦄"'; 13 14htmlEscape`<a href="${url}">Unicorn</a>`; 15//=> '<a href="https://sindresorhus.com?x="🦄"">Unicorn</a>' 16 17const escapedUrl = 'https://sindresorhus.com?x="🦄"'; 18 19htmlUnescape`URL from HTML: ${escapedUrl}`; 20//=> 'URL from HTML: https://sindresorhus.com?x="🦄"'
API
htmlEscape(string)
Escapes the following characters in the given string
argument: &
<
>
"
'
The function also works as a tagged template literal that escapes interpolated values.
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.
htmlUnescape(htmlString)
Unescapes the following HTML entities in the given htmlString
argument: &
<
>
"
'
The function also works as a tagged template literal that unescapes interpolated values.
Tip
Ensure you always quote your HTML attributes to prevent possible XSS.
FAQ
Why yet another HTML escaping package?
I couldn't find one I liked that was tiny, well-tested, and had both escape and unescape methods.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
0 existing vulnerabilities detected
Reason
Found 12/30 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/escape-goat/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/escape-goat/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:21
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Score
4.4
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More