node-html-parser 6.1.11 → 6.1.13
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 +15 -0
- package/README.md +10 -10
- package/dist/main.js +11 -7
- package/dist/nodes/comment.d.ts +2 -1
- package/dist/nodes/comment.js +4 -2
- package/dist/nodes/html.d.ts +13 -11
- package/dist/nodes/html.js +6 -5
- package/dist/nodes/node.d.ts +1 -0
- package/dist/nodes/text.d.ts +1 -0
- package/dist/nodes/text.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,21 @@
|
|
|
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.13](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.12...v6.1.13) (2024-03-29)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* add rawTagName [#269](https://github.com/taoqf/node-fast-html-parser/issues/269) [#270](https://github.com/taoqf/node-fast-html-parser/issues/270) ([9ac642d](https://github.com/taoqf/node-fast-html-parser/commit/9ac642d7b6a97c84fd4471b8eaa0bd9debf5e325))
|
|
11
|
+
|
|
12
|
+
### [6.1.12](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.11...v6.1.12) (2023-12-25)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* [#258](https://github.com/taoqf/node-fast-html-parser/issues/258) ([5a6a614](https://github.com/taoqf/node-fast-html-parser/commit/5a6a61489a62264221dde5e8f76a5d35b18d17bd))
|
|
18
|
+
* nullable return types of HTMLElement ([fe83c3e](https://github.com/taoqf/node-fast-html-parser/commit/fe83c3ee405b2fd973a9d46e4b2ff40f68a5471f))
|
|
19
|
+
|
|
5
20
|
### [6.1.11](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.10...v6.1.11) (2023-10-25)
|
|
6
21
|
|
|
7
22
|
|
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
|
@@ -263,6 +263,7 @@ define("nodes/text", ["require", "exports", "he", "nodes/node", "nodes/type"], f
|
|
|
263
263
|
* @type {Number}
|
|
264
264
|
*/
|
|
265
265
|
_this.nodeType = type_2.default.TEXT_NODE;
|
|
266
|
+
_this.rawTagName = '';
|
|
266
267
|
_this._rawText = rawText;
|
|
267
268
|
return _this;
|
|
268
269
|
}
|
|
@@ -888,6 +889,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
888
889
|
/**
|
|
889
890
|
* find element by it's id
|
|
890
891
|
* @param {string} id the id of the element to select
|
|
892
|
+
* @returns {HTMLElement | null} the element with the given id or null if not found
|
|
891
893
|
*/
|
|
892
894
|
HTMLElement.prototype.getElementById = function (id) {
|
|
893
895
|
var stack = [];
|
|
@@ -925,6 +927,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
925
927
|
/**
|
|
926
928
|
* 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
929
|
* @param selector a DOMString containing a selector list
|
|
930
|
+
* @returns {HTMLElement | null} the element with the given id or null if not found
|
|
928
931
|
*/
|
|
929
932
|
HTMLElement.prototype.closest = function (selector) {
|
|
930
933
|
var mapChild = new Map();
|
|
@@ -986,7 +989,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
986
989
|
Object.defineProperty(HTMLElement.prototype, "firstChild", {
|
|
987
990
|
/**
|
|
988
991
|
* Get first child node
|
|
989
|
-
* @return {Node} first child node
|
|
992
|
+
* @return {Node | undefined} first child node; or undefined if none
|
|
990
993
|
*/
|
|
991
994
|
get: function () {
|
|
992
995
|
return this.childNodes[0];
|
|
@@ -997,7 +1000,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
997
1000
|
Object.defineProperty(HTMLElement.prototype, "lastChild", {
|
|
998
1001
|
/**
|
|
999
1002
|
* Get last child node
|
|
1000
|
-
* @return {Node} last child node
|
|
1003
|
+
* @return {Node | undefined} last child node; or undefined if none
|
|
1001
1004
|
*/
|
|
1002
1005
|
get: function () {
|
|
1003
1006
|
return (0, back_1.default)(this.childNodes);
|
|
@@ -1078,9 +1081,8 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1078
1081
|
this.rawAttrs = Object.keys(attrs)
|
|
1079
1082
|
.map(function (name) {
|
|
1080
1083
|
var val = _this.quoteAttribute(attrs[name]);
|
|
1081
|
-
if (val ===
|
|
1084
|
+
if (val === 'null' || val === '""')
|
|
1082
1085
|
return name;
|
|
1083
|
-
}
|
|
1084
1086
|
return "".concat(name, "=").concat(val);
|
|
1085
1087
|
})
|
|
1086
1088
|
.join(' ');
|
|
@@ -1095,7 +1097,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
|
|
|
1095
1097
|
};
|
|
1096
1098
|
/**
|
|
1097
1099
|
* Get an attribute
|
|
1098
|
-
* @return {string} value of the attribute
|
|
1100
|
+
* @return {string | undefined} value of the attribute; or undefined if not exist
|
|
1099
1101
|
*/
|
|
1100
1102
|
HTMLElement.prototype.getAttribute = function (key) {
|
|
1101
1103
|
return this.attrs[key.toLowerCase()];
|
|
@@ -1557,10 +1559,12 @@ define("nodes/comment", ["require", "exports", "nodes/node", "nodes/type"], func
|
|
|
1557
1559
|
type_4 = __importDefault(type_4);
|
|
1558
1560
|
var CommentNode = /** @class */ (function (_super) {
|
|
1559
1561
|
__extends(CommentNode, _super);
|
|
1560
|
-
function CommentNode(rawText, parentNode, range) {
|
|
1562
|
+
function CommentNode(rawText, parentNode, range, rawTagName) {
|
|
1561
1563
|
if (parentNode === void 0) { parentNode = null; }
|
|
1564
|
+
if (rawTagName === void 0) { rawTagName = '!--'; }
|
|
1562
1565
|
var _this = _super.call(this, parentNode, range) || this;
|
|
1563
1566
|
_this.rawText = rawText;
|
|
1567
|
+
_this.rawTagName = rawTagName;
|
|
1564
1568
|
/**
|
|
1565
1569
|
* Node Type declaration.
|
|
1566
1570
|
* @type {Number}
|
|
@@ -1569,7 +1573,7 @@ define("nodes/comment", ["require", "exports", "nodes/node", "nodes/type"], func
|
|
|
1569
1573
|
return _this;
|
|
1570
1574
|
}
|
|
1571
1575
|
CommentNode.prototype.clone = function () {
|
|
1572
|
-
return new CommentNode(this.rawText, null);
|
|
1576
|
+
return new CommentNode(this.rawText, null, undefined, this.rawTagName);
|
|
1573
1577
|
};
|
|
1574
1578
|
Object.defineProperty(CommentNode.prototype, "text", {
|
|
1575
1579
|
/**
|
package/dist/nodes/comment.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ import Node from './node';
|
|
|
3
3
|
import NodeType from './type';
|
|
4
4
|
export default class CommentNode extends Node {
|
|
5
5
|
rawText: string;
|
|
6
|
+
rawTagName: string;
|
|
6
7
|
clone(): CommentNode;
|
|
7
|
-
constructor(rawText: string, parentNode?: HTMLElement, range?: [number, number]);
|
|
8
|
+
constructor(rawText: string, parentNode?: HTMLElement, range?: [number, number], rawTagName?: string);
|
|
8
9
|
/**
|
|
9
10
|
* Node Type declaration.
|
|
10
11
|
* @type {Number}
|
package/dist/nodes/comment.js
CHANGED
|
@@ -22,10 +22,12 @@ var node_1 = __importDefault(require("./node"));
|
|
|
22
22
|
var type_1 = __importDefault(require("./type"));
|
|
23
23
|
var CommentNode = /** @class */ (function (_super) {
|
|
24
24
|
__extends(CommentNode, _super);
|
|
25
|
-
function CommentNode(rawText, parentNode, range) {
|
|
25
|
+
function CommentNode(rawText, parentNode, range, rawTagName) {
|
|
26
26
|
if (parentNode === void 0) { parentNode = null; }
|
|
27
|
+
if (rawTagName === void 0) { rawTagName = '!--'; }
|
|
27
28
|
var _this = _super.call(this, parentNode, range) || this;
|
|
28
29
|
_this.rawText = rawText;
|
|
30
|
+
_this.rawTagName = rawTagName;
|
|
29
31
|
/**
|
|
30
32
|
* Node Type declaration.
|
|
31
33
|
* @type {Number}
|
|
@@ -34,7 +36,7 @@ var CommentNode = /** @class */ (function (_super) {
|
|
|
34
36
|
return _this;
|
|
35
37
|
}
|
|
36
38
|
CommentNode.prototype.clone = function () {
|
|
37
|
-
return new CommentNode(this.rawText, null);
|
|
39
|
+
return new CommentNode(this.rawText, null, undefined, this.rawTagName);
|
|
38
40
|
};
|
|
39
41
|
Object.defineProperty(CommentNode.prototype, "text", {
|
|
40
42
|
/**
|
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/dist/nodes/node.d.ts
CHANGED
package/dist/nodes/text.d.ts
CHANGED
package/dist/nodes/text.js
CHANGED
package/package.json
CHANGED