feedsmith 2.9.1 → 2.9.2

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
@@ -19,7 +19,7 @@ Feedsmith offers universal and format‑specific parsers that maintain the origi
19
19
  ---
20
20
 
21
21
  > [!IMPORTANT]
22
- > **Feedsmith 3.x is in final stages of development.** Check out the [v3.x guide](https://next.feedsmith.dev/migration/v2-to-v3) to explore new features and learn how to upgrade. Install it with:
22
+ > **Feedsmith 3.x is in final stages of development.** Check out the [v3.x guide](https://v3.feedsmith.dev/migration/v2-to-v3) to explore new features and learn how to upgrade. Install it with:
23
23
  >
24
24
  > `npm install feedsmith@next`
25
25
 
@@ -43,6 +43,7 @@ const parserConfig = {
43
43
  ignorePiTags: true,
44
44
  ignoreDeclaration: true,
45
45
  attributeNamePrefix: "@",
46
+ jPath: false,
46
47
  transformTagName: (name) => name.toLowerCase(),
47
48
  transformAttributeName: (name) => name.toLowerCase()
48
49
  };
@@ -43,6 +43,7 @@ const parserConfig = {
43
43
  ignorePiTags: true,
44
44
  ignoreDeclaration: true,
45
45
  attributeNamePrefix: "@",
46
+ jPath: false,
46
47
  transformTagName: (name) => name.toLowerCase(),
47
48
  transformAttributeName: (name) => name.toLowerCase()
48
49
  };
@@ -26,13 +26,19 @@ const retrieveRdfResourceOrText = (value, parse) => {
26
26
  return parse(retrieveText(value));
27
27
  };
28
28
  const trimObject = (object) => {
29
- let result;
29
+ let hasPresent = false;
30
+ let hasAbsent = false;
31
+ for (const key in object) {
32
+ if (isPresent(object[key])) hasPresent = true;
33
+ else hasAbsent = true;
34
+ if (hasPresent && hasAbsent) break;
35
+ }
36
+ if (!hasPresent) return;
37
+ if (!hasAbsent) return object;
38
+ const result = {};
30
39
  for (const key in object) {
31
40
  const value = object[key];
32
- if (isPresent(value)) {
33
- if (!result) result = {};
34
- result[key] = value;
35
- }
41
+ if (isPresent(value)) result[key] = value;
36
42
  }
37
43
  return result;
38
44
  };
@@ -40,15 +46,15 @@ const trimArray = (value, parse) => {
40
46
  if (!Array.isArray(value) || value.length === 0) return;
41
47
  if (!parse) {
42
48
  let needsTrimming = false;
43
- for (let i = 0; i < value.length; i++) if (!isPresent(value[i])) {
49
+ for (const item of value) if (!isPresent(item)) {
44
50
  needsTrimming = true;
45
51
  break;
46
52
  }
47
53
  if (!needsTrimming) return value;
48
54
  }
49
55
  const result = [];
50
- for (let i = 0; i < value.length; i++) {
51
- const item = parse ? parse(value[i]) : value[i];
56
+ for (const element of value) {
57
+ const item = parse ? parse(element) : element;
52
58
  if (isPresent(item)) result.push(item);
53
59
  }
54
60
  return result.length > 0 ? result : void 0;
@@ -75,13 +81,13 @@ const stripComments = (text) => {
75
81
  let result = "";
76
82
  let lastIndex = 0;
77
83
  while (currentIndex !== -1) {
78
- result += text.substring(lastIndex, currentIndex);
84
+ result += text.slice(lastIndex, currentIndex);
79
85
  const endIndex = text.indexOf(commentEndTag, currentIndex + 4);
80
86
  if (endIndex === -1) return text;
81
87
  lastIndex = endIndex + 3;
82
88
  currentIndex = text.indexOf(commentStartTag, lastIndex);
83
89
  }
84
- result += text.substring(lastIndex);
90
+ result += text.slice(lastIndex);
85
91
  return result;
86
92
  };
87
93
  const decodeWithCdata = (text) => {
@@ -90,15 +96,15 @@ const decodeWithCdata = (text) => {
90
96
  let result = "";
91
97
  let lastIndex = 0;
92
98
  while (currentIndex !== -1) {
93
- const textBefore = text.substring(lastIndex, currentIndex);
99
+ const textBefore = text.slice(lastIndex, currentIndex);
94
100
  result += hasEntities(textBefore) ? (0, entities.decodeHTML)(textBefore) : textBefore;
95
101
  const endIndex = text.indexOf(cdataEndTag, currentIndex + 9);
96
102
  if (endIndex === -1) return hasEntities(text) ? (0, entities.decodeHTML)(text) : text;
97
- result += text.substring(currentIndex + 9, endIndex);
103
+ result += text.slice(currentIndex + 9, endIndex);
98
104
  lastIndex = endIndex + 3;
99
105
  currentIndex = text.indexOf(cdataStartTag, lastIndex);
100
106
  }
101
- const textAfter = text.substring(lastIndex);
107
+ const textAfter = text.slice(lastIndex);
102
108
  result += hasEntities(textAfter) ? (0, entities.decodeHTML)(textAfter) : textAfter;
103
109
  return result;
104
110
  };
@@ -300,7 +306,7 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
300
306
  if (isObject(element)) {
301
307
  for (const key in element) if (key === "@xmlns") declarations[""] = normalizeNamespaceUri(element[key]);
302
308
  else if (key.indexOf("@xmlns:") === 0) {
303
- const prefix = key.substring(7);
309
+ const prefix = key.slice(7);
304
310
  declarations[prefix] = normalizeNamespaceUri(element[key]);
305
311
  }
306
312
  }
@@ -312,14 +318,14 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
312
318
  if (useDefault && context[""]) return resolveNamespacePrefix(context[""], name, name);
313
319
  return name;
314
320
  }
315
- const prefix = name.substring(0, colonIndex);
316
- const unprefixedName = name.substring(colonIndex + 1);
321
+ const prefix = name.slice(0, colonIndex);
322
+ const unprefixedName = name.slice(colonIndex + 1);
317
323
  const uri = context[prefix];
318
324
  if (uri) return resolveNamespacePrefix(uri, unprefixedName, name);
319
325
  return name;
320
326
  };
321
327
  const normalizeKey = (key, context) => {
322
- if (key.charCodeAt(0) === 64) return `@${normalizeWithContext(key.substring(1), context, false)}`;
328
+ if (key.charCodeAt(0) === 64) return `@${normalizeWithContext(key.slice(1), context, false)}`;
323
329
  return normalizeWithContext(key, context, true);
324
330
  };
325
331
  const traverseAndNormalize = (object, parentContext = {}) => {
@@ -352,9 +358,40 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
352
358
  }
353
359
  return normalizedObject;
354
360
  };
361
+ const needsNormalization = (object) => {
362
+ const check = (value) => {
363
+ if (Array.isArray(value)) {
364
+ for (const item of value) if (check(item)) return true;
365
+ return false;
366
+ }
367
+ if (!isObject(value)) return false;
368
+ for (const key in value) {
369
+ if (key[0] === "@") {
370
+ if (key === "@xmlns") {
371
+ const normalizedUri = normalizeNamespaceUri(value[key]);
372
+ if (primaryNamespaceUris?.includes(normalizedUri)) continue;
373
+ if (namespacePrefixes[normalizedUri]) return true;
374
+ } else if (key.startsWith("@xmlns:")) {
375
+ const prefix = key.slice(7);
376
+ const normalizedUri = normalizeNamespaceUri(value[key]);
377
+ const standardPrefix = namespacePrefixes[normalizedUri];
378
+ if (standardPrefix) {
379
+ if (primaryNamespaceUris?.includes(normalizedUri)) return true;
380
+ if (standardPrefix !== prefix) return true;
381
+ }
382
+ }
383
+ continue;
384
+ }
385
+ if (key[0] === "#") continue;
386
+ if (check(value[key])) return true;
387
+ }
388
+ return false;
389
+ };
390
+ return check(object);
391
+ };
355
392
  const normalizeRoot = (object) => {
356
393
  if (!isObject(object)) return object;
357
- if (Array.isArray(object)) return object.map(normalizeRoot);
394
+ if (!needsNormalization(object)) return object;
358
395
  const normalizedObject = {};
359
396
  for (const key in object) {
360
397
  const value = object[key];
@@ -366,19 +403,42 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
366
403
  };
367
404
  return normalizeRoot;
368
405
  };
406
+ const startsWithBraceRegex = /^\s*\{/;
407
+ const endsWithBraceRegex = /\}\s*$/;
369
408
  const parseJsonObject = (value) => {
370
409
  if (isObject(value)) return value;
371
410
  if (!isNonEmptyString(value) || value.length < 2) return;
372
- const startsWithBrace = value.charAt(0) === "{" || /^\s*\{/.test(value);
373
- const endsWithBrace = value.charAt(value.length - 1) === "}" || /\}\s*$/.test(value);
411
+ const startsWithBrace = value.charAt(0) === "{" || startsWithBraceRegex.test(value);
412
+ const endsWithBrace = value.charAt(value.length - 1) === "}" || endsWithBraceRegex.test(value);
374
413
  if (!startsWithBrace || !endsWithBrace) return;
375
414
  try {
376
415
  return JSON.parse(value);
377
416
  } catch {}
378
417
  };
418
+ const namespaceContainers = [
419
+ "media:group",
420
+ "media:content",
421
+ "media:group.media:content",
422
+ "media:embed",
423
+ "podcast:liveitem",
424
+ "itunes:owner"
425
+ ];
426
+ const expandStopNodes = (stopNodes, feedContainerPaths) => {
427
+ const set = /* @__PURE__ */ new Set();
428
+ for (const node of stopNodes) {
429
+ const suffix = node.slice(2);
430
+ const prefix = suffix.split(":")[0];
431
+ for (const feedPath of feedContainerPaths) {
432
+ set.add(`${feedPath}.${suffix}`);
433
+ for (const nsContainer of namespaceContainers) if (nsContainer.split(":")[0] === prefix) set.add(`${feedPath}.${nsContainer}.${suffix}`);
434
+ }
435
+ }
436
+ return [...set];
437
+ };
379
438
  //#endregion
380
439
  exports.createNamespaceNormalizator = createNamespaceNormalizator;
381
440
  exports.detectNamespaces = detectNamespaces;
441
+ exports.expandStopNodes = expandStopNodes;
382
442
  exports.generateArrayOrSingular = generateArrayOrSingular;
383
443
  exports.generateBoolean = generateBoolean;
384
444
  exports.generateCdataString = generateCdataString;
@@ -26,13 +26,19 @@ const retrieveRdfResourceOrText = (value, parse) => {
26
26
  return parse(retrieveText(value));
27
27
  };
28
28
  const trimObject = (object) => {
29
- let result;
29
+ let hasPresent = false;
30
+ let hasAbsent = false;
31
+ for (const key in object) {
32
+ if (isPresent(object[key])) hasPresent = true;
33
+ else hasAbsent = true;
34
+ if (hasPresent && hasAbsent) break;
35
+ }
36
+ if (!hasPresent) return;
37
+ if (!hasAbsent) return object;
38
+ const result = {};
30
39
  for (const key in object) {
31
40
  const value = object[key];
32
- if (isPresent(value)) {
33
- if (!result) result = {};
34
- result[key] = value;
35
- }
41
+ if (isPresent(value)) result[key] = value;
36
42
  }
37
43
  return result;
38
44
  };
@@ -40,15 +46,15 @@ const trimArray = (value, parse) => {
40
46
  if (!Array.isArray(value) || value.length === 0) return;
41
47
  if (!parse) {
42
48
  let needsTrimming = false;
43
- for (let i = 0; i < value.length; i++) if (!isPresent(value[i])) {
49
+ for (const item of value) if (!isPresent(item)) {
44
50
  needsTrimming = true;
45
51
  break;
46
52
  }
47
53
  if (!needsTrimming) return value;
48
54
  }
49
55
  const result = [];
50
- for (let i = 0; i < value.length; i++) {
51
- const item = parse ? parse(value[i]) : value[i];
56
+ for (const element of value) {
57
+ const item = parse ? parse(element) : element;
52
58
  if (isPresent(item)) result.push(item);
53
59
  }
54
60
  return result.length > 0 ? result : void 0;
@@ -75,13 +81,13 @@ const stripComments = (text) => {
75
81
  let result = "";
76
82
  let lastIndex = 0;
77
83
  while (currentIndex !== -1) {
78
- result += text.substring(lastIndex, currentIndex);
84
+ result += text.slice(lastIndex, currentIndex);
79
85
  const endIndex = text.indexOf(commentEndTag, currentIndex + 4);
80
86
  if (endIndex === -1) return text;
81
87
  lastIndex = endIndex + 3;
82
88
  currentIndex = text.indexOf(commentStartTag, lastIndex);
83
89
  }
84
- result += text.substring(lastIndex);
90
+ result += text.slice(lastIndex);
85
91
  return result;
86
92
  };
87
93
  const decodeWithCdata = (text) => {
@@ -90,15 +96,15 @@ const decodeWithCdata = (text) => {
90
96
  let result = "";
91
97
  let lastIndex = 0;
92
98
  while (currentIndex !== -1) {
93
- const textBefore = text.substring(lastIndex, currentIndex);
99
+ const textBefore = text.slice(lastIndex, currentIndex);
94
100
  result += hasEntities(textBefore) ? decodeHTML(textBefore) : textBefore;
95
101
  const endIndex = text.indexOf(cdataEndTag, currentIndex + 9);
96
102
  if (endIndex === -1) return hasEntities(text) ? decodeHTML(text) : text;
97
- result += text.substring(currentIndex + 9, endIndex);
103
+ result += text.slice(currentIndex + 9, endIndex);
98
104
  lastIndex = endIndex + 3;
99
105
  currentIndex = text.indexOf(cdataStartTag, lastIndex);
100
106
  }
101
- const textAfter = text.substring(lastIndex);
107
+ const textAfter = text.slice(lastIndex);
102
108
  result += hasEntities(textAfter) ? decodeHTML(textAfter) : textAfter;
103
109
  return result;
104
110
  };
@@ -300,7 +306,7 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
300
306
  if (isObject(element)) {
301
307
  for (const key in element) if (key === "@xmlns") declarations[""] = normalizeNamespaceUri(element[key]);
302
308
  else if (key.indexOf("@xmlns:") === 0) {
303
- const prefix = key.substring(7);
309
+ const prefix = key.slice(7);
304
310
  declarations[prefix] = normalizeNamespaceUri(element[key]);
305
311
  }
306
312
  }
@@ -312,14 +318,14 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
312
318
  if (useDefault && context[""]) return resolveNamespacePrefix(context[""], name, name);
313
319
  return name;
314
320
  }
315
- const prefix = name.substring(0, colonIndex);
316
- const unprefixedName = name.substring(colonIndex + 1);
321
+ const prefix = name.slice(0, colonIndex);
322
+ const unprefixedName = name.slice(colonIndex + 1);
317
323
  const uri = context[prefix];
318
324
  if (uri) return resolveNamespacePrefix(uri, unprefixedName, name);
319
325
  return name;
320
326
  };
321
327
  const normalizeKey = (key, context) => {
322
- if (key.charCodeAt(0) === 64) return `@${normalizeWithContext(key.substring(1), context, false)}`;
328
+ if (key.charCodeAt(0) === 64) return `@${normalizeWithContext(key.slice(1), context, false)}`;
323
329
  return normalizeWithContext(key, context, true);
324
330
  };
325
331
  const traverseAndNormalize = (object, parentContext = {}) => {
@@ -352,9 +358,40 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
352
358
  }
353
359
  return normalizedObject;
354
360
  };
361
+ const needsNormalization = (object) => {
362
+ const check = (value) => {
363
+ if (Array.isArray(value)) {
364
+ for (const item of value) if (check(item)) return true;
365
+ return false;
366
+ }
367
+ if (!isObject(value)) return false;
368
+ for (const key in value) {
369
+ if (key[0] === "@") {
370
+ if (key === "@xmlns") {
371
+ const normalizedUri = normalizeNamespaceUri(value[key]);
372
+ if (primaryNamespaceUris?.includes(normalizedUri)) continue;
373
+ if (namespacePrefixes[normalizedUri]) return true;
374
+ } else if (key.startsWith("@xmlns:")) {
375
+ const prefix = key.slice(7);
376
+ const normalizedUri = normalizeNamespaceUri(value[key]);
377
+ const standardPrefix = namespacePrefixes[normalizedUri];
378
+ if (standardPrefix) {
379
+ if (primaryNamespaceUris?.includes(normalizedUri)) return true;
380
+ if (standardPrefix !== prefix) return true;
381
+ }
382
+ }
383
+ continue;
384
+ }
385
+ if (key[0] === "#") continue;
386
+ if (check(value[key])) return true;
387
+ }
388
+ return false;
389
+ };
390
+ return check(object);
391
+ };
355
392
  const normalizeRoot = (object) => {
356
393
  if (!isObject(object)) return object;
357
- if (Array.isArray(object)) return object.map(normalizeRoot);
394
+ if (!needsNormalization(object)) return object;
358
395
  const normalizedObject = {};
359
396
  for (const key in object) {
360
397
  const value = object[key];
@@ -366,15 +403,37 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
366
403
  };
367
404
  return normalizeRoot;
368
405
  };
406
+ const startsWithBraceRegex = /^\s*\{/;
407
+ const endsWithBraceRegex = /\}\s*$/;
369
408
  const parseJsonObject = (value) => {
370
409
  if (isObject(value)) return value;
371
410
  if (!isNonEmptyString(value) || value.length < 2) return;
372
- const startsWithBrace = value.charAt(0) === "{" || /^\s*\{/.test(value);
373
- const endsWithBrace = value.charAt(value.length - 1) === "}" || /\}\s*$/.test(value);
411
+ const startsWithBrace = value.charAt(0) === "{" || startsWithBraceRegex.test(value);
412
+ const endsWithBrace = value.charAt(value.length - 1) === "}" || endsWithBraceRegex.test(value);
374
413
  if (!startsWithBrace || !endsWithBrace) return;
375
414
  try {
376
415
  return JSON.parse(value);
377
416
  } catch {}
378
417
  };
418
+ const namespaceContainers = [
419
+ "media:group",
420
+ "media:content",
421
+ "media:group.media:content",
422
+ "media:embed",
423
+ "podcast:liveitem",
424
+ "itunes:owner"
425
+ ];
426
+ const expandStopNodes = (stopNodes, feedContainerPaths) => {
427
+ const set = /* @__PURE__ */ new Set();
428
+ for (const node of stopNodes) {
429
+ const suffix = node.slice(2);
430
+ const prefix = suffix.split(":")[0];
431
+ for (const feedPath of feedContainerPaths) {
432
+ set.add(`${feedPath}.${suffix}`);
433
+ for (const nsContainer of namespaceContainers) if (nsContainer.split(":")[0] === prefix) set.add(`${feedPath}.${nsContainer}.${suffix}`);
434
+ }
435
+ }
436
+ return [...set];
437
+ };
379
438
  //#endregion
380
- export { createNamespaceNormalizator, detectNamespaces, generateArrayOrSingular, generateBoolean, generateCdataString, generateCsvOf, generateNamespaceAttrs, generateNumber, generatePlainString, generateRdfResource, generateRfc3339Date, generateRfc822Date, generateSingularOrArray, generateTextOrCdataString, generateXml, generateYesNoBoolean, isNonEmptyString, isNonEmptyStringOrNumber, isObject, isPresent, parseArrayOf, parseBoolean, parseCsvOf, parseDate, parseJsonObject, parseNumber, parseSingular, parseSingularOf, parseString, parseYesNoBoolean, retrieveRdfResourceOrText, retrieveText, trimArray, trimObject };
439
+ export { createNamespaceNormalizator, detectNamespaces, expandStopNodes, generateArrayOrSingular, generateBoolean, generateCdataString, generateCsvOf, generateNamespaceAttrs, generateNumber, generatePlainString, generateRdfResource, generateRfc3339Date, generateRfc822Date, generateSingularOrArray, generateTextOrCdataString, generateXml, generateYesNoBoolean, isNonEmptyString, isNonEmptyStringOrNumber, isObject, isPresent, parseArrayOf, parseBoolean, parseCsvOf, parseDate, parseJsonObject, parseNumber, parseSingular, parseSingularOf, parseString, parseYesNoBoolean, retrieveRdfResourceOrText, retrieveText, trimArray, trimObject };
@@ -1,11 +1,13 @@
1
1
  const require_config = require("../../../common/config.cjs");
2
2
  const require_utils = require("../../../common/utils.cjs");
3
3
  //#region src/feeds/atom/detect/index.ts
4
+ const feedElementRegex = /(?:^|[\s>])<(?:\w+:)?feed[\s>]/im;
5
+ const atomElementsRegex = /(<(?:\w+:)?(entry|title|link|id|updated|summary)[\s>])/i;
4
6
  const detect = (value) => {
5
7
  if (!require_utils.isNonEmptyString(value)) return false;
6
- if (!/(?:^|[\s>])<(?:\w+:)?feed[\s>]/im.test(value)) return false;
8
+ if (!feedElementRegex.test(value)) return false;
7
9
  const hasAtomNamespace = require_config.namespaceUris.atom.some((uri) => value.includes(uri));
8
- const hasAtomElements = /(<(?:\w+:)?(entry|title|link|id|updated|summary)[\s>])/i.test(value);
10
+ const hasAtomElements = atomElementsRegex.test(value);
9
11
  return hasAtomNamespace || hasAtomElements;
10
12
  };
11
13
  //#endregion
@@ -1,11 +1,13 @@
1
1
  import { namespaceUris } from "../../../common/config.js";
2
2
  import { isNonEmptyString } from "../../../common/utils.js";
3
3
  //#region src/feeds/atom/detect/index.ts
4
+ const feedElementRegex = /(?:^|[\s>])<(?:\w+:)?feed[\s>]/im;
5
+ const atomElementsRegex = /(<(?:\w+:)?(entry|title|link|id|updated|summary)[\s>])/i;
4
6
  const detect = (value) => {
5
7
  if (!isNonEmptyString(value)) return false;
6
- if (!/(?:^|[\s>])<(?:\w+:)?feed[\s>]/im.test(value)) return false;
8
+ if (!feedElementRegex.test(value)) return false;
7
9
  const hasAtomNamespace = namespaceUris.atom.some((uri) => value.includes(uri));
8
- const hasAtomElements = /(<(?:\w+:)?(entry|title|link|id|updated|summary)[\s>])/i.test(value);
10
+ const hasAtomElements = atomElementsRegex.test(value);
9
11
  return hasAtomNamespace || hasAtomElements;
10
12
  };
11
13
  //#endregion
@@ -1,9 +1,14 @@
1
1
  const require_config = require("../../../common/config.cjs");
2
2
  const require_utils = require("../../../common/utils.cjs");
3
+ const require_Expression = require("../../../node_modules/path-expression-matcher/src/Expression.cjs");
3
4
  let fast_xml_parser = require("fast-xml-parser");
4
5
  //#region src/feeds/atom/parse/config.ts
5
6
  const stopNodes = [
6
- ...require_config.namespaceStopNodes,
7
+ ...require_utils.expandStopNodes(require_config.namespaceStopNodes, [
8
+ "feed",
9
+ "feed.entry",
10
+ "feed.entry.source"
11
+ ]),
7
12
  "feed.author.name",
8
13
  "feed.author.uri",
9
14
  "feed.author.url",
@@ -66,7 +71,7 @@ const stopNodes = [
66
71
  ];
67
72
  const parser = new fast_xml_parser.XMLParser({
68
73
  ...require_config.parserConfig,
69
- stopNodes
74
+ stopNodes: stopNodes.map((node) => new require_Expression.default(node))
70
75
  });
71
76
  const normalizeNamespaces = require_utils.createNamespaceNormalizator(require_config.namespaceUris, require_config.namespacePrefixes, ["atom"]);
72
77
  //#endregion
@@ -1,9 +1,14 @@
1
1
  import { namespacePrefixes, namespaceStopNodes, namespaceUris, parserConfig } from "../../../common/config.js";
2
- import { createNamespaceNormalizator } from "../../../common/utils.js";
2
+ import { createNamespaceNormalizator, expandStopNodes } from "../../../common/utils.js";
3
+ import Expression from "../../../node_modules/path-expression-matcher/src/Expression.js";
3
4
  import { XMLParser } from "fast-xml-parser";
4
5
  //#region src/feeds/atom/parse/config.ts
5
6
  const stopNodes = [
6
- ...namespaceStopNodes,
7
+ ...expandStopNodes(namespaceStopNodes, [
8
+ "feed",
9
+ "feed.entry",
10
+ "feed.entry.source"
11
+ ]),
7
12
  "feed.author.name",
8
13
  "feed.author.uri",
9
14
  "feed.author.url",
@@ -66,7 +71,7 @@ const stopNodes = [
66
71
  ];
67
72
  const parser = new XMLParser({
68
73
  ...parserConfig,
69
- stopNodes
74
+ stopNodes: stopNodes.map((node) => new Expression(node))
70
75
  });
71
76
  const normalizeNamespaces = createNamespaceNormalizator(namespaceUris, namespacePrefixes, ["atom"]);
72
77
  //#endregion
@@ -11,12 +11,14 @@ const rssNamespaceUris = [
11
11
  "http://channel.netscape.com/rdf/simple/0.9",
12
12
  "https://channel.netscape.com/rdf/simple/0.9"
13
13
  ];
14
+ const rdfElementRegex = /(?:^|[\s>])<(?:\w+:)?rdf[\s>]/im;
15
+ const rdfElementsRegex = /(<(?:\w+:)?(channel|item|title|link|description)[\s>])/i;
14
16
  const detect = (value) => {
15
17
  if (!require_utils.isNonEmptyString(value)) return false;
16
- if (!/(?:^|[\s>])<(?:\w+:)?rdf[\s>]/im.test(value)) return false;
18
+ if (!rdfElementRegex.test(value)) return false;
17
19
  const hasRdfNamespace = require_config.namespaceUris.rdf.some((uri) => value.includes(uri));
18
20
  const hasRssNamespace = rssNamespaceUris.some((uri) => value.includes(uri));
19
- const hasRdfElements = /(<(?:\w+:)?(channel|item|title|link|description)[\s>])/i.test(value);
21
+ const hasRdfElements = rdfElementsRegex.test(value);
20
22
  return hasRdfNamespace || hasRssNamespace || hasRdfElements;
21
23
  };
22
24
  //#endregion
@@ -11,12 +11,14 @@ const rssNamespaceUris = [
11
11
  "http://channel.netscape.com/rdf/simple/0.9",
12
12
  "https://channel.netscape.com/rdf/simple/0.9"
13
13
  ];
14
+ const rdfElementRegex = /(?:^|[\s>])<(?:\w+:)?rdf[\s>]/im;
15
+ const rdfElementsRegex = /(<(?:\w+:)?(channel|item|title|link|description)[\s>])/i;
14
16
  const detect = (value) => {
15
17
  if (!isNonEmptyString(value)) return false;
16
- if (!/(?:^|[\s>])<(?:\w+:)?rdf[\s>]/im.test(value)) return false;
18
+ if (!rdfElementRegex.test(value)) return false;
17
19
  const hasRdfNamespace = namespaceUris.rdf.some((uri) => value.includes(uri));
18
20
  const hasRssNamespace = rssNamespaceUris.some((uri) => value.includes(uri));
19
- const hasRdfElements = /(<(?:\w+:)?(channel|item|title|link|description)[\s>])/i.test(value);
21
+ const hasRdfElements = rdfElementsRegex.test(value);
20
22
  return hasRdfNamespace || hasRssNamespace || hasRdfElements;
21
23
  };
22
24
  //#endregion
@@ -1,9 +1,15 @@
1
1
  const require_config = require("../../../common/config.cjs");
2
2
  const require_utils = require("../../../common/utils.cjs");
3
+ const require_Expression = require("../../../node_modules/path-expression-matcher/src/Expression.cjs");
3
4
  let fast_xml_parser = require("fast-xml-parser");
4
5
  //#region src/feeds/rdf/parse/config.ts
5
6
  const stopNodes = [
6
- ...require_config.namespaceStopNodes,
7
+ ...require_utils.expandStopNodes(require_config.namespaceStopNodes, [
8
+ "rdf:rdf.channel",
9
+ "rdf:rdf.item",
10
+ "rdf:rdf.image",
11
+ "rdf:rdf.textinput"
12
+ ]),
7
13
  "rdf:rdf.channel.title",
8
14
  "rdf:rdf.channel.link",
9
15
  "rdf:rdf.channel.description",
@@ -20,7 +26,7 @@ const stopNodes = [
20
26
  ];
21
27
  const parser = new fast_xml_parser.XMLParser({
22
28
  ...require_config.parserConfig,
23
- stopNodes
29
+ stopNodes: stopNodes.map((node) => new require_Expression.default(node))
24
30
  });
25
31
  const normalizeNamespaces = require_utils.createNamespaceNormalizator(require_config.namespaceUris, require_config.namespacePrefixes, ["rdf", "rss"]);
26
32
  //#endregion
@@ -1,9 +1,15 @@
1
1
  import { namespacePrefixes, namespaceStopNodes, namespaceUris, parserConfig } from "../../../common/config.js";
2
- import { createNamespaceNormalizator } from "../../../common/utils.js";
2
+ import { createNamespaceNormalizator, expandStopNodes } from "../../../common/utils.js";
3
+ import Expression from "../../../node_modules/path-expression-matcher/src/Expression.js";
3
4
  import { XMLParser } from "fast-xml-parser";
4
5
  //#region src/feeds/rdf/parse/config.ts
5
6
  const stopNodes = [
6
- ...namespaceStopNodes,
7
+ ...expandStopNodes(namespaceStopNodes, [
8
+ "rdf:rdf.channel",
9
+ "rdf:rdf.item",
10
+ "rdf:rdf.image",
11
+ "rdf:rdf.textinput"
12
+ ]),
7
13
  "rdf:rdf.channel.title",
8
14
  "rdf:rdf.channel.link",
9
15
  "rdf:rdf.channel.description",
@@ -20,7 +26,7 @@ const stopNodes = [
20
26
  ];
21
27
  const parser = new XMLParser({
22
28
  ...parserConfig,
23
- stopNodes
29
+ stopNodes: stopNodes.map((node) => new Expression(node))
24
30
  });
25
31
  const normalizeNamespaces = createNamespaceNormalizator(namespaceUris, namespacePrefixes, ["rdf", "rss"]);
26
32
  //#endregion
@@ -1,10 +1,13 @@
1
1
  const require_utils = require("../../../common/utils.cjs");
2
2
  //#region src/feeds/rss/detect/index.ts
3
+ const rssElementRegex = /(?:^|[\s>])<(?:\w+:)?rss[\s>]/im;
4
+ const versionAttributeRegex = /version\s*=\s*["'][^"']*["']/i;
5
+ const rssElementsRegex = /(<(channel|item|title|link|description|pubDate|guid)[\s>])/i;
3
6
  const detect = (value) => {
4
7
  if (!require_utils.isNonEmptyString(value)) return false;
5
- if (!/(?:^|[\s>])<(?:\w+:)?rss[\s>]/im.test(value)) return false;
6
- const hasVersionAttribute = /version\s*=\s*["'][^"']*["']/i.test(value);
7
- const hasRssElements = /(<(channel|item|title|link|description|pubDate|guid)[\s>])/i.test(value);
8
+ if (!rssElementRegex.test(value)) return false;
9
+ const hasVersionAttribute = versionAttributeRegex.test(value);
10
+ const hasRssElements = rssElementsRegex.test(value);
8
11
  return hasVersionAttribute || hasRssElements;
9
12
  };
10
13
  //#endregion
@@ -1,10 +1,13 @@
1
1
  import { isNonEmptyString } from "../../../common/utils.js";
2
2
  //#region src/feeds/rss/detect/index.ts
3
+ const rssElementRegex = /(?:^|[\s>])<(?:\w+:)?rss[\s>]/im;
4
+ const versionAttributeRegex = /version\s*=\s*["'][^"']*["']/i;
5
+ const rssElementsRegex = /(<(channel|item|title|link|description|pubDate|guid)[\s>])/i;
3
6
  const detect = (value) => {
4
7
  if (!isNonEmptyString(value)) return false;
5
- if (!/(?:^|[\s>])<(?:\w+:)?rss[\s>]/im.test(value)) return false;
6
- const hasVersionAttribute = /version\s*=\s*["'][^"']*["']/i.test(value);
7
- const hasRssElements = /(<(channel|item|title|link|description|pubDate|guid)[\s>])/i.test(value);
8
+ if (!rssElementRegex.test(value)) return false;
9
+ const hasVersionAttribute = versionAttributeRegex.test(value);
10
+ const hasRssElements = rssElementsRegex.test(value);
8
11
  return hasVersionAttribute || hasRssElements;
9
12
  };
10
13
  //#endregion
@@ -1,5 +1,6 @@
1
1
  const require_config = require("../../../common/config.cjs");
2
2
  const require_utils = require("../../../common/utils.cjs");
3
+ const require_Expression = require("../../../node_modules/path-expression-matcher/src/Expression.cjs");
3
4
  let fast_xml_parser = require("fast-xml-parser");
4
5
  //#region src/feeds/rss/parse/config.ts
5
6
  const sharedStopNodes = [
@@ -25,7 +26,12 @@ const sharedStopNodes = [
25
26
  "item.source"
26
27
  ];
27
28
  const stopNodes = [
28
- ...require_config.namespaceStopNodes,
29
+ ...require_utils.expandStopNodes(require_config.namespaceStopNodes, [
30
+ "rss.channel",
31
+ "rss.channel.item",
32
+ "rss",
33
+ "rss.item"
34
+ ]),
29
35
  "rss.channel.title",
30
36
  "rss.channel.link",
31
37
  "rss.channel.description",
@@ -48,7 +54,7 @@ const stopNodes = [
48
54
  ];
49
55
  const parser = new fast_xml_parser.XMLParser({
50
56
  ...require_config.parserConfig,
51
- stopNodes
57
+ stopNodes: stopNodes.map((node) => new require_Expression.default(node))
52
58
  });
53
59
  const normalizeNamespaces = require_utils.createNamespaceNormalizator(require_config.namespaceUris, require_config.namespacePrefixes);
54
60
  //#endregion
@@ -1,5 +1,6 @@
1
1
  import { namespacePrefixes, namespaceStopNodes, namespaceUris, parserConfig } from "../../../common/config.js";
2
- import { createNamespaceNormalizator } from "../../../common/utils.js";
2
+ import { createNamespaceNormalizator, expandStopNodes } from "../../../common/utils.js";
3
+ import Expression from "../../../node_modules/path-expression-matcher/src/Expression.js";
3
4
  import { XMLParser } from "fast-xml-parser";
4
5
  //#region src/feeds/rss/parse/config.ts
5
6
  const sharedStopNodes = [
@@ -25,7 +26,12 @@ const sharedStopNodes = [
25
26
  "item.source"
26
27
  ];
27
28
  const stopNodes = [
28
- ...namespaceStopNodes,
29
+ ...expandStopNodes(namespaceStopNodes, [
30
+ "rss.channel",
31
+ "rss.channel.item",
32
+ "rss",
33
+ "rss.item"
34
+ ]),
29
35
  "rss.channel.title",
30
36
  "rss.channel.link",
31
37
  "rss.channel.description",
@@ -48,7 +54,7 @@ const stopNodes = [
48
54
  ];
49
55
  const parser = new XMLParser({
50
56
  ...parserConfig,
51
- stopNodes
57
+ stopNodes: stopNodes.map((node) => new Expression(node))
52
58
  });
53
59
  const normalizeNamespaces = createNamespaceNormalizator(namespaceUris, namespacePrefixes);
54
60
  //#endregion
@@ -1,8 +1,9 @@
1
1
  const require_utils = require("../../../common/utils.cjs");
2
2
  //#region src/namespaces/georss/parse/utils.ts
3
+ const whitespaceRegex = /\s+/;
3
4
  const parseLatLngPairs = (value, pairsCount) => {
4
5
  if (!require_utils.isNonEmptyString(value)) return;
5
- const rawParts = value.split(/\s+/);
6
+ const rawParts = value.split(whitespaceRegex);
6
7
  const numericParts = require_utils.parseArrayOf(rawParts, require_utils.parseNumber);
7
8
  if (!numericParts || numericParts.length % 2 !== 0 || rawParts.length !== numericParts.length) return;
8
9
  const actualPairCount = numericParts.length / 2;
@@ -1,8 +1,9 @@
1
1
  import { isNonEmptyString, isObject, isPresent, parseArrayOf, parseNumber, parseSingularOf, parseString, retrieveText, trimObject } from "../../../common/utils.js";
2
2
  //#region src/namespaces/georss/parse/utils.ts
3
+ const whitespaceRegex = /\s+/;
3
4
  const parseLatLngPairs = (value, pairsCount) => {
4
5
  if (!isNonEmptyString(value)) return;
5
- const rawParts = value.split(/\s+/);
6
+ const rawParts = value.split(whitespaceRegex);
6
7
  const numericParts = parseArrayOf(rawParts, parseNumber);
7
8
  if (!numericParts || numericParts.length % 2 !== 0 || rawParts.length !== numericParts.length) return;
8
9
  const actualPairCount = numericParts.length / 2;
@@ -1,5 +1,7 @@
1
1
  const require_utils = require("../../../common/utils.cjs");
2
2
  //#region src/namespaces/itunes/parse/utils.ts
3
+ const explicitOrYesRegex = /^\p{White_Space}*(explicit|yes)\p{White_Space}*$/iu;
4
+ const durationRegex = /^(?:(\d+):)?(\d+):(\d+)$/;
3
5
  const parseCategory = (value) => {
4
6
  if (!require_utils.isObject(value)) return;
5
7
  return require_utils.trimObject({
@@ -14,7 +16,6 @@ const parseOwner = (value) => {
14
16
  email: require_utils.parseSingularOf(value["itunes:email"], (value) => require_utils.parseString(require_utils.retrieveText(value)))
15
17
  });
16
18
  };
17
- const explicitOrYesRegex = /^\p{White_Space}*(explicit|yes)\p{White_Space}*$/iu;
18
19
  const parseExplicit = (value) => {
19
20
  const boolean = require_utils.parseBoolean(value);
20
21
  if (boolean !== void 0) return boolean;
@@ -24,7 +25,7 @@ const parseDuration = (value) => {
24
25
  const duration = require_utils.parseNumber(value);
25
26
  if (duration !== void 0) return duration;
26
27
  if (typeof value !== "string") return;
27
- const match = value.match(/^(?:(\d+):)?(\d+):(\d+)$/);
28
+ const match = value.match(durationRegex);
28
29
  if (match) {
29
30
  const [, hours, minutes, seconds] = match;
30
31
  return Number(hours || 0) * 3600 + Number(minutes) * 60 + Number(seconds);
@@ -1,5 +1,7 @@
1
1
  import { isNonEmptyStringOrNumber, isObject, parseArrayOf, parseBoolean, parseCsvOf, parseNumber, parseSingularOf, parseString, parseYesNoBoolean, retrieveText, trimObject } from "../../../common/utils.js";
2
2
  //#region src/namespaces/itunes/parse/utils.ts
3
+ const explicitOrYesRegex = /^\p{White_Space}*(explicit|yes)\p{White_Space}*$/iu;
4
+ const durationRegex = /^(?:(\d+):)?(\d+):(\d+)$/;
3
5
  const parseCategory = (value) => {
4
6
  if (!isObject(value)) return;
5
7
  return trimObject({
@@ -14,7 +16,6 @@ const parseOwner = (value) => {
14
16
  email: parseSingularOf(value["itunes:email"], (value) => parseString(retrieveText(value)))
15
17
  });
16
18
  };
17
- const explicitOrYesRegex = /^\p{White_Space}*(explicit|yes)\p{White_Space}*$/iu;
18
19
  const parseExplicit = (value) => {
19
20
  const boolean = parseBoolean(value);
20
21
  if (boolean !== void 0) return boolean;
@@ -24,7 +25,7 @@ const parseDuration = (value) => {
24
25
  const duration = parseNumber(value);
25
26
  if (duration !== void 0) return duration;
26
27
  if (typeof value !== "string") return;
27
- const match = value.match(/^(?:(\d+):)?(\d+):(\d+)$/);
28
+ const match = value.match(durationRegex);
28
29
  if (match) {
29
30
  const [, hours, minutes, seconds] = match;
30
31
  return Number(hours || 0) * 3600 + Number(minutes) * 60 + Number(seconds);
@@ -1,5 +1,7 @@
1
1
  const require_utils = require("../../../common/utils.cjs");
2
2
  //#region src/namespaces/podcast/parse/utils.ts
3
+ const whitespaceRegex = /\s+/;
4
+ const trailingWRegex = /w$/;
3
5
  const parseTranscript = (value) => {
4
6
  if (!require_utils.isObject(value)) return;
5
7
  return require_utils.trimObject({
@@ -154,10 +156,10 @@ const parseImages = (value) => {
154
156
  const images = [];
155
157
  const segments = srcset.split(",");
156
158
  for (const segment of segments) {
157
- const [href, width] = segment.trim().split(/\s+/);
159
+ const [href, width] = segment.trim().split(whitespaceRegex);
158
160
  const image = {
159
161
  href: require_utils.parseString(href),
160
- width: require_utils.parseNumber(width?.replace(/w$/, ""))
162
+ width: require_utils.parseNumber(width?.replace(trailingWRegex, ""))
161
163
  };
162
164
  images.push(image);
163
165
  }
@@ -1,5 +1,7 @@
1
1
  import { isObject, parseArrayOf, parseBoolean, parseDate, parseNumber, parseSingularOf, parseString, parseYesNoBoolean, retrieveText, trimArray, trimObject } from "../../../common/utils.js";
2
2
  //#region src/namespaces/podcast/parse/utils.ts
3
+ const whitespaceRegex = /\s+/;
4
+ const trailingWRegex = /w$/;
3
5
  const parseTranscript = (value) => {
4
6
  if (!isObject(value)) return;
5
7
  return trimObject({
@@ -154,10 +156,10 @@ const parseImages = (value) => {
154
156
  const images = [];
155
157
  const segments = srcset.split(",");
156
158
  for (const segment of segments) {
157
- const [href, width] = segment.trim().split(/\s+/);
159
+ const [href, width] = segment.trim().split(whitespaceRegex);
158
160
  const image = {
159
161
  href: parseString(href),
160
- width: parseNumber(width?.replace(/w$/, ""))
162
+ width: parseNumber(width?.replace(trailingWRegex, ""))
161
163
  };
162
164
  images.push(image);
163
165
  }
@@ -31,7 +31,7 @@ const parseSubscribe = (value) => {
31
31
  if (!require_utils.isObject(value)) return;
32
32
  const subscribe = {};
33
33
  for (const key in value) if (key.startsWith("@")) {
34
- const attrName = key.substring(1);
34
+ const attrName = key.slice(1);
35
35
  const attrValue = require_utils.parseString(value[key]);
36
36
  if (attrValue) subscribe[attrName] = attrValue;
37
37
  }
@@ -31,7 +31,7 @@ const parseSubscribe = (value) => {
31
31
  if (!isObject(value)) return;
32
32
  const subscribe = {};
33
33
  for (const key in value) if (key.startsWith("@")) {
34
- const attrName = key.substring(1);
34
+ const attrName = key.slice(1);
35
35
  const attrValue = parseString(value[key]);
36
36
  if (attrValue) subscribe[attrName] = attrValue;
37
37
  }
@@ -0,0 +1,153 @@
1
+ //#region node_modules/path-expression-matcher/src/Expression.js
2
+ /**
3
+ * Expression - Parses and stores a tag pattern expression
4
+ *
5
+ * Patterns are parsed once and stored in an optimized structure for fast matching.
6
+ *
7
+ * @example
8
+ * const expr = new Expression("root.users.user");
9
+ * const expr2 = new Expression("..user[id]:first");
10
+ * const expr3 = new Expression("root/users/user", { separator: '/' });
11
+ */
12
+ var Expression = class {
13
+ /**
14
+ * Create a new Expression
15
+ * @param {string} pattern - Pattern string (e.g., "root.users.user", "..user[id]")
16
+ * @param {Object} options - Configuration options
17
+ * @param {string} options.separator - Path separator (default: '.')
18
+ */
19
+ constructor(pattern, options = {}, data) {
20
+ this.pattern = pattern;
21
+ this.separator = options.separator || ".";
22
+ this.segments = this._parse(pattern);
23
+ this.data = data;
24
+ this._hasDeepWildcard = this.segments.some((seg) => seg.type === "deep-wildcard");
25
+ this._hasAttributeCondition = this.segments.some((seg) => seg.attrName !== void 0);
26
+ this._hasPositionSelector = this.segments.some((seg) => seg.position !== void 0);
27
+ }
28
+ /**
29
+ * Parse pattern string into segments
30
+ * @private
31
+ * @param {string} pattern - Pattern to parse
32
+ * @returns {Array} Array of segment objects
33
+ */
34
+ _parse(pattern) {
35
+ const segments = [];
36
+ let i = 0;
37
+ let currentPart = "";
38
+ while (i < pattern.length) if (pattern[i] === this.separator) if (i + 1 < pattern.length && pattern[i + 1] === this.separator) {
39
+ if (currentPart.trim()) {
40
+ segments.push(this._parseSegment(currentPart.trim()));
41
+ currentPart = "";
42
+ }
43
+ segments.push({ type: "deep-wildcard" });
44
+ i += 2;
45
+ } else {
46
+ if (currentPart.trim()) segments.push(this._parseSegment(currentPart.trim()));
47
+ currentPart = "";
48
+ i++;
49
+ }
50
+ else {
51
+ currentPart += pattern[i];
52
+ i++;
53
+ }
54
+ if (currentPart.trim()) segments.push(this._parseSegment(currentPart.trim()));
55
+ return segments;
56
+ }
57
+ /**
58
+ * Parse a single segment
59
+ * @private
60
+ * @param {string} part - Segment string (e.g., "user", "ns::user", "user[id]", "ns::user:first")
61
+ * @returns {Object} Segment object
62
+ */
63
+ _parseSegment(part) {
64
+ const segment = { type: "tag" };
65
+ let bracketContent = null;
66
+ let withoutBrackets = part;
67
+ const bracketMatch = part.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);
68
+ if (bracketMatch) {
69
+ withoutBrackets = bracketMatch[1] + bracketMatch[3];
70
+ if (bracketMatch[2]) {
71
+ const content = bracketMatch[2].slice(1, -1);
72
+ if (content) bracketContent = content;
73
+ }
74
+ }
75
+ let namespace = void 0;
76
+ let tagAndPosition = withoutBrackets;
77
+ if (withoutBrackets.includes("::")) {
78
+ const nsIndex = withoutBrackets.indexOf("::");
79
+ namespace = withoutBrackets.substring(0, nsIndex).trim();
80
+ tagAndPosition = withoutBrackets.substring(nsIndex + 2).trim();
81
+ if (!namespace) throw new Error(`Invalid namespace in pattern: ${part}`);
82
+ }
83
+ let tag = void 0;
84
+ let positionMatch = null;
85
+ if (tagAndPosition.includes(":")) {
86
+ const colonIndex = tagAndPosition.lastIndexOf(":");
87
+ const tagPart = tagAndPosition.substring(0, colonIndex).trim();
88
+ const posPart = tagAndPosition.substring(colonIndex + 1).trim();
89
+ if ([
90
+ "first",
91
+ "last",
92
+ "odd",
93
+ "even"
94
+ ].includes(posPart) || /^nth\(\d+\)$/.test(posPart)) {
95
+ tag = tagPart;
96
+ positionMatch = posPart;
97
+ } else tag = tagAndPosition;
98
+ } else tag = tagAndPosition;
99
+ if (!tag) throw new Error(`Invalid segment pattern: ${part}`);
100
+ segment.tag = tag;
101
+ if (namespace) segment.namespace = namespace;
102
+ if (bracketContent) if (bracketContent.includes("=")) {
103
+ const eqIndex = bracketContent.indexOf("=");
104
+ segment.attrName = bracketContent.substring(0, eqIndex).trim();
105
+ segment.attrValue = bracketContent.substring(eqIndex + 1).trim();
106
+ } else segment.attrName = bracketContent.trim();
107
+ if (positionMatch) {
108
+ const nthMatch = positionMatch.match(/^nth\((\d+)\)$/);
109
+ if (nthMatch) {
110
+ segment.position = "nth";
111
+ segment.positionValue = parseInt(nthMatch[1], 10);
112
+ } else segment.position = positionMatch;
113
+ }
114
+ return segment;
115
+ }
116
+ /**
117
+ * Get the number of segments
118
+ * @returns {number}
119
+ */
120
+ get length() {
121
+ return this.segments.length;
122
+ }
123
+ /**
124
+ * Check if expression contains deep wildcard
125
+ * @returns {boolean}
126
+ */
127
+ hasDeepWildcard() {
128
+ return this._hasDeepWildcard;
129
+ }
130
+ /**
131
+ * Check if expression has attribute conditions
132
+ * @returns {boolean}
133
+ */
134
+ hasAttributeCondition() {
135
+ return this._hasAttributeCondition;
136
+ }
137
+ /**
138
+ * Check if expression has position selectors
139
+ * @returns {boolean}
140
+ */
141
+ hasPositionSelector() {
142
+ return this._hasPositionSelector;
143
+ }
144
+ /**
145
+ * Get string representation
146
+ * @returns {string}
147
+ */
148
+ toString() {
149
+ return this.pattern;
150
+ }
151
+ };
152
+ //#endregion
153
+ exports.default = Expression;
@@ -0,0 +1,153 @@
1
+ //#region node_modules/path-expression-matcher/src/Expression.js
2
+ /**
3
+ * Expression - Parses and stores a tag pattern expression
4
+ *
5
+ * Patterns are parsed once and stored in an optimized structure for fast matching.
6
+ *
7
+ * @example
8
+ * const expr = new Expression("root.users.user");
9
+ * const expr2 = new Expression("..user[id]:first");
10
+ * const expr3 = new Expression("root/users/user", { separator: '/' });
11
+ */
12
+ var Expression = class {
13
+ /**
14
+ * Create a new Expression
15
+ * @param {string} pattern - Pattern string (e.g., "root.users.user", "..user[id]")
16
+ * @param {Object} options - Configuration options
17
+ * @param {string} options.separator - Path separator (default: '.')
18
+ */
19
+ constructor(pattern, options = {}, data) {
20
+ this.pattern = pattern;
21
+ this.separator = options.separator || ".";
22
+ this.segments = this._parse(pattern);
23
+ this.data = data;
24
+ this._hasDeepWildcard = this.segments.some((seg) => seg.type === "deep-wildcard");
25
+ this._hasAttributeCondition = this.segments.some((seg) => seg.attrName !== void 0);
26
+ this._hasPositionSelector = this.segments.some((seg) => seg.position !== void 0);
27
+ }
28
+ /**
29
+ * Parse pattern string into segments
30
+ * @private
31
+ * @param {string} pattern - Pattern to parse
32
+ * @returns {Array} Array of segment objects
33
+ */
34
+ _parse(pattern) {
35
+ const segments = [];
36
+ let i = 0;
37
+ let currentPart = "";
38
+ while (i < pattern.length) if (pattern[i] === this.separator) if (i + 1 < pattern.length && pattern[i + 1] === this.separator) {
39
+ if (currentPart.trim()) {
40
+ segments.push(this._parseSegment(currentPart.trim()));
41
+ currentPart = "";
42
+ }
43
+ segments.push({ type: "deep-wildcard" });
44
+ i += 2;
45
+ } else {
46
+ if (currentPart.trim()) segments.push(this._parseSegment(currentPart.trim()));
47
+ currentPart = "";
48
+ i++;
49
+ }
50
+ else {
51
+ currentPart += pattern[i];
52
+ i++;
53
+ }
54
+ if (currentPart.trim()) segments.push(this._parseSegment(currentPart.trim()));
55
+ return segments;
56
+ }
57
+ /**
58
+ * Parse a single segment
59
+ * @private
60
+ * @param {string} part - Segment string (e.g., "user", "ns::user", "user[id]", "ns::user:first")
61
+ * @returns {Object} Segment object
62
+ */
63
+ _parseSegment(part) {
64
+ const segment = { type: "tag" };
65
+ let bracketContent = null;
66
+ let withoutBrackets = part;
67
+ const bracketMatch = part.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);
68
+ if (bracketMatch) {
69
+ withoutBrackets = bracketMatch[1] + bracketMatch[3];
70
+ if (bracketMatch[2]) {
71
+ const content = bracketMatch[2].slice(1, -1);
72
+ if (content) bracketContent = content;
73
+ }
74
+ }
75
+ let namespace = void 0;
76
+ let tagAndPosition = withoutBrackets;
77
+ if (withoutBrackets.includes("::")) {
78
+ const nsIndex = withoutBrackets.indexOf("::");
79
+ namespace = withoutBrackets.substring(0, nsIndex).trim();
80
+ tagAndPosition = withoutBrackets.substring(nsIndex + 2).trim();
81
+ if (!namespace) throw new Error(`Invalid namespace in pattern: ${part}`);
82
+ }
83
+ let tag = void 0;
84
+ let positionMatch = null;
85
+ if (tagAndPosition.includes(":")) {
86
+ const colonIndex = tagAndPosition.lastIndexOf(":");
87
+ const tagPart = tagAndPosition.substring(0, colonIndex).trim();
88
+ const posPart = tagAndPosition.substring(colonIndex + 1).trim();
89
+ if ([
90
+ "first",
91
+ "last",
92
+ "odd",
93
+ "even"
94
+ ].includes(posPart) || /^nth\(\d+\)$/.test(posPart)) {
95
+ tag = tagPart;
96
+ positionMatch = posPart;
97
+ } else tag = tagAndPosition;
98
+ } else tag = tagAndPosition;
99
+ if (!tag) throw new Error(`Invalid segment pattern: ${part}`);
100
+ segment.tag = tag;
101
+ if (namespace) segment.namespace = namespace;
102
+ if (bracketContent) if (bracketContent.includes("=")) {
103
+ const eqIndex = bracketContent.indexOf("=");
104
+ segment.attrName = bracketContent.substring(0, eqIndex).trim();
105
+ segment.attrValue = bracketContent.substring(eqIndex + 1).trim();
106
+ } else segment.attrName = bracketContent.trim();
107
+ if (positionMatch) {
108
+ const nthMatch = positionMatch.match(/^nth\((\d+)\)$/);
109
+ if (nthMatch) {
110
+ segment.position = "nth";
111
+ segment.positionValue = parseInt(nthMatch[1], 10);
112
+ } else segment.position = positionMatch;
113
+ }
114
+ return segment;
115
+ }
116
+ /**
117
+ * Get the number of segments
118
+ * @returns {number}
119
+ */
120
+ get length() {
121
+ return this.segments.length;
122
+ }
123
+ /**
124
+ * Check if expression contains deep wildcard
125
+ * @returns {boolean}
126
+ */
127
+ hasDeepWildcard() {
128
+ return this._hasDeepWildcard;
129
+ }
130
+ /**
131
+ * Check if expression has attribute conditions
132
+ * @returns {boolean}
133
+ */
134
+ hasAttributeCondition() {
135
+ return this._hasAttributeCondition;
136
+ }
137
+ /**
138
+ * Check if expression has position selectors
139
+ * @returns {boolean}
140
+ */
141
+ hasPositionSelector() {
142
+ return this._hasPositionSelector;
143
+ }
144
+ /**
145
+ * Get string representation
146
+ * @returns {string}
147
+ */
148
+ toString() {
149
+ return this.pattern;
150
+ }
151
+ };
152
+ //#endregion
153
+ export { Expression as default };
@@ -1,24 +1,25 @@
1
1
  const require_config = require("../../common/config.cjs");
2
+ const require_Expression = require("../../node_modules/path-expression-matcher/src/Expression.cjs");
2
3
  let fast_xml_parser = require("fast-xml-parser");
3
4
  //#region src/opml/parse/config.ts
4
5
  const stopNodes = [
5
6
  "opml.head.title",
6
- "opml.head.dateCreated",
7
- "opml.head.dateModified",
8
- "opml.head.ownerName",
9
- "opml.head.ownerEmail",
10
- "opml.head.ownerId",
7
+ "opml.head.datecreated",
8
+ "opml.head.datemodified",
9
+ "opml.head.ownername",
10
+ "opml.head.owneremail",
11
+ "opml.head.ownerid",
11
12
  "opml.head.docs",
12
- "opml.head.expansionState",
13
- "opml.head.vertScrollState",
14
- "opml.head.windowTop",
15
- "opml.head.windowLeft",
16
- "opml.head.windowBottom",
17
- "opml.head.windowRight"
13
+ "opml.head.expansionstate",
14
+ "opml.head.vertscrollstate",
15
+ "opml.head.windowtop",
16
+ "opml.head.windowleft",
17
+ "opml.head.windowbottom",
18
+ "opml.head.windowright"
18
19
  ];
19
20
  const parser = new fast_xml_parser.XMLParser({
20
21
  ...require_config.parserConfig,
21
- stopNodes
22
+ stopNodes: stopNodes.map((node) => new require_Expression.default(node))
22
23
  });
23
24
  //#endregion
24
25
  exports.parser = parser;
@@ -1,24 +1,25 @@
1
1
  import { parserConfig } from "../../common/config.js";
2
+ import Expression from "../../node_modules/path-expression-matcher/src/Expression.js";
2
3
  import { XMLParser } from "fast-xml-parser";
3
4
  //#region src/opml/parse/config.ts
4
5
  const stopNodes = [
5
6
  "opml.head.title",
6
- "opml.head.dateCreated",
7
- "opml.head.dateModified",
8
- "opml.head.ownerName",
9
- "opml.head.ownerEmail",
10
- "opml.head.ownerId",
7
+ "opml.head.datecreated",
8
+ "opml.head.datemodified",
9
+ "opml.head.ownername",
10
+ "opml.head.owneremail",
11
+ "opml.head.ownerid",
11
12
  "opml.head.docs",
12
- "opml.head.expansionState",
13
- "opml.head.vertScrollState",
14
- "opml.head.windowTop",
15
- "opml.head.windowLeft",
16
- "opml.head.windowBottom",
17
- "opml.head.windowRight"
13
+ "opml.head.expansionstate",
14
+ "opml.head.vertscrollstate",
15
+ "opml.head.windowtop",
16
+ "opml.head.windowleft",
17
+ "opml.head.windowbottom",
18
+ "opml.head.windowright"
18
19
  ];
19
20
  const parser = new XMLParser({
20
21
  ...parserConfig,
21
- stopNodes
22
+ stopNodes: stopNodes.map((node) => new Expression(node))
22
23
  });
23
24
  //#endregion
24
25
  export { parser };
package/package.json CHANGED
@@ -72,13 +72,13 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "entities": "^7.0.1",
75
- "fast-xml-parser": "~5.4.2"
75
+ "fast-xml-parser": "~5.5.12"
76
76
  },
77
77
  "devDependencies": {
78
- "@types/bun": "^1.3.10",
79
- "kvalita": "^1.10.0",
80
- "tsdown": "^0.21.2",
81
- "vitepress": "^1.6.4"
78
+ "@types/bun": "^1.3.12",
79
+ "kvalita": "^1.12.4",
80
+ "tsdown": "^0.21.8",
81
+ "vitepress": "^2.0.0-alpha.17"
82
82
  },
83
- "version": "2.9.1"
83
+ "version": "2.9.2"
84
84
  }