npm.io
1.1.0 β€’ Published 1 week ago

html-entity-codec

Licence
MIT
Version
1.1.0
Deps
0
Size
118 kB
Vulns
0
Weekly
0
Stars
214

html-entity-codec

Decode, encode, and escape HTML character references

page on codsen.com page on npm page on github Downloads per month changelog MIT Licence

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

ok codsen star

Keywords