html-entity-codec
Decode, encode, and escape HTML character references
No dependencies whatsoever. This package declares no dependencies or devDependencies.
Features
HTML character-reference transformations from pinned WHATWG data.
- Decode in one pass with text or attribute context and explicit semicolon and parse-error policies.
- Encode with stable named aliases or uppercase hexadecimal references; the dedicated numeric encoder lets bundlers omit named data.
- Escape quoted attributes and ordinary HTML text, with optional progress and completion callbacks.
- Keep source offsets through the reference scanner.
Install
This package is pure ESM.
npm i html-entity-codec
Quick Take
import assert from "node:assert/strict";
import { decode } from "html-entity-codec";
assert.equal(
decode("Cat & fiddle 😼🎻"),
"Cat & fiddle πΌπ»",
);
Documentation
Please visit codsen.com for a full description of the API. For Changelog, see raw md on GitHub or the website.
Contributing
To report bugs or request features or assistance, raise an issue on GitHub.
Licence
MIT License
Copyright 2010-2026 Roy Revelt and other contributors
HTML named character references - Copyright WHATWG (Apple, Google, Mozilla, Microsoft) - see its BSD-3-Clause disclaimer
![]()