Registry / serialization / fast-html-parser

fast-html-parser

JSON →
library1.0.1jsnpmunverified

Fast HTML Parser (version 1.0.1) is an HTML parsing library designed for high performance and low-cost processing of large HTML files, generating a simplified DOM tree with basic element query support. It prioritizes speed, often outperforming alternatives like older versions of `htmlparser2` in its benchmarks. Key differentiators include its focus on raw parsing speed and a simplified DOM structure. However, this package is effectively abandoned, with its last release over a decade ago. It lacks active maintenance, modern features, and critical security updates. For current projects requiring a fast HTML parser, `node-html-parser` (a separate, actively maintained package that appears to be a spiritual successor or re-implementation) is the recommended alternative, offering similar performance goals with ongoing development and broader feature support.

serialization
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

This package is CommonJS-only; direct ES module imports are not supported.

const HTMLParser = require('fast-html-parser');

The `parse` function is a method on the `HTMLParser` object, not a top-level named export for CommonJS modules, and ESM imports are not supported by this version.

const { parse } = require('fast-html-parser'); // Destructures the 'parse' method from the main export

HTMLElement is an internal class representing parsed DOM elements; it is not exposed for direct import.

// HTMLElement instances are returned by parse and query methods, not directly imported.

Demonstrates parsing HTML, accessing the root element, querying elements by ID and class, and extracting text and raw HTML content.

const HTMLParser = require('fast-html-parser'); const htmlContent = ` <div id="container"> <h1>Welcome</h1> <p class="intro">Hello, <span class="name">World</span>!</p> <ul> <li>Item 1</li> <li>Item 2</li> </ul> </div>`; const root = HTMLParser.parse(htmlContent); console.log('Root structure:\n', root.firstChild.structure); const container = root.querySelector('#container'); if (container) { const welcomeHeading = container.querySelector('h1'); console.log('\nWelcome Heading Text:', welcomeHeading ? welcomeHeading.text : 'Not found'); const introParagraph = container.querySelector('.intro'); console.log('Intro Paragraph HTML:', introParagraph ? introParagraph.rawText : 'Not found'); const spanName = introParagraph ? introParagraph.querySelector('.name') : null; console.log('Span Name Text:', spanName ? spanName.text : 'Not found'); }
Debug
Known footguns
breakingThe `fast-html-parser` package (v1.0.1) is abandoned and has not been updated in over a decade. It is not recommended for new projects due to potential unpatched bugs, security vulnerabilities, and lack of modern feature support.
gotchaCSS selector support is limited to `tagName`, `#id`, and `.class` selectors only. Advanced CSS selectors (e.g., attribute selectors, pseudo-classes, direct child combinators) are not supported, which differs significantly from browser-native `querySelector` implementations.
gotchaThe `HTMLElement#querySelectorAll()` method does not behave like standard browser `querySelectorAll()`. It stops searching a sub-tree after finding the *first* match within that sub-tree, potentially returning an incomplete list of matches.
gotchaThe `lowerCaseTagName`, `script`, `style`, and `pre` parsing options are noted to 'hurt performance heavily/slightly'. Enabling these options will negate some of the library's primary performance benefits.
gotchaThis parser is designed for speed and may not correctly parse all malformed HTML. While it handles common errors like missing closing `<li>` or `<td>` tags, highly irregular or broken HTML might lead to incorrect DOM structures.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
4
ahrefsbot
4
script
1
Resources