@qezor/livedomparser
v1.0.1
Published
Sync-first and live-stream capable DOMParser polyfill with low-memory HTML tokenization.
Downloads
253
Maintainers
Readme
@qezor/livedomparser
@qezor/livedomparser is a DOMParser-style package with two honest modes:
- sync ordinary parsing for normal
parseFromString(...) - live async parsing for streamed sources where memory discipline matters
Install
npm install @qezor/livedomparserMain API
new LiveDOMParser(options)parseFromString(html, mimeType?)parseFromSource(source, mimeType?, options?)parseAsync(source, mimeType?, options?)installDOMParserPolyfill(options?)createHtmlTokenIterator(source, options?)
Ordinary Sync Use
const { LiveDOMParser } = require("@qezor/livedomparser")
const parser = new LiveDOMParser()
const document = parser.parseFromString("<div id='app'><h1>Hello</h1></div>", "text/html")
console.log(document.getElementById("app").querySelector("h1").textContent)Live Async Use
const parser = new LiveDOMParser({
asyncMode: "live",
})
const document = await parser.parseFromSource([
"<main><p>Hel",
"lo</p></main>",
], "text/html")Polyfill
const { installDOMParserPolyfill } = require("@qezor/livedomparser")
installDOMParserPolyfill({
target: globalThis,
})If DOMParser already exists, it is left alone unless you pass force: true.
Notes
- the sync path is meant to feel normal in ordinary environments
- the async path uses streaming tokenization instead of forcing whole-document buffering
- selector support is intentionally practical rather than browser-complete:
- tag
#id.class[attr][attr=value][attr^=value],[attr$=value],[attr*=value],[attr~=value],[attr|=value]- descendant, child, adjacent sibling, and general sibling combinators
:not(...):first-child:last-child:only-child:empty:nth-child(...)
- XML mode now keeps tag and attribute casing precise instead of forcing HTML-style lowercasing
Versioning
@qezor/livedomparser follows practical semver:
- patch: safe parser, tokenizer, selector, or XML precision fixes
- minor: additive DOM, selector, or token features that preserve existing behavior
- major: breaking changes to token shapes, node contracts, selector semantics, or parser entrypoints
Release notes live in CHANGELOG.md.
