node-html-parser 1.4.2 → 1.4.6

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.
@@ -161,31 +161,18 @@ export default class Matcher {
161
161
  let attr_key = '';
162
162
  let value = '';
163
163
  if (tagName && tagName !== '*') {
164
- let reg;
165
164
  if (tagName.startsWith('#')) {
166
165
  // source += 'if (el.id != ' + JSON.stringify(tagName.substr(1)) + ') return false;';// 1
167
166
  function_name += '1';
168
167
  }
169
168
  else {
170
- reg = /^\[\s*(\S+)\s*(=|!=)\s*((((["'])([^\6]*)\6))|(\S*?))\]\s*/.exec(tagName);
169
+ const reg = /\[\s*([\w-]+)(\s*=\s*(((?<quote>'|")\s*(.*)(\k<quote>))|(\S*)))?\s*\]/.exec(tagName);
171
170
  if (reg) {
172
171
  attr_key = reg[1];
173
- let method = reg[2];
174
- if (method !== '=' && method !== '!=') {
175
- // eslint-disable-next-line no-template-curly-in-string
176
- throw new Error('Selector not supported, Expect [key${op}value].op must be =,!=');
177
- }
178
- if (method === '=') {
179
- method = '==';
180
- }
181
- value = reg[7] || reg[8];
172
+ value = reg[6] || reg[8];
182
173
  // source += `let attrs = el.attributes;for (let key in attrs){const val = attrs[key]; if (key == "${attr_key}" && val == "${value}"){return true;}} return false;`;// 2
183
174
  function_name += '2';
184
175
  }
185
- else if ((reg = /^\[(.*?)\]/.exec(tagName))) {
186
- attr_key = reg[1];
187
- function_name += '5';
188
- }
189
176
  else {
190
177
  // source += 'if (el.tagName != ' + JSON.stringify(tagName) + ') return false;';// 3
191
178
  function_name += '3';
@@ -96,7 +96,7 @@ export default class HTMLElement extends Node {
96
96
  this.childNodes[idx] = newNode;
97
97
  }
98
98
  get tagName() {
99
- return this.rawTagName?.toUpperCase();
99
+ return this.rawTagName ? this.rawTagName.toUpperCase() : this.rawTagName;
100
100
  }
101
101
  /**
102
102
  * Get escpaed (as-it) text value of current node and its children.
@@ -573,7 +573,15 @@ const kSelfClosingElements = {
573
573
  meta: true,
574
574
  META: true,
575
575
  source: true,
576
- SOURCE: true
576
+ SOURCE: true,
577
+ embed: true,
578
+ EMBED: true,
579
+ param: true,
580
+ PARAM: true,
581
+ track: true,
582
+ TRACK: true,
583
+ wbr: true,
584
+ WBR: true
577
585
  };
578
586
  const kElementsClosedByOpening = {
579
587
  li: { li: true, LI: true },
package/dist/main.js CHANGED
@@ -312,31 +312,18 @@ define("matcher", ["require", "exports"], function (require, exports) {
312
312
  var attr_key = '';
313
313
  var value = '';
314
314
  if (tagName && tagName !== '*') {
315
- var reg = void 0;
316
315
  if (tagName.startsWith('#')) {
317
316
  // source += 'if (el.id != ' + JSON.stringify(tagName.substr(1)) + ') return false;';// 1
318
317
  function_name += '1';
319
318
  }
320
319
  else {
321
- reg = /^\[\s*(\S+)\s*(=|!=)\s*((((["'])([^\6]*)\6))|(\S*?))\]\s*/.exec(tagName);
320
+ var reg = /\[\s*([\w-]+)(\s*=\s*(((?<quote>'|")\s*(.*)(\k<quote>))|(\S*)))?\s*\]/.exec(tagName);
322
321
  if (reg) {
323
322
  attr_key = reg[1];
324
- var method = reg[2];
325
- if (method !== '=' && method !== '!=') {
326
- // eslint-disable-next-line no-template-curly-in-string
327
- throw new Error('Selector not supported, Expect [key${op}value].op must be =,!=');
328
- }
329
- if (method === '=') {
330
- method = '==';
331
- }
332
- value = reg[7] || reg[8];
323
+ value = reg[6] || reg[8];
333
324
  // source += `let attrs = el.attributes;for (let key in attrs){const val = attrs[key]; if (key == "${attr_key}" && val == "${value}"){return true;}} return false;`;// 2
334
325
  function_name += '2';
335
326
  }
336
- else if ((reg = /^\[(.*?)\]/.exec(tagName))) {
337
- attr_key = reg[1];
338
- function_name += '5';
339
- }
340
327
  else {
341
328
  // source += 'if (el.tagName != ' + JSON.stringify(tagName) + ') return false;';// 3
342
329
  function_name += '3';
@@ -513,8 +500,7 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
513
500
  };
514
501
  Object.defineProperty(HTMLElement.prototype, "tagName", {
515
502
  get: function () {
516
- var _a;
517
- return (_a = this.rawTagName) === null || _a === void 0 ? void 0 : _a.toUpperCase();
503
+ return this.rawTagName ? this.rawTagName.toUpperCase() : this.rawTagName;
518
504
  },
519
505
  enumerable: false,
520
506
  configurable: true
@@ -1042,7 +1028,15 @@ define("nodes/html", ["require", "exports", "he", "nodes/node", "nodes/type", "n
1042
1028
  meta: true,
1043
1029
  META: true,
1044
1030
  source: true,
1045
- SOURCE: true
1031
+ SOURCE: true,
1032
+ embed: true,
1033
+ EMBED: true,
1034
+ param: true,
1035
+ PARAM: true,
1036
+ track: true,
1037
+ TRACK: true,
1038
+ wbr: true,
1039
+ WBR: true
1046
1040
  };
1047
1041
  var kElementsClosedByOpening = {
1048
1042
  li: { li: true, LI: true },
package/dist/matcher.js CHANGED
@@ -163,31 +163,18 @@ var Matcher = /** @class */ (function () {
163
163
  var attr_key = '';
164
164
  var value = '';
165
165
  if (tagName && tagName !== '*') {
166
- var reg = void 0;
167
166
  if (tagName.startsWith('#')) {
168
167
  // source += 'if (el.id != ' + JSON.stringify(tagName.substr(1)) + ') return false;';// 1
169
168
  function_name += '1';
170
169
  }
171
170
  else {
172
- reg = /^\[\s*(\S+)\s*(=|!=)\s*((((["'])([^\6]*)\6))|(\S*?))\]\s*/.exec(tagName);
171
+ var reg = /\[\s*([\w-]+)(\s*=\s*(((?<quote>'|")\s*(.*)(\k<quote>))|(\S*)))?\s*\]/.exec(tagName);
173
172
  if (reg) {
174
173
  attr_key = reg[1];
175
- var method = reg[2];
176
- if (method !== '=' && method !== '!=') {
177
- // eslint-disable-next-line no-template-curly-in-string
178
- throw new Error('Selector not supported, Expect [key${op}value].op must be =,!=');
179
- }
180
- if (method === '=') {
181
- method = '==';
182
- }
183
- value = reg[7] || reg[8];
174
+ value = reg[6] || reg[8];
184
175
  // source += `let attrs = el.attributes;for (let key in attrs){const val = attrs[key]; if (key == "${attr_key}" && val == "${value}"){return true;}} return false;`;// 2
185
176
  function_name += '2';
186
177
  }
187
- else if ((reg = /^\[(.*?)\]/.exec(tagName))) {
188
- attr_key = reg[1];
189
- function_name += '5';
190
- }
191
178
  else {
192
179
  // source += 'if (el.tagName != ' + JSON.stringify(tagName) + ') return false;';// 3
193
180
  function_name += '3';
@@ -127,8 +127,7 @@ var HTMLElement = /** @class */ (function (_super) {
127
127
  };
128
128
  Object.defineProperty(HTMLElement.prototype, "tagName", {
129
129
  get: function () {
130
- var _a;
131
- return (_a = this.rawTagName) === null || _a === void 0 ? void 0 : _a.toUpperCase();
130
+ return this.rawTagName ? this.rawTagName.toUpperCase() : this.rawTagName;
132
131
  },
133
132
  enumerable: false,
134
133
  configurable: true
@@ -656,7 +655,15 @@ var kSelfClosingElements = {
656
655
  meta: true,
657
656
  META: true,
658
657
  source: true,
659
- SOURCE: true
658
+ SOURCE: true,
659
+ embed: true,
660
+ EMBED: true,
661
+ param: true,
662
+ PARAM: true,
663
+ track: true,
664
+ TRACK: true,
665
+ wbr: true,
666
+ WBR: true
660
667
  };
661
668
  var kElementsClosedByOpening = {
662
669
  li: { li: true, LI: true },
package/package.json CHANGED
@@ -1,19 +1,18 @@
1
1
  {
2
2
  "name": "node-html-parser",
3
- "version": "1.4.2",
3
+ "version": "1.4.6",
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",
7
- "browser": "dist/main.js",
8
7
  "types": "dist/index.d.ts",
9
8
  "scripts": {
10
9
  "test": "mocha",
11
10
  "lint": "eslint ./src/*.ts ./src/**/*.ts",
12
11
  "clean": "del-cli ./dist/",
13
12
  "ts:cjs": "tsc -m commonjs",
14
- "ts:umd": "tsc -t es5 -m amd -d false --outFile ./dist/main.js",
13
+ "ts:amd": "tsc -t es5 -m amd -d false --outFile ./dist/main.js",
15
14
  "ts:esm": "tsc -t esnext -m esnext -d false --outDir ./dist/esm/",
16
- "build": "npm run lint && npm run clean && npm run ts:cjs && npm run ts:umd && npm run ts:esm",
15
+ "build": "npm run lint && npm run clean && npm run ts:cjs && npm run ts:amd && npm run ts:esm",
17
16
  "dev": "tsc -w",
18
17
  "pretest": "tsc -m commonjs"
19
18
  },