parse-html-dom 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2026 Kris Walker (www.kriswalker.me).
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ HTML DOM
2
+ ========
3
+
4
+ Parse an HTML string into a virtual [Document Object Model](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model).
5
+
6
+ Zero dependencies. Runs unmodified on Node.js and Deno.
7
+
8
+ Supported Environments
9
+ ----------------------
10
+
11
+ | Env | Version |
12
+ |---------|------------|
13
+ | ECMA | >= ES2022 |
14
+ | Node.js | >= 18.3.0 |
15
+ | Deno | >= 1.42.0 |
16
+
17
+ Usage
18
+ -----
19
+
20
+ ```javascript
21
+ import { parseHTML } from 'html-dom';
22
+
23
+ const document = parseHTML('<p class="lead">Hello <b>world</b>');
24
+
25
+ document.body.querySelector('p.lead').textContent; // 'Hello world'
26
+ document.body.querySelector('p.lead').innerHTML; // 'Hello <b>world</b>'
27
+ document.parseErrors; // recorded recoveries
28
+ ```
29
+
30
+ `parseHTML()` never throws for malformed markup — it recovers and records what it did in `document.parseErrors` — but does throw a `TypeError` when given a non-string argument.
31
+
32
+ ### Supported API
33
+
34
+ **Entry point**
35
+
36
+ | Member | Description |
37
+ |---|---|
38
+ | `parseHTML(html)` | Parses an HTML string and returns a `Document` |
39
+
40
+ **`Document`**
41
+
42
+ | Member | Description |
43
+ |---|---|
44
+ | `documentElement` | The `<html>` element (always non-null) |
45
+ | `head` | The `<head>` element (always non-null) |
46
+ | `body` | The `<body>` element (always non-null) |
47
+ | `doctype` | `{name, publicId, systemId}`, or `null` |
48
+ | `parseErrors` | Recoveries recorded while parsing |
49
+
50
+ **`Element`**
51
+
52
+ | Member | Description |
53
+ |---|---|
54
+ | `tagName` | Uppercase local name for HTML elements; `rawName` for foreign elements |
55
+ | `localName` | Lowercase tag name |
56
+ | `rawName` | Tag name exactly as written in the source |
57
+ | `isForeign` | Whether the element is inside an `svg` or `math` subtree |
58
+ | `id` | The `id` attribute, or an empty string |
59
+ | `classList` | Read-only, iterable view of the `class` attribute's tokens, deduplicated |
60
+ | `attributes` | Frozen, iterable collection of `{name, value}` in source order |
61
+ | `getAttribute(name)` | Attribute value, or `null` |
62
+ | `hasAttribute(name)` | Whether the attribute is present |
63
+ | `getAttributeNames()` | Frozen Array of attribute names, in source order |
64
+ | `innerHTML` | Serialized child nodes |
65
+ | `outerHTML` | Serialized element, including itself |
66
+ | `querySelector(selector)` | First matching descendant, or `null` |
67
+ | `querySelectorAll(selector)` | Every matching descendant, in document order |
68
+ | `closest(selector)` | This element or its nearest matching ancestor, or `null` |
69
+ | `getElementsByTagName(name)` | Descendants with this local name, or all for `'*'` |
70
+ | `getElementsByClassName(names)` | Descendants carrying all the given class names |
71
+
72
+ **Members shared by nodes**
73
+
74
+ | Member | Available on |
75
+ |---|---|
76
+ | `nodeType` | `Text`, `Comment`, `Element`, `Document` |
77
+ | `nodeName` | `Text`, `Comment`, `Element`, `Document` |
78
+ | `parentNode` | `Text`, `Comment`, `Element`, `Document` |
79
+ | `parentElement` | `Text`, `Comment`, `Element`, `Document` |
80
+ | `textContent` | `Text`, `Comment`, `Element`, `Document` |
81
+ | `childNodes` | `Element`, `Document` |
82
+ | `children` | `Element`, `Document` |
83
+
84
+ **Exported classes**
85
+
86
+ | Export | Purpose |
87
+ |---|---|
88
+ | `Node`, `ParentNode`, `CharacterData`, `Text`, `Comment`, `Element`, `Document` | Available for `instanceof` checks |
89
+ | `SelectorSyntaxError` | Thrown for an invalid selector |
90
+
91
+ The tree is read-only: nothing returned by `parseHTML()` has a public setter, and no collection is a live `HTMLCollection`/`NodeList`. Node collections (`children`, `childNodes`, `querySelectorAll()` results, `getElementsBy*()` results, `getAttributeNames()`) are frozen Arrays. `classList` and `attributes` are frozen, iterable, array-like objects instead — indexed with `[0]` and a `length`, but not Arrays, so they carry their own helpers (`classList.contains()`, `classList.value`, `attributes.getNamedItem()`) and no Array methods. Spread them (`[ ...element.classList ]`) when you need one.
92
+
93
+ This is a **pragmatic subset** of WHATWG HTML tree construction and CSS Selectors, not a full implementation — see [`agents/plans/html-dom-v1.md`](./agents/plans/html-dom-v1.md) ("Conformance boundary") for exactly what is and is not implemented, and why.
94
+
95
+ Development
96
+ -----------
97
+
98
+ Run the linter over the project's JavaScript sources:
99
+
100
+ ```
101
+ npm run lint
102
+ ```
103
+
104
+ Run the unit test suite:
105
+
106
+ ```
107
+ node run-tests.js
108
+ ```
109
+
110
+ `run-tests.js` runs every `*.test.js` file under `test/unit-tests/`. Pass pathnames to run a subset, or `--skip <path>` (repeatable) to exclude one:
111
+
112
+ ```
113
+ node run-tests.js test/unit-tests/lib
114
+ node run-tests.js --skip test/unit-tests/lib/config-loader.test.js
115
+ ```
116
+
117
+ Run both, linter first:
118
+
119
+ ```
120
+ npm test
121
+ ```
122
+
123
+ Copyright and License
124
+ ---------------------
125
+ Copyright: (c) 2026 by Kris Walker (www.kriswalker.me)
126
+
127
+ Unless otherwise indicated, all source code is licensed under the MIT license. See LICENSE for details.