@dooboostore/dom-parser 1.0.0 â 1.0.1
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/README.MD +47 -94
- package/package.json +3 -10
package/README.MD
CHANGED
|
@@ -4,21 +4,20 @@
|
|
|
4
4
|
[](https://github.com/dooboostore-develop/packages/actions/workflows/main.yaml)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
|
|
7
|
-
**Full Documentation:** [https://dooboostore-develop.github.io/
|
|
7
|
+
**Full Documentation:** [https://dooboostore-develop.github.io/@dooboostore/dom-parser](https://dooboostore-develop.github.io/@dooboostore/dom-parser)
|
|
8
8
|
|
|
9
|
-
A lightweight DOM parser for server-side HTML parsing and manipulation with full DOM API support.
|
|
9
|
+
A lightweight DOM parser for server-side HTML parsing and manipulation with full DOM API support.
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
13
|
## Features
|
|
14
14
|
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
- **ðŠķ Lightweight**: Zero dependencies with fast parsing performance
|
|
15
|
+
- **⥠Server-Side DOM**: Complete DOM implementation for Node.js environments
|
|
16
|
+
- **ð CSS Selector Support**: Full `querySelector` and `querySelectorAll` support
|
|
17
|
+
- **ðĶ Multi-Format**: Available as ESM, CJS, and UMD bundles
|
|
18
|
+
- **ðĄïļ TypeScript**: Full TypeScript definitions included
|
|
19
|
+
- **ðŠķ Zero Dependencies**: Lightweight with fast parsing performance
|
|
20
|
+
- **ðŊ HTML Templates**: Handles complex HTML templates and attributes
|
|
22
21
|
|
|
23
22
|
## Installation
|
|
24
23
|
|
|
@@ -80,40 +79,30 @@ global.window = window;
|
|
|
80
79
|
global.document = document;
|
|
81
80
|
```
|
|
82
81
|
|
|
83
|
-
###
|
|
82
|
+
### Template Processing
|
|
84
83
|
|
|
85
84
|
```typescript
|
|
86
85
|
import { DomParser } from '@dooboostore/dom-parser';
|
|
87
86
|
|
|
88
|
-
// Parse
|
|
87
|
+
// Parse HTML templates with complex attributes
|
|
89
88
|
const templateHtml = `
|
|
90
89
|
<div class="container">
|
|
91
|
-
<
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
<option value="1">Option 1</option>
|
|
96
|
-
</dr-select>
|
|
97
|
-
<dr-button
|
|
98
|
-
onClick="\${() => @this@.submit?.()}$"
|
|
99
|
-
disabled="@this@.loading ? 'true' : 'false'"
|
|
100
|
-
>
|
|
101
|
-
Submit
|
|
102
|
-
</dr-button>
|
|
90
|
+
<button onclick="handleClick(data)" disabled="false">
|
|
91
|
+
Click Me
|
|
92
|
+
</button>
|
|
93
|
+
<input value="user.name" placeholder="Enter name" />
|
|
103
94
|
</div>
|
|
104
95
|
`;
|
|
105
96
|
|
|
106
97
|
const parser = new DomParser(templateHtml);
|
|
107
98
|
const document = parser.document;
|
|
108
99
|
|
|
109
|
-
// Access
|
|
110
|
-
const
|
|
111
|
-
console.log(
|
|
112
|
-
// "${(data) => @this@?.handleSelectChange?.(data, #it#)}$"
|
|
100
|
+
// Access and modify elements
|
|
101
|
+
const button = document.querySelector('button');
|
|
102
|
+
console.log(button?.getAttribute('onclick')); // "handleClick(data)"
|
|
113
103
|
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
// "${() => @this@.submit?.()}$"
|
|
104
|
+
const input = document.querySelector('input');
|
|
105
|
+
input?.setAttribute('value', 'new value');
|
|
117
106
|
```
|
|
118
107
|
|
|
119
108
|
## API Reference
|
|
@@ -130,7 +119,13 @@ Creates a new DOM parser instance with the provided HTML string.
|
|
|
130
119
|
**Parameters:**
|
|
131
120
|
- `html`: HTML string to parse
|
|
132
121
|
- `options`: Optional configuration object
|
|
133
|
-
|
|
122
|
+
|
|
123
|
+
**DomParserOptions:**
|
|
124
|
+
```typescript
|
|
125
|
+
interface DomParserOptions {
|
|
126
|
+
href?: string; // Base URL for the document
|
|
127
|
+
}
|
|
128
|
+
```
|
|
134
129
|
|
|
135
130
|
#### Properties
|
|
136
131
|
|
|
@@ -163,25 +158,7 @@ const h1 = document.querySelector('h1');
|
|
|
163
158
|
console.log(h1?.textContent); // "Hello"
|
|
164
159
|
```
|
|
165
160
|
|
|
166
|
-
###
|
|
167
|
-
|
|
168
|
-
#### ð Advanced JavaScript Expression Support
|
|
169
|
-
|
|
170
|
-
Handles complex JavaScript expressions that would break other parsers:
|
|
171
|
-
|
|
172
|
-
```typescript
|
|
173
|
-
// â
Supported: Arrow functions with '>' operators
|
|
174
|
-
changeSelected="${(data) => data.value > 0 ? data : null}$"
|
|
175
|
-
|
|
176
|
-
// â
Supported: Ternary operators with nested expressions
|
|
177
|
-
condition="${user?.role === 'admin' ? 'show' : 'hide'}$"
|
|
178
|
-
|
|
179
|
-
// â
Supported: Framework-specific syntax
|
|
180
|
-
items="@this@.items"
|
|
181
|
-
handler="#item#.onClick"
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
#### ð Complete DOM API Support
|
|
161
|
+
### Supported DOM APIs
|
|
185
162
|
|
|
186
163
|
- `document.querySelector()` / `document.querySelectorAll()`
|
|
187
164
|
- `document.getElementById()` / `document.getElementsByClassName()`
|
|
@@ -193,29 +170,30 @@ handler="#item#.onClick"
|
|
|
193
170
|
|
|
194
171
|
## Use Cases
|
|
195
172
|
|
|
196
|
-
### ðŊ
|
|
197
|
-
|
|
198
|
-
Perfect for processing modern framework templates with complex JavaScript expressions:
|
|
173
|
+
### ðŊ HTML Processing & Manipulation
|
|
199
174
|
|
|
200
175
|
```typescript
|
|
201
176
|
import { DomParser } from '@dooboostore/dom-parser';
|
|
202
177
|
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
178
|
+
function processHtml(html: string) {
|
|
179
|
+
const parser = new DomParser(html);
|
|
180
|
+
const document = parser.document;
|
|
181
|
+
|
|
182
|
+
// Modify the DOM
|
|
183
|
+
const title = document.querySelector('title');
|
|
184
|
+
if (title) {
|
|
185
|
+
title.textContent = 'Processed Title';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Add meta tags
|
|
189
|
+
const head = document.querySelector('head');
|
|
190
|
+
const meta = document.createElement('meta');
|
|
191
|
+
meta.setAttribute('name', 'description');
|
|
192
|
+
meta.setAttribute('content', 'Processed content');
|
|
193
|
+
head?.appendChild(meta);
|
|
194
|
+
|
|
195
|
+
return document.documentElement.outerHTML;
|
|
196
|
+
}
|
|
219
197
|
```
|
|
220
198
|
|
|
221
199
|
### ð§ Server-Side Rendering (SSR)
|
|
@@ -243,37 +221,12 @@ global.document = parser.document;
|
|
|
243
221
|
global.window = parser.window;
|
|
244
222
|
```
|
|
245
223
|
|
|
246
|
-
### ð HTML Processing & Manipulation
|
|
247
224
|
|
|
248
|
-
```typescript
|
|
249
|
-
import { DomParser } from '@dooboostore/dom-parser';
|
|
250
|
-
|
|
251
|
-
function processHtml(html: string) {
|
|
252
|
-
const parser = new DomParser(html);
|
|
253
|
-
const document = parser.document;
|
|
254
|
-
|
|
255
|
-
// Modify the DOM
|
|
256
|
-
const title = document.querySelector('title');
|
|
257
|
-
if (title) {
|
|
258
|
-
title.textContent = 'Processed Title';
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// Add meta tags
|
|
262
|
-
const head = document.querySelector('head');
|
|
263
|
-
const meta = document.createElement('meta');
|
|
264
|
-
meta.setAttribute('name', 'description');
|
|
265
|
-
meta.setAttribute('content', 'Processed content');
|
|
266
|
-
head?.appendChild(meta);
|
|
267
|
-
|
|
268
|
-
return document.documentElement.outerHTML;
|
|
269
|
-
}
|
|
270
|
-
```
|
|
271
225
|
|
|
272
226
|
## Learn More
|
|
273
227
|
|
|
274
228
|
The detailed API documentation, including all supported DOM methods and usage examples, is available on our documentation website.
|
|
275
229
|
|
|
276
|
-
**[Explore the full @dooboostore/dom-parser documentation »](https://dooboostore-develop.github.io/packages/dom-parser)**
|
|
277
230
|
|
|
278
231
|
## License
|
|
279
232
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dooboostore/dom-parser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
]
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
|
-
"description": "A lightweight DOM parser for server-side HTML parsing and manipulation with
|
|
20
|
+
"description": "A lightweight DOM parser for server-side HTML parsing and manipulation with full DOM API support",
|
|
21
21
|
"keywords": [
|
|
22
22
|
"dom",
|
|
23
23
|
"parser",
|
|
@@ -31,14 +31,7 @@
|
|
|
31
31
|
"typescript",
|
|
32
32
|
"node",
|
|
33
33
|
"browser",
|
|
34
|
-
"
|
|
35
|
-
"framework",
|
|
36
|
-
"javascript-expressions",
|
|
37
|
-
"ssr",
|
|
38
|
-
"template-parsing",
|
|
39
|
-
"framework-templates",
|
|
40
|
-
"arrow-functions",
|
|
41
|
-
"complex-expressions"
|
|
34
|
+
"ssr"
|
|
42
35
|
],
|
|
43
36
|
"files": [
|
|
44
37
|
"dist",
|