node-html-parser 6.1.11 → 6.1.12
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/CHANGELOG.md +8 -0
- package/README.md +10 -10
- package/dist/main.js +6 -5
- package/dist/nodes/html.d.ts +13 -11
- package/dist/nodes/html.js +6 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [6.1.12](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.11...v6.1.12) (2023-12-25)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* [#258](https://github.com/taoqf/node-fast-html-parser/issues/258) ([5a6a614](https://github.com/taoqf/node-fast-html-parser/commit/5a6a61489a62264221dde5e8f76a5d35b18d17bd))
|
|
11
|
+
* nullable return types of HTMLElement ([fe83c3e](https://github.com/taoqf/node-fast-html-parser/commit/fe83c3ee405b2fd973a9d46e4b2ff40f68a5471f))
|
|
12
|
+
|
|
5
13
|
### [6.1.11](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.10...v6.1.11) (2023-10-25)
|
|
6
14
|
|
|
7
15
|
|
package/README.md
CHANGED
|
@@ -202,7 +202,7 @@ Note: Full range of CSS3 selectors supported since v3.0.0.
|
|
|
202
202
|
|
|
203
203
|
### querySelector(selector)
|
|
204
204
|
|
|
205
|
-
Query CSS Selector to find matching node.
|
|
205
|
+
Query CSS Selector to find matching node. `null` if not found.
|
|
206
206
|
|
|
207
207
|
### getElementsByTagName(tagName)
|
|
208
208
|
|
|
@@ -212,7 +212,7 @@ Note: Use * for all elements.
|
|
|
212
212
|
|
|
213
213
|
### closest(selector)
|
|
214
214
|
|
|
215
|
-
Query closest element by css selector.
|
|
215
|
+
Query closest element by css selector. `null` if not found.
|
|
216
216
|
|
|
217
217
|
### appendChild(node)
|
|
218
218
|
|
|
@@ -236,7 +236,7 @@ Remove `key` attribute.
|
|
|
236
236
|
|
|
237
237
|
### getAttribute(key: string)
|
|
238
238
|
|
|
239
|
-
Get `key` attribute.
|
|
239
|
+
Get `key` attribute. `undefined` if not set.
|
|
240
240
|
|
|
241
241
|
### exchangeChild(oldNode: Node, newNode: Node)
|
|
242
242
|
|
|
@@ -292,7 +292,7 @@ Get class names.
|
|
|
292
292
|
|
|
293
293
|
Clone a node.
|
|
294
294
|
|
|
295
|
-
#### getElementById(id: string): HTMLElement
|
|
295
|
+
#### getElementById(id: string): HTMLElement | null
|
|
296
296
|
|
|
297
297
|
Get element by it's ID.
|
|
298
298
|
|
|
@@ -322,11 +322,11 @@ Get DOM structure.
|
|
|
322
322
|
|
|
323
323
|
### firstChild
|
|
324
324
|
|
|
325
|
-
Get first child node.
|
|
325
|
+
Get first child node. `undefined` if no child.
|
|
326
326
|
|
|
327
327
|
### lastChild
|
|
328
328
|
|
|
329
|
-
Get last child node.
|
|
329
|
+
Get last child node. `undefined` if no child
|
|
330
330
|
|
|
331
331
|
### innerHTML
|
|
332
332
|
|
|
@@ -338,19 +338,19 @@ Get outerHTML.
|
|
|
338
338
|
|
|
339
339
|
### nextSibling
|
|
340
340
|
|
|
341
|
-
Returns a reference to the next child node of the current element's parent.
|
|
341
|
+
Returns a reference to the next child node of the current element's parent. `null` if not found.
|
|
342
342
|
|
|
343
343
|
### nextElementSibling
|
|
344
344
|
|
|
345
|
-
Returns a reference to the next child element of the current element's parent.
|
|
345
|
+
Returns a reference to the next child element of the current element's parent. `null` if not found.
|
|
346
346
|
|
|
347
347
|
### previousSibling
|
|
348
348
|
|
|
349
|
-
Returns a reference to the previous child node of the current element's parent.
|
|
349
|
+
Returns a reference to the previous child node of the current element's parent. `null` if not found.
|
|
350
350
|
|
|
351
351
|
### previousElementSibling
|
|
352
352
|
|
|
353
|
-
Returns a reference to the previous child element of the current element's parent.
|
|
353
|
+
Returns a reference to the previous child element of the current element's parent. `null` if not found.
|
|
354
354
|
|
|
355
355
|
### textContent
|
|
356
356
|
|
package/dist/main.js
CHANGED
|
@@ -888,6 +888,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
888
888
|
/**
|
|
889
889
|
* find element by it's id
|
|
890
890
|
* @param {string} id the id of the element to select
|
|
891
|
+
* @returns {HTMLElement | null} the element with the given id or null if not found
|
|
891
892
|
*/
|
|
892
893
|
HTMLElement.prototype.getElementById = function (id) {
|
|
893
894
|
var stack = [];
|
|
@@ -925,6 +926,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
925
926
|
/**
|
|
926
927
|
* traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
|
|
927
928
|
* @param selector a DOMString containing a selector list
|
|
929
|
+
* @returns {HTMLElement | null} the element with the given id or null if not found
|
|
928
930
|
*/
|
|
929
931
|
HTMLElement.prototype.closest = function (selector) {
|
|
930
932
|
var mapChild = new Map();
|
|
@@ -986,7 +988,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
986
988
|
Object.defineProperty(HTMLElement.prototype, "firstChild", {
|
|
987
989
|
/**
|
|
988
990
|
* Get first child node
|
|
989
|
-
* @return {Node} first child node
|
|
991
|
+
* @return {Node | undefined} first child node; or undefined if none
|
|
990
992
|
*/
|
|
991
993
|
get: function () {
|
|
992
994
|
return this.childNodes[0];
|
|
@@ -997,7 +999,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
997
999
|
Object.defineProperty(HTMLElement.prototype, "lastChild", {
|
|
998
1000
|
/**
|
|
999
1001
|
* Get last child node
|
|
1000
|
-
* @return {Node} last child node
|
|
1002
|
+
* @return {Node | undefined} last child node; or undefined if none
|
|
1001
1003
|
*/
|
|
1002
1004
|
get: function () {
|
|
1003
1005
|
return (0, back_1.default)(this.childNodes);
|
|
@@ -1078,9 +1080,8 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1078
1080
|
this.rawAttrs = Object.keys(attrs)
|
|
1079
1081
|
.map(function (name) {
|
|
1080
1082
|
var val = _this.quoteAttribute(attrs[name]);
|
|
1081
|
-
if (val ===
|
|
1083
|
+
if (val === 'null' || val === '""')
|
|
1082
1084
|
return name;
|
|
1083
|
-
}
|
|
1084
1085
|
return "".concat(name, "=").concat(val);
|
|
1085
1086
|
})
|
|
1086
1087
|
.join(' ');
|
|
@@ -1095,7 +1096,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1095
1096
|
};
|
|
1096
1097
|
/**
|
|
1097
1098
|
* Get an attribute
|
|
1098
|
-
* @return {string} value of the attribute
|
|
1099
|
+
* @return {string | undefined} value of the attribute; or undefined if not exist
|
|
1099
1100
|
*/
|
|
1100
1101
|
HTMLElement.prototype.getAttribute = function (key) {
|
|
1101
1102
|
return this.attrs[key.toLowerCase()];
|
package/dist/nodes/html.d.ts
CHANGED
|
@@ -137,13 +137,15 @@ export default class HTMLElement extends Node {
|
|
|
137
137
|
/**
|
|
138
138
|
* find element by it's id
|
|
139
139
|
* @param {string} id the id of the element to select
|
|
140
|
+
* @returns {HTMLElement | null} the element with the given id or null if not found
|
|
140
141
|
*/
|
|
141
|
-
getElementById(id: string): HTMLElement;
|
|
142
|
+
getElementById(id: string): HTMLElement | null;
|
|
142
143
|
/**
|
|
143
144
|
* traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
|
|
144
145
|
* @param selector a DOMString containing a selector list
|
|
146
|
+
* @returns {HTMLElement | null} the element with the given id or null if not found
|
|
145
147
|
*/
|
|
146
|
-
closest(selector: string): HTMLElement;
|
|
148
|
+
closest(selector: string): HTMLElement | null;
|
|
147
149
|
/**
|
|
148
150
|
* Append a child node to childNodes
|
|
149
151
|
* @param {Node} node node to append
|
|
@@ -152,14 +154,14 @@ export default class HTMLElement extends Node {
|
|
|
152
154
|
appendChild<T extends Node = Node>(node: T): T;
|
|
153
155
|
/**
|
|
154
156
|
* Get first child node
|
|
155
|
-
* @return {Node} first child node
|
|
157
|
+
* @return {Node | undefined} first child node; or undefined if none
|
|
156
158
|
*/
|
|
157
|
-
get firstChild(): Node;
|
|
159
|
+
get firstChild(): Node | undefined;
|
|
158
160
|
/**
|
|
159
161
|
* Get last child node
|
|
160
|
-
* @return {Node} last child node
|
|
162
|
+
* @return {Node | undefined} last child node; or undefined if none
|
|
161
163
|
*/
|
|
162
|
-
get lastChild(): Node;
|
|
164
|
+
get lastChild(): Node | undefined;
|
|
163
165
|
/**
|
|
164
166
|
* Get attributes
|
|
165
167
|
* @access private
|
|
@@ -176,7 +178,7 @@ export default class HTMLElement extends Node {
|
|
|
176
178
|
hasAttribute(key: string): boolean;
|
|
177
179
|
/**
|
|
178
180
|
* Get an attribute
|
|
179
|
-
* @return {string} value of the attribute
|
|
181
|
+
* @return {string | undefined} value of the attribute; or undefined if not exist
|
|
180
182
|
*/
|
|
181
183
|
getAttribute(key: string): string | undefined;
|
|
182
184
|
/**
|
|
@@ -191,10 +193,10 @@ export default class HTMLElement extends Node {
|
|
|
191
193
|
*/
|
|
192
194
|
setAttributes(attributes: Attributes): this;
|
|
193
195
|
insertAdjacentHTML(where: InsertPosition, html: string): this;
|
|
194
|
-
get nextSibling(): Node;
|
|
195
|
-
get nextElementSibling(): HTMLElement;
|
|
196
|
-
get previousSibling(): Node;
|
|
197
|
-
get previousElementSibling(): HTMLElement;
|
|
196
|
+
get nextSibling(): Node | null;
|
|
197
|
+
get nextElementSibling(): HTMLElement | null;
|
|
198
|
+
get previousSibling(): Node | null;
|
|
199
|
+
get previousElementSibling(): HTMLElement | null;
|
|
198
200
|
get classNames(): string;
|
|
199
201
|
/**
|
|
200
202
|
* Clone this Node
|
package/dist/nodes/html.js
CHANGED
|
@@ -554,6 +554,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
554
554
|
/**
|
|
555
555
|
* find element by it's id
|
|
556
556
|
* @param {string} id the id of the element to select
|
|
557
|
+
* @returns {HTMLElement | null} the element with the given id or null if not found
|
|
557
558
|
*/
|
|
558
559
|
HTMLElement.prototype.getElementById = function (id) {
|
|
559
560
|
var stack = [];
|
|
@@ -591,6 +592,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
591
592
|
/**
|
|
592
593
|
* traverses the Element and its parents (heading toward the document root) until it finds a node that matches the provided selector string. Will return itself or the matching ancestor. If no such element exists, it returns null.
|
|
593
594
|
* @param selector a DOMString containing a selector list
|
|
595
|
+
* @returns {HTMLElement | null} the element with the given id or null if not found
|
|
594
596
|
*/
|
|
595
597
|
HTMLElement.prototype.closest = function (selector) {
|
|
596
598
|
var mapChild = new Map();
|
|
@@ -652,7 +654,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
652
654
|
Object.defineProperty(HTMLElement.prototype, "firstChild", {
|
|
653
655
|
/**
|
|
654
656
|
* Get first child node
|
|
655
|
-
* @return {Node} first child node
|
|
657
|
+
* @return {Node | undefined} first child node; or undefined if none
|
|
656
658
|
*/
|
|
657
659
|
get: function () {
|
|
658
660
|
return this.childNodes[0];
|
|
@@ -663,7 +665,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
663
665
|
Object.defineProperty(HTMLElement.prototype, "lastChild", {
|
|
664
666
|
/**
|
|
665
667
|
* Get last child node
|
|
666
|
-
* @return {Node} last child node
|
|
668
|
+
* @return {Node | undefined} last child node; or undefined if none
|
|
667
669
|
*/
|
|
668
670
|
get: function () {
|
|
669
671
|
return (0, back_1.default)(this.childNodes);
|
|
@@ -744,9 +746,8 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
744
746
|
this.rawAttrs = Object.keys(attrs)
|
|
745
747
|
.map(function (name) {
|
|
746
748
|
var val = _this.quoteAttribute(attrs[name]);
|
|
747
|
-
if (val ===
|
|
749
|
+
if (val === 'null' || val === '""')
|
|
748
750
|
return name;
|
|
749
|
-
}
|
|
750
751
|
return "".concat(name, "=").concat(val);
|
|
751
752
|
})
|
|
752
753
|
.join(' ');
|
|
@@ -761,7 +762,7 @@ var HTMLElement = /** @class */ (function (_super) {
|
|
|
761
762
|
};
|
|
762
763
|
/**
|
|
763
764
|
* Get an attribute
|
|
764
|
-
* @return {string} value of the attribute
|
|
765
|
+
* @return {string | undefined} value of the attribute; or undefined if not exist
|
|
765
766
|
*/
|
|
766
767
|
HTMLElement.prototype.getAttribute = function (key) {
|
|
767
768
|
return this.attrs[key.toLowerCase()];
|
package/package.json
CHANGED