node-html-parser 1.4.7 → 1.4.8

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 CHANGED
@@ -62,7 +62,7 @@ var HTMLParser = require('node-html-parser');
62
62
  var root = HTMLParser.parse('<ul id="list"><li>Hello World</li></ul>');
63
63
  ```
64
64
 
65
- ## global Methods
65
+ ## Global Methods
66
66
 
67
67
  ### parse(data[, options])
68
68
 
@@ -142,7 +142,7 @@ Same as [outerHTML](#htmlelementouterhtml)
142
142
 
143
143
  Set content. **Notice**: Do not set content of the **root** node.
144
144
 
145
- ### HTMLElement#remove();
145
+ ### HTMLElement#remove()
146
146
 
147
147
  Remove current element.
148
148
 
@@ -181,3 +181,11 @@ Get innerHTML.
181
181
  ### HTMLElement#outerHTML
182
182
 
183
183
  Get outerHTML.
184
+
185
+ ### HTMLElement#nextSibling
186
+
187
+ Returns a reference to the next child node of the current element's parent.
188
+
189
+ ### HTMLElement#nextElementSibling
190
+
191
+ Returns a reference to the next child element of the current element's parent.
@@ -76,7 +76,7 @@ export default class HTMLElement extends Node {
76
76
  */
77
77
  remove() {
78
78
  if (this.parentNode) {
79
- const children = this.childNodes;
79
+ const children = this.parentNode.childNodes;
80
80
  this.parentNode.childNodes = children.filter((child) => {
81
81
  return this !== child;
82
82
  });
@@ -97,14 +97,13 @@ export default class HTMLElement extends Node {
97
97
  * @param {HTMLElement} newNode new node
98
98
  */
99
99
  exchangeChild(oldNode, newNode) {
100
- let idx = -1;
101
- for (let i = 0; i < this.childNodes.length; i++) {
102
- if (this.childNodes[i] === oldNode) {
103
- idx = i;
104
- break;
100
+ const children = this.childNodes;
101
+ this.childNodes = children.map((child) => {
102
+ if (child === oldNode) {
103
+ return newNode;
105
104
  }
106
- }
107
- this.childNodes[idx] = newNode;
105
+ return child;
106
+ });
108
107
  }
109
108
  get tagName() {
110
109
  return this.rawTagName ? this.rawTagName.toUpperCase() : this.rawTagName;
@@ -556,6 +555,38 @@ export default class HTMLElement extends Node {
556
555
  // return;
557
556
  // }
558
557
  }
558
+ get nextSibling() {
559
+ if (this.parentNode) {
560
+ const children = this.parentNode.childNodes;
561
+ let i = 0;
562
+ while (i < children.length) {
563
+ const child = children[i++];
564
+ if (this === child) {
565
+ return children[i] || null;
566
+ }
567
+ }
568
+ return null;
569
+ }
570
+ }
571
+ get nextElementSibling() {
572
+ if (this.parentNode) {
573
+ const children = this.parentNode.childNodes;
574
+ let i = 0;
575
+ let find = false;
576
+ while (i < children.length) {
577
+ const child = children[i++];
578
+ if (find) {
579
+ if (child instanceof HTMLElement) {
580
+ return child || null;
581
+ }
582
+ }
583
+ else if (this === child) {
584
+ find = true;
585
+ }
586
+ }
587
+ return null;
588
+ }
589
+ }
559
590
  }
560
591
  // https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
561
592
  const kMarkupPattern = /<!--[^]*?(?=-->)-->|<(\/?)([a-z][-.:0-9_a-z]*)\s*([^>]*?)(\/?)>/ig;
package/dist/main.js CHANGED
@@ -480,7 +480,7 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
480
480
  HTMLElement.prototype.remove = function () {
481
481
  var _this = this;
482
482
  if (this.parentNode) {
483
- var children = this.childNodes;
483
+ var children = this.parentNode.childNodes;
484
484
  this.parentNode.childNodes = children.filter(function (child) {
485
485
  return _this !== child;
486
486
  });
@@ -501,14 +501,13 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
501
501
  * @param {HTMLElement} newNode new node
502
502
  */
503
503
  HTMLElement.prototype.exchangeChild = function (oldNode, newNode) {
504
- var idx = -1;
505
- for (var i = 0; i < this.childNodes.length; i++) {
506
- if (this.childNodes[i] === oldNode) {
507
- idx = i;
508
- break;
504
+ var children = this.childNodes;
505
+ this.childNodes = children.map(function (child) {
506
+ if (child === oldNode) {
507
+ return newNode;
509
508
  }
510
- }
511
- this.childNodes[idx] = newNode;
509
+ return child;
510
+ });
512
511
  };
513
512
  Object.defineProperty(HTMLElement.prototype, "tagName", {
514
513
  get: function () {
@@ -1010,6 +1009,46 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
1010
1009
  // return;
1011
1010
  // }
1012
1011
  };
1012
+ Object.defineProperty(HTMLElement.prototype, "nextSibling", {
1013
+ get: function () {
1014
+ if (this.parentNode) {
1015
+ var children = this.parentNode.childNodes;
1016
+ var i = 0;
1017
+ while (i < children.length) {
1018
+ var child = children[i++];
1019
+ if (this === child) {
1020
+ return children[i] || null;
1021
+ }
1022
+ }
1023
+ return null;
1024
+ }
1025
+ },
1026
+ enumerable: false,
1027
+ configurable: true
1028
+ });
1029
+ Object.defineProperty(HTMLElement.prototype, "nextElementSibling", {
1030
+ get: function () {
1031
+ if (this.parentNode) {
1032
+ var children = this.parentNode.childNodes;
1033
+ var i = 0;
1034
+ var find = false;
1035
+ while (i < children.length) {
1036
+ var child = children[i++];
1037
+ if (find) {
1038
+ if (child instanceof HTMLElement) {
1039
+ return child || null;
1040
+ }
1041
+ }
1042
+ else if (this === child) {
1043
+ find = true;
1044
+ }
1045
+ }
1046
+ return null;
1047
+ }
1048
+ },
1049
+ enumerable: false,
1050
+ configurable: true
1051
+ });
1013
1052
  return HTMLElement;
1014
1053
  }(node_3.default));
1015
1054
  exports.default = HTMLElement;
@@ -152,6 +152,8 @@ export default class HTMLElement extends Node {
152
152
  */
153
153
  setAttributes(attributes: Attributes): void;
154
154
  insertAdjacentHTML(where: InsertPosition, html: string): void;
155
+ get nextSibling(): Node;
156
+ get nextElementSibling(): HTMLElement;
155
157
  }
156
158
  export interface Options {
157
159
  lowerCaseTagName: boolean;
@@ -107,7 +107,7 @@ var HTMLElement = /** @class */ (function (_super) {
107
107
  HTMLElement.prototype.remove = function () {
108
108
  var _this = this;
109
109
  if (this.parentNode) {
110
- var children = this.childNodes;
110
+ var children = this.parentNode.childNodes;
111
111
  this.parentNode.childNodes = children.filter(function (child) {
112
112
  return _this !== child;
113
113
  });
@@ -128,14 +128,13 @@ var HTMLElement = /** @class */ (function (_super) {
128
128
  * @param {HTMLElement} newNode new node
129
129
  */
130
130
  HTMLElement.prototype.exchangeChild = function (oldNode, newNode) {
131
- var idx = -1;
132
- for (var i = 0; i < this.childNodes.length; i++) {
133
- if (this.childNodes[i] === oldNode) {
134
- idx = i;
135
- break;
131
+ var children = this.childNodes;
132
+ this.childNodes = children.map(function (child) {
133
+ if (child === oldNode) {
134
+ return newNode;
136
135
  }
137
- }
138
- this.childNodes[idx] = newNode;
136
+ return child;
137
+ });
139
138
  };
140
139
  Object.defineProperty(HTMLElement.prototype, "tagName", {
141
140
  get: function () {
@@ -637,6 +636,46 @@ var HTMLElement = /** @class */ (function (_super) {
637
636
  // return;
638
637
  // }
639
638
  };
639
+ Object.defineProperty(HTMLElement.prototype, "nextSibling", {
640
+ get: function () {
641
+ if (this.parentNode) {
642
+ var children = this.parentNode.childNodes;
643
+ var i = 0;
644
+ while (i < children.length) {
645
+ var child = children[i++];
646
+ if (this === child) {
647
+ return children[i] || null;
648
+ }
649
+ }
650
+ return null;
651
+ }
652
+ },
653
+ enumerable: false,
654
+ configurable: true
655
+ });
656
+ Object.defineProperty(HTMLElement.prototype, "nextElementSibling", {
657
+ get: function () {
658
+ if (this.parentNode) {
659
+ var children = this.parentNode.childNodes;
660
+ var i = 0;
661
+ var find = false;
662
+ while (i < children.length) {
663
+ var child = children[i++];
664
+ if (find) {
665
+ if (child instanceof HTMLElement) {
666
+ return child || null;
667
+ }
668
+ }
669
+ else if (this === child) {
670
+ find = true;
671
+ }
672
+ }
673
+ return null;
674
+ }
675
+ },
676
+ enumerable: false,
677
+ configurable: true
678
+ });
640
679
  return HTMLElement;
641
680
  }(node_1.default));
642
681
  exports.default = HTMLElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-html-parser",
3
- "version": "1.4.7",
3
+ "version": "1.4.8",
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
  "module": "dist/esm/index.js",
@@ -13,11 +13,14 @@
13
13
  "ts:amd": "tsc -t es5 -m amd -d false --outFile ./dist/main.js",
14
14
  "ts:esm": "tsc -t esnext -m esnext -d false --outDir ./dist/esm/",
15
15
  "build": "npm run lint && npm run clean && npm run ts:cjs && npm run ts:amd && npm run ts:esm",
16
- "dev": "tsc -w",
16
+ "dev": "tsc -w & mocha -w ./test/*.js",
17
17
  "pretest": "tsc -m commonjs"
18
18
  },
19
19
  "keywords": [
20
- "fast html parser nodejs typescript"
20
+ "parser",
21
+ "html",
22
+ "nodejs",
23
+ "typescript"
21
24
  ],
22
25
  "author": "Xiaoyi Shi <ashi009@gmail.com>",
23
26
  "contributors": [