@ismail-elkorchi/html-parser
v0.1.1
Published
Deterministic HTML parser for Node, Deno, Bun, and modern browsers.
Readme
@ismail-elkorchi/html-parser
Deterministic HTML parsing for automation workflows that need stable output across Node, Deno, Bun, and modern browsers.
No runtime dependencies: this package ships with zero runtime dependencies.
When To Use
- You need deterministic parse and serialize output.
- You need explicit resource budgets for untrusted input.
- You need consistent behavior across Node, Deno, Bun, and browser smoke paths.
When Not To Use
- You need HTML sanitization.
- You need a full browser engine with script execution.
- You need DOM mutation semantics beyond deterministic parse utilities.
Install
npm install @ismail-elkorchi/html-parserdeno add jsr:@ismail-elkorchi/html-parserImport
import { parse } from "@ismail-elkorchi/html-parser";import { parse } from "jsr:@ismail-elkorchi/html-parser";Copy/Paste Examples
Example 1: Parse a document
import { parse } from "@ismail-elkorchi/html-parser";
const tree = parse("<main><h1>Hello</h1></main>");
console.log(tree.kind);Example 2: Parse streaming bytes
import { parseStream } from "@ismail-elkorchi/html-parser";
const stream = new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode("<p>streamed</p>"));
controller.close();
}
});
const tree = await parseStream(stream, { budgets: { maxInputBytes: 4096, maxBufferedBytes: 512 } });
console.log(tree.kind);Example 3: Extract visible text
import { parse, visibleText } from "@ismail-elkorchi/html-parser";
const tree = parse("<article><h1>Title</h1><p>Hello world.</p></article>");
console.log(visibleText(tree).trim());Example 4: Compute and apply a patch plan
import { applyPatchPlan, computePatch } from "@ismail-elkorchi/html-parser";
const plan = computePatch("<p>Draft</p>", []);
const patched = applyPatchPlan("<p>Draft</p>", plan);
console.log(patched);Run packaged examples:
npm run examples:runCompatibility
Runtime compatibility matrix:
| Runtime | Status | | --- | --- | | Node.js | Supported | | Deno | Supported | | Bun | Supported | | Browser (evergreen) | Supported |
Security and Safety Notes
Parsing is not sanitization. For untrusted input:
- set strict budgets,
- handle
BudgetExceededErrorexplicitly, - sanitize separately before rendering.
