node-html-parser 6.1.10 → 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 CHANGED
@@ -2,6 +2,22 @@
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
+
13
+ ### [6.1.11](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.10...v6.1.11) (2023-10-25)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * [#254](https://github.com/taoqf/node-fast-html-parser/issues/254) ([8e4e9e0](https://github.com/taoqf/node-fast-html-parser/commit/8e4e9e0a13796ed9a39ebb930b0ee5e55b578b82))
19
+ * Fixed typo in JSDoc for HTMLElement `structure` method ([3a52ee9](https://github.com/taoqf/node-fast-html-parser/commit/3a52ee97463d8ab1f35ef7c0f08d3696bc38e5c4))
20
+
5
21
  ### [6.1.10](https://github.com/taoqf/node-fast-html-parser/compare/v6.1.9...v6.1.10) (2023-09-15)
6
22
 
7
23
 
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
@@ -592,7 +592,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
592
592
  */
593
593
  get: function () {
594
594
  // https://github.com/taoqf/node-html-parser/issues/249
595
- if (/br/i.test(this.rawTagName)) {
595
+ if (/^br$/i.test(this.rawTagName)) {
596
596
  return '\n';
597
597
  }
598
598
  return this.childNodes.reduce(function (pre, cur) {
@@ -772,7 +772,7 @@ define("nodes/html", ["require", "exports", "css-select", "he", "back", "matcher
772
772
  Object.defineProperty(HTMLElement.prototype, "structure", {
773
773
  /**
774
774
  * Get DOM structure
775
- * @return {string} strucutre
775
+ * @return {string} structure
776
776
  */
777
777
  get: function () {
778
778
  var res = [];
@@ -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 === undefined || val === 'null') {
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()];
@@ -109,7 +109,7 @@ export default class HTMLElement extends Node {
109
109
  trimRight(pattern: RegExp): this;
110
110
  /**
111
111
  * Get DOM structure
112
- * @return {string} strucutre
112
+ * @return {string} structure
113
113
  */
114
114
  get structure(): string;
115
115
  /**
@@ -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
@@ -258,7 +258,7 @@ var HTMLElement = /** @class */ (function (_super) {
258
258
  */
259
259
  get: function () {
260
260
  // https://github.com/taoqf/node-html-parser/issues/249
261
- if (/br/i.test(this.rawTagName)) {
261
+ if (/^br$/i.test(this.rawTagName)) {
262
262
  return '\n';
263
263
  }
264
264
  return this.childNodes.reduce(function (pre, cur) {
@@ -438,7 +438,7 @@ var HTMLElement = /** @class */ (function (_super) {
438
438
  Object.defineProperty(HTMLElement.prototype, "structure", {
439
439
  /**
440
440
  * Get DOM structure
441
- * @return {string} strucutre
441
+ * @return {string} structure
442
442
  */
443
443
  get: function () {
444
444
  var res = [];
@@ -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 === undefined || val === 'null') {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-html-parser",
3
- "version": "6.1.10",
3
+ "version": "6.1.12",
4
4
  "description": "A very fast HTML parser, generating a simplified DOM, with basic element query support.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,9 +22,9 @@
22
22
  "reset": "yarn run clean:global && yarn install && yarn build",
23
23
  "--------------- ": "",
24
24
  "test:target": "mocha --recursive \"./test/tests\"",
25
- "test:ci": "cross-env TEST_TARGET=dist yarn run test:target",
25
+ "test:ci": "cd test && yarn install && cd .. && cross-env TEST_TARGET=dist yarn run test:target",
26
26
  "posttest": "yarn run benchmark",
27
- "prepare": "cd test && yarn install",
27
+ "prepare": "npm run build",
28
28
  "release": "standard-version && git push --follow-tags origin main"
29
29
  },
30
30
  "keywords": [