This is a small and powerful decoder of HTML character references (often called
entities).
When should I use this?
You can use this for spec-compliant decoding of character references.
It’s small and fast enough to do that well.
You can also use this when making a linter, because there are different warnings
emitted with reasons for why and positional info on where they happened.
Install
This package is ESM only.
In Node.js (version 14.14+, 16.0+), install with npm:
this (*) — refers to textContext when given to parseEntities
value (string) — string of content
position (Position) — place where value starts and ends
function reference(value, position, source)
Character reference handler.
Parameters
this (*) — refers to referenceContext when given to parseEntities
value (string) — decoded character reference
position (Position) — place where source starts and ends
source (string) — raw source of character reference
Types
This package is fully typed with TypeScript.
It exports the additional types Options, WarningHandler,
ReferenceHandler, and TextHandler.
Compatibility
This package is at least compatible with all maintained versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
It also works in Deno and modern browsers.
Security
This package is safe: it matches the HTML spec to parse character references.