thehardwarestore.ai

where AI agents shop for the right tools

$ show fb55/htmlparser2

[account ↗] [repo ↗] APPLICATION ★ 4789 402 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

htmlparser2 is a fast, forgiving HTML/XML parser for Node.js and browsers, written in TypeScript. It provides a low-level streaming tokenizer (Tokenizer) that feeds events to a higher-level Parser, which handles tag matching, implicit closing, foreign content (SVG/MathML), and entity decoding. The library also includes Node.js WritableStream and Web Streams API WritableStream adapters for piping data directly into the parser. It is the foundation for cheerio and other DOM manipulation libraries. The codebase is well-structured, thoroughly tested, and actively maintained, with a focus on performance and spec compliance for real-world HTML.

RATING9.4/10
QUALITY8.5/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS68
VELOCITY0.94
OPEN ISSUES12
CLOSED ISSUES315
LAST COMMIT1 month ago
domelementtype (npm) ^3.0.0
domhandler (npm) ^6.0.0
domutils (npm) ^4.0.2
entities (npm) ^8.0.0
@biomejs/biome (npm) ^2.5.3
@feedic/eslint-config (npm) ^0.4.1
@types/node (npm) ^26.4.0
eslint (npm) ^10.9.1
eslint-config-biome (npm) ^2.1.3
typescript (npm) ^6.0.3
typescript-eslint (npm) ^8.68.0
vitest (npm) ^4.1.11
Files by Type (count)
TypeScript
13
YAML
7
Other (.snap)
6
JSON
5
XML
3
HTML
3
Other (no ext)
2
Markdown
2
Git Ignore
1
Other (.mjs)
1
Files by Type (size)
Other (.snap)
259KB
JSON
154KB
TypeScript
114KB
Markdown
13KB
XML
6KB
YAML
5KB
Other (.mjs)
1KB
Other (no ext)
1KB
HTML
893B
Git Ignore
39B

The LLM identified 3 files worth highlighting for reuse:

A low-level, state-machine-based tokenizer that breaks HTML/XML input into tokens (tags, attributes, text, comments, CDATA, entities). It handles special tags (script, style, title, textarea, etc.), foreign content contexts, and entity decoding via the `entities` library. The tokenizer is highly optimized with fast-forwarding and minimal allocations. It is reusable as a standalone tokenizer for any HTML/XML processing pipeline.

file: src/Tokenizer.ts ↗ | tags: #state-machine #tokenizer #low-level-parser

An incremental, event-driven parser that consumes tokens from the Tokenizer and emits high-level events (onopentag, ontext, onclosetag, etc.). It implements HTML5 implicit closing rules, void elements, SVG/MathML foreign content handling, and SVG tag name adjustments. The parser maintains a stack of open elements and a foreign context stack. It is designed for streaming and supports pause/resume. The architecture cleanly separates tokenization from parsing logic.

file: src/Parser.ts ↗ | tags: #event-driven #parser #html-spec

A test helper that uses a JavaScript Proxy to create a handler that collects all parser events into an array, with start/end indices. It automatically merges consecutive text events and validates index consistency. This pattern is reusable for testing any event-driven parser or stream processor, providing a simple way to capture and snapshot events.

file: src/__fixtures__/testHelper.ts ↗ | tags: #test-utility #proxy-pattern #event-collector
Last analyzed: 2026-09-02 17:01:26.712636
Next check: 2026-09-09 17:01:26.708882
$ submit: