html-entities

Fast, zero-dependency HTML5/HTML4/XML entity encoding and decoding for JavaScript and TypeScript.

Library
npm
v2.6.0
686 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
41 /100 Fair
Development Activity 0
Maintenance 20
Community 64
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
73 /100 Good
Architecture 78
Code Quality 85
Innovation 85
Learning Curve 45

html-entities is a small, dependency-free TypeScript library that encodes and decodes HTML entities across the HTML5, HTML4, and XML standards. It exposes a handful of pure functions — encode, decode, and decodeEntity — built around precomputed named-reference tables and regex-based scanners, so there’s no DOM or parser dependency to pull in just to escape or unescape text.

The library is explicitly built for speed and small footprint: it ships its own benchmark suite comparing directly against the two most common alternatives, he and entities, and documents package-size comparisons in its README. It ships as dual ESM/CJS builds via tshy, with full TypeScript types and generated Flow types for legacy typed codebases.

Because entity handling has real security implications (output encoding is a standard XSS mitigation), the library gives fine-grained control over exactly which character ranges get escaped — from HTML’s four special characters up to full non-ASCII and non-printable coverage — plus a choice between decimal and hexadecimal numeric references, and a decode scope that mirrors how browsers parse entities differently inside tag bodies versus attributes.

What You Get

  • encode() for escaping special characters, non-ASCII characters, or the full extensive set, with configurable HTML5/HTML4/XML entity levels
  • decode() for unescaping named and numeric entities, with a scope option that emulates browser parsing rules for tag bodies vs. attributes
  • decodeEntity() for decoding a single entity string in isolation
  • Zero runtime dependencies — the package.json test suite explicitly asserts this stays true
  • Dual ESM and CommonJS builds published from one TypeScript source via tshy, plus generated Flow type definitions
  • Support for decimal or hexadecimal numeric character references on encode

Common Use Cases

  • Escaping user-submitted text before rendering it into HTML templates to prevent injection
  • Decoding entity-encoded content pulled from scraped web pages, RSS/Atom feeds, or CMS exports
  • Normalizing HTML4/XML entity differences when processing content from mixed legacy sources
  • Server-side rendering pipelines that need fast, allocation-light encode/decode without a full HTML parser

Under The Hood

Architecture

The library is a flat functional core rather than a layered system: src/index.ts composes lookup tables from named-references.ts (precomputed HTML5/HTML4/XML entity maps), numeric-unicode-map.ts (legacy numeric character-reference remapping), and surrogate-pairs.ts (UTF-16 surrogate-pair handling for codepoints outside the BMP). encode() and decode() dispatch through mode/level/scope-keyed regex tables (encodeRegExps, decodeRegExps) into a shared getDecodedEntity() helper, so all three decode scopes (strict/body/attribute) stay consistent by construction. There is no class hierarchy, no global mutable state, and no I/O — every function is pure, which keeps the surface easy to reason about but means any change to the core scanning strategy (e.g. moving off regex to a stateful tokenizer) would need to preserve behavior across all scope/level combinations simultaneously.

Tech Stack

Written in TypeScript 5.8 with zero runtime dependencies, verified by an explicit test assertion against package.json. Builds are produced via tshy, publishing matching ESM and CommonJS output from a single source tree, with Flow type definitions generated afterward via flowgen for legacy typed-JS consumers. Tests run under Jest with ts-jest, and the repo maintains its own benchmark.js suite that compares directly against the two closest competing packages, he and entities, tracked in the README’s performance tables.

Code Quality

The test suite spans unit coverage of encode/decode/decodeEntity plus integration checks that exercise the built ESM, CommonJS, and TypeScript-consumer output under test/test-apps/, run through test:dist:commonjs and test:dist:esm scripts. A Husky pre-commit hook enforces lint && test before any commit, and commitlint enforces Conventional Commits. ESLint with typescript-eslint and Prettier keep style consistent. Exported types (Level, EncodeMode, DecodeOptions, etc.) give callers full compile-time safety over the option surface.

API Design The public API is deliberately small: three functions (encode, decode, decodeEntity) cover the entire feature set, each with sensible defaults (level: 'all', mode: 'specialChars') so a caller can start with a single-argument call and opt into finer control only when needed. The README documents every option as a table with concrete before/after examples, and the dual-package exports map means consumers get correct types and module resolution automatically regardless of whether they’re on ESM or CommonJS.

Used by 14 apps in this directory

Python
38%
Other

Open WebUI

AI Agents · AI Assistants

156,607

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
92
Repo Health
75
Technical
66
Dependency
Built with
Python 38%
Svelte 35%
JavaScript 19%
Updated 5 days ago
TypeScript
64%
AGPL 3.0

Puter

Developer Tools · File Storage

43,864

A self-hostable, web-based internet OS with desktop GUI, cloud storage, AI drivers, and a developer SDK — all running in your browser.

View details
88
Repo Health
88
Technical
67
Dependency
Built with
TypeScript 64%
JavaScript 33%
Updated 5 days ago
JavaScript
86%
AGPL 3.0

SillyTavern

AI Assistants

34,869

The power-user LLM frontend that unifies dozens of AI backends with a rich scripting engine, immersive Visual Novel mode, and a thriving extension ecosystem.

View details
88
Repo Health
71
Technical
63
Dependency
Built with
JavaScript 86%
Updated 3 weeks ago
TypeScript
92%
Other

Suna

AI Agents

20,306

Turn your company into a git repo — one config, one command center, a workforce of AI agents that runs the real work around the clock.

View details
90
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 92%
Updated 5 days ago
Python
50%
AGPL 3.0

VoiceStudio

Mcp · Music Audio · Voice AI

83,641

Open-source, fully local ElevenLabs alternative for voice cloning, voice design, video dubbing, dictation, transcription and audiobooks, with a local API and MCP server for agents.

View details
86
Repo Health
83
Technical
70
Dependency
Built with
Python 50%
JavaScript 22%
TypeScript 21%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers