he
A robust HTML entity encoder and decoder that handles named references, hex, and decimal escaping.
Official Documentation ↗v2.0.0. Check the official docs for the latest API surface.Installation
npm install heMethods
No methods match this filter.
he encodes and decodes HTML entities without a DOM, so it works in build scripts and any runtime.
Key Features
- Full named entity table
- encode, decode, escape, and unescape helpers
- Configurable entity escape style
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/mathiasbynens/he@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:13.884Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- With strict enabled, he.encode either throws (if the input contains invalid code points) or returns a string of valid HTML. (https://cdn.jsdelivr.net/gh/mathiasbynens/he@latest/README.md)
- This means that encode() will encode any HTML text content you feed it, even if it contains any symbols that cause parse errors. (https://cdn.jsdelivr.net/gh/mathiasbynens/he@latest/README.md)
- To throw an error when such invalid HTML is encountered, set the strict option to true. (https://cdn.jsdelivr.net/gh/mathiasbynens/he@latest/README.md)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/mathiasbynens/he@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:13.884Z.
- If the option is enabled, encode will generally use decimal escapes (e.g. (https://cdn.jsdelivr.net/gh/mathiasbynens/he@latest/README.md)
- HTML entities without a named reference are encoded using decimal escapes. (https://cdn.jsdelivr.net/gh/mathiasbynens/he@latest/README.md)
- This means that encode() will not use any character references for printable ASCII symbols that don’t need escaping. (https://cdn.jsdelivr.net/gh/mathiasbynens/he@latest/README.md)
FAQ
- How is he different from the DOM?
- he is a pure string encoder and decoder with no DOM dependency, so it works in any environment including build scripts and workers.
- Does he decode entities without semicolons?
- Only in its lenient mode. Use strict: true to avoid decoding ambiguous ampersands that appear in ordinary text.
- Is encoding enough to prevent XSS?
- Encoding text and quoted attribute values is the main defense, but you must also use safe contexts and avoid inline scripts.
Report a problem with this API docOpens a pre-filled issue on GitHub.