Registry / web-framework / es-html-parser

es-html-parser

JSON →
library0.3.1jsnpmunverified

es-html-parser is a JavaScript/TypeScript library designed for parsing HTML content into an Abstract Syntax Tree (AST) that closely adheres to the ESTree specification. It also provides access to the raw token stream generated during parsing. Currently at version 0.3.1, this project originated as a fork of `hyntax` and is actively developed to align its AST output with ESTree standards, making it suitable for tooling that processes HTML with familiar JavaScript AST traversal patterns. While the release cadence is not explicitly defined, its 0.x version implies ongoing development and potential for breaking changes between minor versions. It differentiates itself by its ESTree-like AST structure, which can be advantageous for developers already familiar with JavaScript AST manipulation.

npm install es-html-parser
INSTALL
IMPORT
SIG · ES-HTML-PARSER
E
es-html-parser
web-frameworkjavascriptv0.3.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

parse
✓ import { parse } from 'es-html-parser';
✗ const { parse } = require('es-html-parser');
The library primarily uses named exports and is designed for ESM. CommonJS 'require' syntax will not work by default.
ParseResult
✓ import type { ParseResult } from 'es-html-parser';
✗ import { ParseResult } from 'es-html-parser';
When importing only types, use 'import type' for better tree-shaking and to prevent runtime issues in environments that don't strip type imports.
TokenTypes
✓ import { TokenTypes } from 'es-html-parser';
✗ import * as TokenTypes from 'es-html-parser/TokenTypes';
Constants like TokenTypes are directly exported from the main package entry point, not from a subpath.

This quickstart demonstrates parsing a basic HTML string, including script tags, and accessing the resulting AST and tokens. It explicitly uses the `rawContentTags` option for common embedded content.

import { parse } from 'es-html-parser'; const htmlInput = ` <!DOCTYPE html> <html> <head> <title>Hello Parser</title> </head> <body> <button type="button">Click me</button> <script> console.log('Parser demo'); </script> </body> </html> `; const { ast, tokens } = parse(htmlInput, { rawContentTags: ['script', 'style'] // Treat script/style content as raw text }); console.log('Parsed AST (root node):', JSON.stringify(ast, null, 2)); console.log('Generated Tokens (first 5):', tokens.slice(0, 5)); // Further processing of AST or tokens can be done here
Debug
Known issues
gotchaThe package is currently in a pre-1.0.0 state (version 0.3.1). This means the API might not be stable, and breaking changes can occur in minor or even patch releases without strictly adhering to semantic versioning.
fix
Always pin to exact versions (e.g., `"es-html-parser": "0.3.1"`) and review release notes carefully when upgrading to newer `0.x` versions.
affects: <1.0.0
gotchaThe `rawContentTags` option is crucial for correct parsing of tags like `<script>` or `<style>`, or custom elements whose inner content should not be parsed as HTML. Forgetting to specify them can lead to incorrect AST generation for their children.
fix
Always provide an array of tag names to `rawContentTags` in the options if their content should be treated as raw text (e.g., `{ rawContentTags: ['script', 'style', 'custom-raw-tag'] }`).
affects: >=0.1.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Attempting to use `import` syntax in a CommonJS (CJS) environment (e.g., a Node.js script without `"type": "module"` in package.json, or an older Node.js version).
fix
Ensure your project is configured for ESM by adding `"type": "module"` to your `package.json` or by using a bundler (like Webpack, Rollup, Parcel, or esbuild) that transpiles ESM to CJS if targeting older environments.
TypeError: (0 , es_html_parser__WEBPACK_IMPORTED_MODULE_0__.parse) is not a function
This error typically occurs in bundled environments when a named export (`parse`) is incorrectly treated as a default export or when destructuring fails due to a module resolution issue.
fix
Verify that `import { parse } from 'es-html-parser';` is correctly used and that your bundler configuration is compatible with ESM modules. Ensure the package is installed correctly and not corrupted.
Upgrade
Version history
0.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

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