node-html-parser 1.4.5 → 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';
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';
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';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-html-parser",
3
- "version": "1.4.5",
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",