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.

npm install fast-html-parser
INSTALL
IMPORT
SIG · FAST-HTML-PARSER
F
fast-html-parser
serializationjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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.

HTMLParser
const HTMLParser = require('fast-html-parser');
import HTMLParser from 'fast-html-parser';
This package is CommonJS-only; direct ES module imports are not supported.
parse
const { parse } = require('fast-html-parser'); // Destructures the 'parse' method from the main export
import { parse } from '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.
HTMLElement
// HTMLElement instances are returned by parse and query methods, not directly imported.
HTMLElement is an internal class representing parsed DOM elements; it is not exposed for direct import.

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 issues
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.
fix
Migrate to an actively maintained alternative like `node-html-parser` for ongoing support and security updates.
affects: >=1.0.0
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.
fix
Manually traverse the DOM tree for more complex selection criteria or use a different parser with full CSS selector support.
affects: >=1.0.0
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.
fix
Be aware of this non-standard behavior. If you need all matches, you might need to implement a recursive search or use a different library.
affects: >=1.0.0
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.
fix
Only enable these options if absolutely necessary for your parsing logic and be aware of the performance trade-offs.
affects: >=1.0.0
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.
fix
Ensure HTML input is as well-formed as possible, or use a more forgiving, spec-compliant parser if robust error handling for malformed HTML is critical.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: HTMLParser.parse is not a function
Attempting to use a named import (e.g., `import { parse } from 'fast-html-parser';`) in an ESM context when the package is CommonJS-only and exports the `parse` function as a method of its default export.
fix
Use CommonJS `require` syntax: `const HTMLParser = require('fast-html-parser'); const root = HTMLParser.parse(...)`.
ReferenceError: require is not defined
Trying to use CommonJS `require()` in an ES module (ESM) environment (e.g., a file with `"type": "module"` in `package.json` or `.mjs` extension) without proper CommonJS interoperability.
fix
This package is CommonJS-only. For modern ESM environments, consider using `node-html-parser` which offers ESM support, or dynamically import this package using `import('fast-html-parser').then(mod => mod.parse(...))` (though not officially supported/tested for this old package).
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
fast-html-parser — npm install fast-html-parser · libregistry