API Reference

he

A robust HTML entity encoder and decoder that handles named references, hex, and decimal escaping.

Official Documentation ↗
CompatibilityThis documentation covers version v2.0.0. Check the official docs for the latest API surface.

Installation

npmnpm install he

Methods

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.

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.

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.