Registry / web-framework / h2x-core

h2x-core

JSON →
library1.1.1jsnpmunverified

h2x-core is the core compiler for h2x, an HTML-to-JSX transformer. It converts HTML strings into a JavaScript AST (JSX) via JSDOM, using a plugin system for extensibility. Version 1.1.1 is current, with releases every few months. Key differentiators: leverages JSDOM for robust parsing, supports state, and has a plugin architecture. It handles special SVG attributes and style attributes. Alternatives are typically SVGR or manual transformation.

npm install h2x-core
INSTALL
IMPORT
SIG · H2X-CORE
H
h2x-core
web-frameworkjavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

compile
import { compile } from 'h2x-core'
const { compile } = require('h2x-core')
Use ESM import. CommonJS require also works but is less common.
transform
import { transform } from 'h2x-core'
import { transpile } from 'h2x-core'
The correct function name is 'transform', not 'transpile'.
parse
import { parse } from 'h2x-core'
import { parseHtml } from 'h2x-core'
Direct 'parse' export. No submodule import.

Demonstrates how to compile HTML to JSX using a plugin.

import { compile } from 'h2x-core'; import pluginJsx from 'h2x-plugin-jsx'; const html = `<div class="foo">Hello</div>`; const jsx = compile(html, { plugins: [pluginJsx], output: 'string' }); console.log(jsx); // <div className="foo">Hello</div>
Debug
Known issues
breakingv1.0.0: AST generation changed from a custom tree to JSDOM-based tree. You must use fromHtmlAttribute and fromHtmlElement for node replacement. originalNode property available.
fix
Update code to use new API: node.originalNode, fromHtmlAttribute, fromHtmlElement.
affects: >=1.0.0 <1.2.0
gotchaThe package does not include any default plugin; you must provide plugins (e.g., h2x-plugin-jsx) for meaningful output.
fix
Install and pass plugins: e.g., `compile(html, { plugins: [require('h2x-plugin-jsx')] })`.
affects: >=1.0.0
gotchaJSDOM v12+ required; older JSDOM versions may cause parse errors.
fix
Ensure jsdom >=12 is installed.
affects: >=1.1.0
deprecatedIn v0.x, the API exported a different set of functions. Direct migration may break.
fix
Update to v1.x API (compile, transform, parse).
affects: <1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'h2x-core'
h2x-core not installed or not imported correctly.
fix
Run `npm install h2x-core` and ensure import path is correct: `import { compile } from 'h2x-core'`.
TypeError: compile is not a function
Mis-imported default export vs named export.
fix
Use named import: `import { compile } from 'h2x-core'`.
Error: JSDOM is not defined
jsdom peer dependency not installed.
fix
Run `npm install jsdom@12`.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
h2x-typesrequiredprovides node type definitions
jsdomrequiredused to parse HTML into a DOM tree for AST generation
Agent activity
8 hits · last 30 days
node
8
Resources
h2x-core — npm install h2x-core · libregistry