feedsmith 2.9.1 → 2.9.3

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
@@ -3,7 +3,11 @@ const require_utils = require("../../../common/utils.cjs");
3
3
  let fast_xml_parser = require("fast-xml-parser");
4
4
  //#region src/feeds/atom/parse/config.ts
5
5
  const stopNodes = [
6
- ...require_config.namespaceStopNodes,
6
+ ...require_utils.expandStopNodes(require_config.namespaceStopNodes, [
7
+ "feed",
8
+ "feed.entry",
9
+ "feed.entry.source"
10
+ ]),
7
11
  "feed.author.name",
8
12
  "feed.author.uri",
9
13
  "feed.author.url",
@@ -1,9 +1,13 @@
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
3
  import { XMLParser } from "fast-xml-parser";
4
4
  //#region src/feeds/atom/parse/config.ts
5
5
  const stopNodes = [
6
- ...namespaceStopNodes,
6
+ ...expandStopNodes(namespaceStopNodes, [
7
+ "feed",
8
+ "feed.entry",
9
+ "feed.entry.source"
10
+ ]),
7
11
  "feed.author.name",
8
12
  "feed.author.uri",
9
13
  "feed.author.url",
@@ -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
@@ -3,7 +3,12 @@ const require_utils = require("../../../common/utils.cjs");
3
3
  let fast_xml_parser = require("fast-xml-parser");
4
4
  //#region src/feeds/rdf/parse/config.ts
5
5
  const stopNodes = [
6
- ...require_config.namespaceStopNodes,
6
+ ...require_utils.expandStopNodes(require_config.namespaceStopNodes, [
7
+ "rdf:rdf.channel",
8
+ "rdf:rdf.item",
9
+ "rdf:rdf.image",
10
+ "rdf:rdf.textinput"
11
+ ]),
7
12
  "rdf:rdf.channel.title",
8
13
  "rdf:rdf.channel.link",
9
14
  "rdf:rdf.channel.description",
@@ -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
3
  import { XMLParser } from "fast-xml-parser";
4
4
  //#region src/feeds/rdf/parse/config.ts
5
5
  const stopNodes = [
6
- ...namespaceStopNodes,
6
+ ...expandStopNodes(namespaceStopNodes, [
7
+ "rdf:rdf.channel",
8
+ "rdf:rdf.item",
9
+ "rdf:rdf.image",
10
+ "rdf:rdf.textinput"
11
+ ]),
7
12
  "rdf:rdf.channel.title",
8
13
  "rdf:rdf.channel.link",
9
14
  "rdf:rdf.channel.description",
@@ -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
@@ -25,7 +25,12 @@ const sharedStopNodes = [
25
25
  "item.source"
26
26
  ];
27
27
  const stopNodes = [
28
- ...require_config.namespaceStopNodes,
28
+ ...require_utils.expandStopNodes(require_config.namespaceStopNodes, [
29
+ "rss.channel",
30
+ "rss.channel.item",
31
+ "rss",
32
+ "rss.item"
33
+ ]),
29
34
  "rss.channel.title",
30
35
  "rss.channel.link",
31
36
  "rss.channel.description",
@@ -1,5 +1,5 @@
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
3
  import { XMLParser } from "fast-xml-parser";
4
4
  //#region src/feeds/rss/parse/config.ts
5
5
  const sharedStopNodes = [
@@ -25,7 +25,12 @@ const sharedStopNodes = [
25
25
  "item.source"
26
26
  ];
27
27
  const stopNodes = [
28
- ...namespaceStopNodes,
28
+ ...expandStopNodes(namespaceStopNodes, [
29
+ "rss.channel",
30
+ "rss.channel.item",
31
+ "rss",
32
+ "rss.item"
33
+ ]),
29
34
  "rss.channel.title",
30
35
  "rss.channel.link",
31
36
  "rss.channel.description",
@@ -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
  }
@@ -3,18 +3,18 @@ let fast_xml_parser = require("fast-xml-parser");
3
3
  //#region src/opml/parse/config.ts
4
4
  const stopNodes = [
5
5
  "opml.head.title",
6
- "opml.head.dateCreated",
7
- "opml.head.dateModified",
8
- "opml.head.ownerName",
9
- "opml.head.ownerEmail",
10
- "opml.head.ownerId",
6
+ "opml.head.datecreated",
7
+ "opml.head.datemodified",
8
+ "opml.head.ownername",
9
+ "opml.head.owneremail",
10
+ "opml.head.ownerid",
11
11
  "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"
12
+ "opml.head.expansionstate",
13
+ "opml.head.vertscrollstate",
14
+ "opml.head.windowtop",
15
+ "opml.head.windowleft",
16
+ "opml.head.windowbottom",
17
+ "opml.head.windowright"
18
18
  ];
19
19
  const parser = new fast_xml_parser.XMLParser({
20
20
  ...require_config.parserConfig,
@@ -3,18 +3,18 @@ import { XMLParser } from "fast-xml-parser";
3
3
  //#region src/opml/parse/config.ts
4
4
  const stopNodes = [
5
5
  "opml.head.title",
6
- "opml.head.dateCreated",
7
- "opml.head.dateModified",
8
- "opml.head.ownerName",
9
- "opml.head.ownerEmail",
10
- "opml.head.ownerId",
6
+ "opml.head.datecreated",
7
+ "opml.head.datemodified",
8
+ "opml.head.ownername",
9
+ "opml.head.owneremail",
10
+ "opml.head.ownerid",
11
11
  "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"
12
+ "opml.head.expansionstate",
13
+ "opml.head.vertscrollstate",
14
+ "opml.head.windowtop",
15
+ "opml.head.windowleft",
16
+ "opml.head.windowbottom",
17
+ "opml.head.windowright"
18
18
  ];
19
19
  const parser = new XMLParser({
20
20
  ...parserConfig,
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.7.1"
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.9",
81
+ "vitepress": "^2.0.0-alpha.17"
82
82
  },
83
- "version": "2.9.1"
83
+ "version": "2.9.3"
84
84
  }