feedsmith 2.6.0 → 2.7.0

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.
Files changed (50) hide show
  1. package/README.md +37 -33
  2. package/dist/common/config.cjs +50 -0
  3. package/dist/common/config.js +50 -0
  4. package/dist/common/parse.cjs +4 -2
  5. package/dist/common/parse.js +4 -2
  6. package/dist/common/utils.cjs +12 -1
  7. package/dist/common/utils.js +12 -2
  8. package/dist/feeds/json/detect/index.cjs +3 -2
  9. package/dist/feeds/json/detect/index.js +4 -3
  10. package/dist/feeds/json/parse/index.cjs +5 -3
  11. package/dist/feeds/json/parse/index.js +4 -2
  12. package/dist/feeds/rdf/common/types.d.cts +5 -0
  13. package/dist/feeds/rdf/common/types.d.ts +5 -0
  14. package/dist/feeds/rdf/parse/utils.cjs +21 -4
  15. package/dist/feeds/rdf/parse/utils.js +22 -5
  16. package/dist/feeds/rss/common/types.d.cts +8 -0
  17. package/dist/feeds/rss/common/types.d.ts +8 -0
  18. package/dist/feeds/rss/generate/utils.cjs +32 -24
  19. package/dist/feeds/rss/generate/utils.js +55 -47
  20. package/dist/feeds/rss/parse/utils.cjs +26 -18
  21. package/dist/feeds/rss/parse/utils.js +53 -45
  22. package/dist/namespaces/acast/common/types.d.cts +29 -0
  23. package/dist/namespaces/acast/common/types.d.ts +29 -0
  24. package/dist/namespaces/acast/generate/utils.cjs +43 -0
  25. package/dist/namespaces/acast/generate/utils.js +42 -0
  26. package/dist/namespaces/acast/parse/utils.cjs +43 -0
  27. package/dist/namespaces/acast/parse/utils.js +42 -0
  28. package/dist/namespaces/blogchannel/common/types.d.cts +10 -0
  29. package/dist/namespaces/blogchannel/common/types.d.ts +10 -0
  30. package/dist/namespaces/blogchannel/generate/utils.cjs +14 -0
  31. package/dist/namespaces/blogchannel/generate/utils.js +14 -0
  32. package/dist/namespaces/blogchannel/parse/utils.cjs +14 -0
  33. package/dist/namespaces/blogchannel/parse/utils.js +14 -0
  34. package/dist/namespaces/podcast/common/types.d.cts +12 -2
  35. package/dist/namespaces/podcast/common/types.d.ts +12 -2
  36. package/dist/namespaces/podcast/generate/utils.cjs +13 -5
  37. package/dist/namespaces/podcast/generate/utils.js +13 -5
  38. package/dist/namespaces/podcast/parse/utils.cjs +30 -4
  39. package/dist/namespaces/podcast/parse/utils.js +31 -5
  40. package/dist/namespaces/prism/common/types.d.cts +156 -0
  41. package/dist/namespaces/prism/common/types.d.ts +156 -0
  42. package/dist/namespaces/prism/generate/utils.cjs +154 -0
  43. package/dist/namespaces/prism/generate/utils.js +153 -0
  44. package/dist/namespaces/prism/parse/utils.cjs +154 -0
  45. package/dist/namespaces/prism/parse/utils.js +153 -0
  46. package/dist/namespaces/rdf/common/types.d.cts +19 -0
  47. package/dist/namespaces/rdf/common/types.d.ts +19 -0
  48. package/dist/namespaces/rdf/parse/utils.cjs +10 -0
  49. package/dist/namespaces/rdf/parse/utils.js +10 -0
  50. package/package.json +5 -5
package/README.md CHANGED
@@ -63,45 +63,49 @@ Feedsmith aims to fully support all major feed formats and namespaces in complet
63
63
  | [RDF](https://web.resource.org/rss/1.0/spec) | 0.9, 1.0 | ✅ | 📋 |
64
64
  | [JSON Feed](https://jsonfeed.org) | 1.0, 1.1 | ✅ | ✅ |
65
65
 
66
- ### Namespaces
67
-
68
- | Name | Prefix | Supported in | Parsing | Generating |
69
- |------|---------|--------------|---------|------------|
70
- | [Atom](http://www.w3.org/2005/Atom) | `<atom:*>` | RSS, RDF | ✅ | ✅ |
71
- | [Dublin Core](http://purl.org/dc/elements/1.1/) | `<dc:*>` | RSS, Atom, RDF | ✅ | ✅ |
72
- | [Dublin Core Terms](http://purl.org/dc/terms/) | `<dcterms:*>` | RSS, Atom, RDF | ✅ | ✅ |
73
- | [Syndication](http://purl.org/rss/1.0/modules/syndication/) | `<sy:*>` | RSS, Atom, RDF | ✅ | ✅ |
74
- | [Content](http://purl.org/rss/1.0/modules/content/) | `<content:*>` | RSS, RDF | ✅ | ✅ |
75
- | [Slash](http://purl.org/rss/1.0/modules/slash/) | `<slash:*>` | RSS, Atom, RDF | ✅ | ✅ |
76
- | [iTunes](http://www.itunes.com/dtds/podcast-1.0.dtd) | `<itunes:*>` | RSS, Atom | ✅ | ✅ |
77
- | [Podcast Index](https://podcastindex.org/namespace/1.0) | `<podcast:*>` | RSS | ✅ | ✅ |
78
- | [Podlove Simple Chapters](http://podlove.org/simple-chapters) | `<psc:*>` | RSS, Atom | ✅ | ✅ |
79
- | [Media RSS](http://search.yahoo.com/mrss/) | `<media:*>` | RSS, Atom, RDF | ✅ | ✅ |
80
- | [Google Play Podcast](https://www.google.com/schemas/play-podcasts/1.0/) | `<googleplay:*>` | RSS, Atom | ✅ | ✅ |
81
- | [Spotify](http://www.spotify.com/ns/rss) | `<spotify:*>` | RSS | ✅ | ✅ |
82
- | [RawVoice](https://blubrry.com/developer/rawvoice-rss/) | `<rawvoice:*>` | RSS | ✅ | ✅ |
83
- | [FeedPress](https://feedpress.com/xmlns) | `<feedpress:*>` | RSS | ✅ | ✅ |
84
- | [arXiv](http://arxiv.org/schemas/atom) | `<arxiv:*>` | Atom | ✅ | ✅ |
85
- | [OpenSearch](http://a9.com/-/spec/opensearch/1.1/) | `<opensearch:*>` | RSS, Atom | ✅ | ✅ |
86
- | [ccREL](http://creativecommons.org/ns#) | `<cc:*>` | RSS, Atom | ✅ | ✅ |
87
- | [Creative Commons](http://backend.userland.com/creativeCommonsRssModule) | `<creativeCommons:*>` | RSS, Atom | ✅ | ✅ |
88
- | [Atom Threading](https://www.ietf.org/rfc/rfc4685.txt) | `<thr:*>` | RSS, Atom | ✅ | ✅ |
89
- | [Atom Publishing Protocol](http://www.w3.org/2007/app) | `<app:*>` | Atom | ✅ | ✅ |
90
- | [Comment API](http://wellformedweb.org/CommentAPI/) | `<wfw:*>` | RSS, Atom, RDF | ✅ | ✅ |
91
- | [Administrative](http://webns.net/mvcb/) | `<admin:*>` | RSS, Atom, RDF | ✅ | ✅ |
92
- | [Pingback](http://madskills.com/public/xml/rss/module/pingback/) | `<pingback:*>` | RSS, Atom | ✅ | ✅ |
93
- | [Trackback](http://madskills.com/public/xml/rss/module/trackback/) | `<trackback:*>` | RSS, Atom | ✅ | ✅ |
94
- | [Source](http://source.scripting.com/) | `<source:*>` | RSS | ✅ | ✅ |
95
- | [YouTube](https://www.youtube.com/feeds/videos.xml) | `<yt:*>` | Atom | ✅ | ✅ |
96
- | [W3C Basic Geo](http://www.w3.org/2003/01/geo/wgs84_pos#) | `<geo:*>` | RSS, Atom | ✅ | ✅ |
97
- | [GeoRSS Simple](http://www.georss.org/georss) | `<georss:*>` | RSS, Atom, RDF | ✅ | ✅ |
98
-
99
66
  ### Other
100
67
 
101
68
  | Format | Versions | Parsing | Generating |
102
69
  |--------|----------|---------|------------|
103
70
  | [OPML](https://opml.org/) | 1.0, 2.0 | ✅ | ✅ |
104
71
 
72
+ ### Feed Namespaces
73
+
74
+ | Name | Prefix | Supported in | Parsing | Generating |
75
+ |------|---------|--------------|---------|------------|
76
+ | [Atom](https://feedsmith.dev/reference/namespaces/atom) | `<atom:*>` | RSS, RDF | ✅ | ✅ |
77
+ | [Dublin Core](https://feedsmith.dev/reference/namespaces/dc) | `<dc:*>` | RSS, Atom, RDF | ✅ | ✅ |
78
+ | [Dublin Core Terms](https://feedsmith.dev/reference/namespaces/dcterms) | `<dcterms:*>` | RSS, Atom, RDF | ✅ | ✅ |
79
+ | [Syndication](https://feedsmith.dev/reference/namespaces/sy) | `<sy:*>` | RSS, Atom, RDF | ✅ | ✅ |
80
+ | [Content](https://feedsmith.dev/reference/namespaces/content) | `<content:*>` | RSS, RDF | ✅ | ✅ |
81
+ | [Slash](https://feedsmith.dev/reference/namespaces/slash) | `<slash:*>` | RSS, Atom, RDF | ✅ | ✅ |
82
+ | [iTunes](https://feedsmith.dev/reference/namespaces/itunes) | `<itunes:*>` | RSS, Atom | ✅ | ✅ |
83
+ | [Podcast Index](https://feedsmith.dev/reference/namespaces/podcast) | `<podcast:*>` | RSS | ✅ | ✅ |
84
+ | [Podlove Simple Chapters](https://feedsmith.dev/reference/namespaces/psc) | `<psc:*>` | RSS, Atom | ✅ | ✅ |
85
+ | [Media RSS](https://feedsmith.dev/reference/namespaces/media) | `<media:*>` | RSS, Atom, RDF | ✅ | ✅ |
86
+ | [Google Play Podcast](https://feedsmith.dev/reference/namespaces/googleplay) | `<googleplay:*>` | RSS, Atom | ✅ | ✅ |
87
+ | [Spotify](https://feedsmith.dev/reference/namespaces/spotify) | `<spotify:*>` | RSS | ✅ | ✅ |
88
+ | [Acast](https://feedsmith.dev/reference/namespaces/acast) | `<acast:*>` | RSS | ✅ | ✅ |
89
+ | [RawVoice](https://feedsmith.dev/reference/namespaces/rawvoice) | `<rawvoice:*>` | RSS | ✅ | ✅ |
90
+ | [FeedPress](https://feedsmith.dev/reference/namespaces/feedpress) | `<feedpress:*>` | RSS | ✅ | ✅ |
91
+ | [arXiv](https://feedsmith.dev/reference/namespaces/arxiv) | `<arxiv:*>` | Atom | ✅ | ✅ |
92
+ | [OpenSearch](https://feedsmith.dev/reference/namespaces/opensearch) | `<opensearch:*>` | RSS, Atom | ✅ | ✅ |
93
+ | [PRISM](https://feedsmith.dev/reference/namespaces/prism) | `<prism:*>` | RSS | ✅ | ✅ |
94
+ | [ccREL](https://feedsmith.dev/reference/namespaces/cc) | `<cc:*>` | RSS, Atom | ✅ | ✅ |
95
+ | [Creative Commons](https://feedsmith.dev/reference/namespaces/creativecommons) | `<creativeCommons:*>` | RSS, Atom | ✅ | ✅ |
96
+ | [Atom Threading](https://feedsmith.dev/reference/namespaces/thr) | `<thr:*>` | RSS, Atom | ✅ | ✅ |
97
+ | [Atom Publishing Protocol](https://feedsmith.dev/reference/namespaces/app) | `<app:*>` | Atom | ✅ | ✅ |
98
+ | [Comment API](https://feedsmith.dev/reference/namespaces/wfw) | `<wfw:*>` | RSS, Atom, RDF | ✅ | ✅ |
99
+ | [Administrative](https://feedsmith.dev/reference/namespaces/admin) | `<admin:*>` | RSS, Atom, RDF | ✅ | ✅ |
100
+ | [Pingback](https://feedsmith.dev/reference/namespaces/pingback) | `<pingback:*>` | RSS, Atom | ✅ | ✅ |
101
+ | [Trackback](https://feedsmith.dev/reference/namespaces/trackback) | `<trackback:*>` | RSS, Atom | ✅ | ✅ |
102
+ | [Source](https://feedsmith.dev/reference/namespaces/source) | `<source:*>` | RSS | ✅ | ✅ |
103
+ | [blogChannel](https://feedsmith.dev/reference/namespaces/blogchannel) | `<blogChannel:*>` | RSS | ✅ | ✅ |
104
+ | [YouTube](https://feedsmith.dev/reference/namespaces/yt) | `<yt:*>` | Atom | ✅ | ✅ |
105
+ | [W3C Basic Geo](https://feedsmith.dev/reference/namespaces/geo) | `<geo:*>` | RSS, Atom | ✅ | ✅ |
106
+ | [GeoRSS Simple](https://feedsmith.dev/reference/namespaces/georss) | `<georss:*>` | RSS, Atom, RDF | ✅ | ✅ |
107
+ | [RDF](https://feedsmith.dev/reference/namespaces/rdf) | `<rdf:*>` | RDF | ✅ | ✅ |
108
+
105
109
  ## Quick Start
106
110
 
107
111
  This guide will get you up and running with Feedsmith in just a few minutes.
@@ -46,6 +46,12 @@ const namespaceUris = {
46
46
  "http://purl.org/atom/ns#",
47
47
  "https://purl.org/atom/ns#"
48
48
  ],
49
+ blogChannel: [
50
+ "http://backend.userland.com/blogChannelModule",
51
+ "https://backend.userland.com/blogChannelModule",
52
+ "http://backend.userland.com/blogChannelModule/",
53
+ "https://backend.userland.com/blogChannelModule/"
54
+ ],
49
55
  app: [
50
56
  "http://www.w3.org/2007/app",
51
57
  "https://www.w3.org/2007/app",
@@ -251,6 +257,50 @@ const namespaceUris = {
251
257
  "https://madskills.com/public/xml/rss/module/trackback/",
252
258
  "http://madskills.com/public/xml/rss/module/trackback",
253
259
  "https://madskills.com/public/xml/rss/module/trackback"
260
+ ],
261
+ prism: [
262
+ "http://prismstandard.org/namespaces/basic/3.0/",
263
+ "https://prismstandard.org/namespaces/basic/3.0/",
264
+ "http://prismstandard.org/namespaces/basic/3.0",
265
+ "https://prismstandard.org/namespaces/basic/3.0",
266
+ "http://prismstandard.org/namespaces/basic/2.2/",
267
+ "https://prismstandard.org/namespaces/basic/2.2/",
268
+ "http://prismstandard.org/namespaces/basic/2.2",
269
+ "https://prismstandard.org/namespaces/basic/2.2",
270
+ "http://prismstandard.org/namespaces/basic/2.1/",
271
+ "https://prismstandard.org/namespaces/basic/2.1/",
272
+ "http://prismstandard.org/namespaces/basic/2.1",
273
+ "https://prismstandard.org/namespaces/basic/2.1",
274
+ "http://prismstandard.org/namespaces/basic/2.0/",
275
+ "https://prismstandard.org/namespaces/basic/2.0/",
276
+ "http://prismstandard.org/namespaces/basic/2.0",
277
+ "https://prismstandard.org/namespaces/basic/2.0",
278
+ "http://prismstandard.org/namespaces/2.0/basic/",
279
+ "https://prismstandard.org/namespaces/2.0/basic/",
280
+ "http://prismstandard.org/namespaces/2.0/basic",
281
+ "https://prismstandard.org/namespaces/2.0/basic",
282
+ "http://prismstandard.org/namespaces/1.2/basic/",
283
+ "https://prismstandard.org/namespaces/1.2/basic/",
284
+ "http://prismstandard.org/namespaces/1.2/basic",
285
+ "https://prismstandard.org/namespaces/1.2/basic",
286
+ "http://prismstandard.org/namespaces/1.1/basic/",
287
+ "https://prismstandard.org/namespaces/1.1/basic/",
288
+ "http://prismstandard.org/namespaces/1.1/basic",
289
+ "https://prismstandard.org/namespaces/1.1/basic",
290
+ "http://prismstandard.org/namespaces/1.0/basic/",
291
+ "https://prismstandard.org/namespaces/1.0/basic/",
292
+ "http://prismstandard.org/namespaces/1.0/basic",
293
+ "https://prismstandard.org/namespaces/1.0/basic",
294
+ "http://purl.org/rss/1.0/modules/prism/",
295
+ "https://purl.org/rss/1.0/modules/prism/",
296
+ "http://purl.org/rss/1.0/modules/prism",
297
+ "https://purl.org/rss/1.0/modules/prism"
298
+ ],
299
+ acast: [
300
+ "https://schema.acast.com/1.0/",
301
+ "http://schema.acast.com/1.0/",
302
+ "https://schema.acast.com/1.0",
303
+ "http://schema.acast.com/1.0"
254
304
  ]
255
305
  };
256
306
  const namespacePrefixes = Object.entries(namespaceUris).reduce((prefixes, [prefix, uris]) => {
@@ -45,6 +45,12 @@ const namespaceUris = {
45
45
  "http://purl.org/atom/ns#",
46
46
  "https://purl.org/atom/ns#"
47
47
  ],
48
+ blogChannel: [
49
+ "http://backend.userland.com/blogChannelModule",
50
+ "https://backend.userland.com/blogChannelModule",
51
+ "http://backend.userland.com/blogChannelModule/",
52
+ "https://backend.userland.com/blogChannelModule/"
53
+ ],
48
54
  app: [
49
55
  "http://www.w3.org/2007/app",
50
56
  "https://www.w3.org/2007/app",
@@ -250,6 +256,50 @@ const namespaceUris = {
250
256
  "https://madskills.com/public/xml/rss/module/trackback/",
251
257
  "http://madskills.com/public/xml/rss/module/trackback",
252
258
  "https://madskills.com/public/xml/rss/module/trackback"
259
+ ],
260
+ prism: [
261
+ "http://prismstandard.org/namespaces/basic/3.0/",
262
+ "https://prismstandard.org/namespaces/basic/3.0/",
263
+ "http://prismstandard.org/namespaces/basic/3.0",
264
+ "https://prismstandard.org/namespaces/basic/3.0",
265
+ "http://prismstandard.org/namespaces/basic/2.2/",
266
+ "https://prismstandard.org/namespaces/basic/2.2/",
267
+ "http://prismstandard.org/namespaces/basic/2.2",
268
+ "https://prismstandard.org/namespaces/basic/2.2",
269
+ "http://prismstandard.org/namespaces/basic/2.1/",
270
+ "https://prismstandard.org/namespaces/basic/2.1/",
271
+ "http://prismstandard.org/namespaces/basic/2.1",
272
+ "https://prismstandard.org/namespaces/basic/2.1",
273
+ "http://prismstandard.org/namespaces/basic/2.0/",
274
+ "https://prismstandard.org/namespaces/basic/2.0/",
275
+ "http://prismstandard.org/namespaces/basic/2.0",
276
+ "https://prismstandard.org/namespaces/basic/2.0",
277
+ "http://prismstandard.org/namespaces/2.0/basic/",
278
+ "https://prismstandard.org/namespaces/2.0/basic/",
279
+ "http://prismstandard.org/namespaces/2.0/basic",
280
+ "https://prismstandard.org/namespaces/2.0/basic",
281
+ "http://prismstandard.org/namespaces/1.2/basic/",
282
+ "https://prismstandard.org/namespaces/1.2/basic/",
283
+ "http://prismstandard.org/namespaces/1.2/basic",
284
+ "https://prismstandard.org/namespaces/1.2/basic",
285
+ "http://prismstandard.org/namespaces/1.1/basic/",
286
+ "https://prismstandard.org/namespaces/1.1/basic/",
287
+ "http://prismstandard.org/namespaces/1.1/basic",
288
+ "https://prismstandard.org/namespaces/1.1/basic",
289
+ "http://prismstandard.org/namespaces/1.0/basic/",
290
+ "https://prismstandard.org/namespaces/1.0/basic/",
291
+ "http://prismstandard.org/namespaces/1.0/basic",
292
+ "https://prismstandard.org/namespaces/1.0/basic",
293
+ "http://purl.org/rss/1.0/modules/prism/",
294
+ "https://purl.org/rss/1.0/modules/prism/",
295
+ "http://purl.org/rss/1.0/modules/prism",
296
+ "https://purl.org/rss/1.0/modules/prism"
297
+ ],
298
+ acast: [
299
+ "https://schema.acast.com/1.0/",
300
+ "http://schema.acast.com/1.0/",
301
+ "https://schema.acast.com/1.0",
302
+ "http://schema.acast.com/1.0"
253
303
  ]
254
304
  };
255
305
  const namespacePrefixes = Object.entries(namespaceUris).reduce((prefixes, [prefix, uris]) => {
@@ -1,3 +1,4 @@
1
+ const require_utils = require('./utils.cjs');
1
2
  const require_index = require('../feeds/atom/detect/index.cjs');
2
3
  const require_config = require('./config.cjs');
3
4
  const require_index$1 = require('../feeds/atom/parse/index.cjs');
@@ -22,9 +23,10 @@ const parse$4 = (value, options) => {
22
23
  format: "rdf",
23
24
  feed: require_index$5.parse(value, options)
24
25
  };
25
- if (require_index$2.detect(value)) return {
26
+ const json = require_utils.parseJsonObject(value);
27
+ if (require_index$2.detect(json)) return {
26
28
  format: "json",
27
- feed: require_index$3.parse(value, options)
29
+ feed: require_index$3.parse(json, options)
28
30
  };
29
31
  throw new Error(require_config.locales.unrecognizedFeedFormat);
30
32
  };
@@ -1,3 +1,4 @@
1
+ import { parseJsonObject } from "./utils.js";
1
2
  import { detect } from "../feeds/atom/detect/index.js";
2
3
  import { locales } from "./config.js";
3
4
  import { parse } from "../feeds/atom/parse/index.js";
@@ -22,9 +23,10 @@ const parse$4 = (value, options) => {
22
23
  format: "rdf",
23
24
  feed: parse$2(value, options)
24
25
  };
25
- if (detect$1(value)) return {
26
+ const json = parseJsonObject(value);
27
+ if (detect$1(json)) return {
26
28
  format: "json",
27
- feed: parse$1(value, options)
29
+ feed: parse$1(json, options)
28
30
  };
29
31
  throw new Error(locales.unrecognizedFeedFormat);
30
32
  };
@@ -307,8 +307,8 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
307
307
  return normalizeWithContext(key, context, true);
308
308
  };
309
309
  const traverseAndNormalize = (object, parentContext = {}) => {
310
- if (!isObject(object)) return object;
311
310
  if (Array.isArray(object)) return object.map((item) => traverseAndNormalize(item, parentContext));
311
+ if (!isObject(object)) return object;
312
312
  const normalizedObject = {};
313
313
  const keyGroups = /* @__PURE__ */ new Map();
314
314
  const declarations = extractNamespaceDeclarations(object);
@@ -345,6 +345,16 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
345
345
  };
346
346
  return normalizeRoot;
347
347
  };
348
+ const parseJsonObject = (value) => {
349
+ if (isObject(value)) return value;
350
+ if (!isNonEmptyString(value) || value.length < 2) return;
351
+ const startsWithBrace = value.charAt(0) === "{" || /^\s*\{/.test(value);
352
+ const endsWithBrace = value.charAt(value.length - 1) === "}" || /\}\s*$/.test(value);
353
+ if (!startsWithBrace || !endsWithBrace) return;
354
+ try {
355
+ return JSON.parse(value);
356
+ } catch {}
357
+ };
348
358
 
349
359
  //#endregion
350
360
  exports.createNamespaceNormalizator = createNamespaceNormalizator;
@@ -371,6 +381,7 @@ exports.parseArrayOf = parseArrayOf;
371
381
  exports.parseBoolean = parseBoolean;
372
382
  exports.parseCsvOf = parseCsvOf;
373
383
  exports.parseDate = parseDate;
384
+ exports.parseJsonObject = parseJsonObject;
374
385
  exports.parseNumber = parseNumber;
375
386
  exports.parseSingular = parseSingular;
376
387
  exports.parseSingularOf = parseSingularOf;
@@ -307,8 +307,8 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
307
307
  return normalizeWithContext(key, context, true);
308
308
  };
309
309
  const traverseAndNormalize = (object, parentContext = {}) => {
310
- if (!isObject(object)) return object;
311
310
  if (Array.isArray(object)) return object.map((item) => traverseAndNormalize(item, parentContext));
311
+ if (!isObject(object)) return object;
312
312
  const normalizedObject = {};
313
313
  const keyGroups = /* @__PURE__ */ new Map();
314
314
  const declarations = extractNamespaceDeclarations(object);
@@ -345,6 +345,16 @@ const createNamespaceNormalizator = (namespaceUris, namespacePrefixes, primaryNa
345
345
  };
346
346
  return normalizeRoot;
347
347
  };
348
+ const parseJsonObject = (value) => {
349
+ if (isObject(value)) return value;
350
+ if (!isNonEmptyString(value) || value.length < 2) return;
351
+ const startsWithBrace = value.charAt(0) === "{" || /^\s*\{/.test(value);
352
+ const endsWithBrace = value.charAt(value.length - 1) === "}" || /\}\s*$/.test(value);
353
+ if (!startsWithBrace || !endsWithBrace) return;
354
+ try {
355
+ return JSON.parse(value);
356
+ } catch {}
357
+ };
348
358
 
349
359
  //#endregion
350
- 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, parseNumber, parseSingular, parseSingularOf, parseString, parseYesNoBoolean, retrieveRdfResourceOrText, retrieveText, trimArray, trimObject };
360
+ 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 };
@@ -3,8 +3,9 @@ const require_utils$1 = require('../parse/utils.cjs');
3
3
 
4
4
  //#region src/feeds/json/detect/index.ts
5
5
  const detect = (value) => {
6
- if (!require_utils.isObject(value)) return false;
7
- const get = require_utils$1.createCaseInsensitiveGetter(value);
6
+ const json = require_utils.parseJsonObject(value);
7
+ if (!require_utils.isObject(json)) return false;
8
+ const get = require_utils$1.createCaseInsensitiveGetter(json);
8
9
  const version = get("version");
9
10
  if (require_utils.isNonEmptyString(version)) return version.includes("jsonfeed.org/version/");
10
11
  const hasTitle = require_utils.isNonEmptyString(get("title"));
@@ -1,10 +1,11 @@
1
- import { isNonEmptyString, isObject } from "../../../common/utils.js";
1
+ import { isNonEmptyString, isObject, parseJsonObject } from "../../../common/utils.js";
2
2
  import { createCaseInsensitiveGetter } from "../parse/utils.js";
3
3
 
4
4
  //#region src/feeds/json/detect/index.ts
5
5
  const detect = (value) => {
6
- if (!isObject(value)) return false;
7
- const get = createCaseInsensitiveGetter(value);
6
+ const json = parseJsonObject(value);
7
+ if (!isObject(json)) return false;
8
+ const get = createCaseInsensitiveGetter(json);
8
9
  const version = get("version");
9
10
  if (isNonEmptyString(version)) return version.includes("jsonfeed.org/version/");
10
11
  const hasTitle = isNonEmptyString(get("title"));
@@ -1,11 +1,13 @@
1
+ const require_utils = require('../../../common/utils.cjs');
1
2
  const require_config = require('../../../common/config.cjs');
2
- const require_utils = require('./utils.cjs');
3
+ const require_utils$1 = require('./utils.cjs');
3
4
  const require_index = require('../detect/index.cjs');
4
5
 
5
6
  //#region src/feeds/json/parse/index.ts
6
7
  const parse = (value, options) => {
7
- if (!require_index.detect(value)) throw new Error(require_config.locales.invalidFeedFormat);
8
- const parsed = require_utils.parseFeed(value, options);
8
+ const json = require_utils.parseJsonObject(value);
9
+ if (!require_index.detect(json)) throw new Error(require_config.locales.invalidFeedFormat);
10
+ const parsed = require_utils$1.parseFeed(json, options);
9
11
  if (!parsed) throw new Error(require_config.locales.invalidFeedFormat);
10
12
  return parsed;
11
13
  };
@@ -1,11 +1,13 @@
1
+ import { parseJsonObject } from "../../../common/utils.js";
1
2
  import { locales } from "../../../common/config.js";
2
3
  import { parseFeed } from "./utils.js";
3
4
  import { detect } from "../detect/index.js";
4
5
 
5
6
  //#region src/feeds/json/parse/index.ts
6
7
  const parse = (value, options) => {
7
- if (!detect(value)) throw new Error(locales.invalidFeedFormat);
8
- const parsed = parseFeed(value, options);
8
+ const json = parseJsonObject(value);
9
+ if (!detect(json)) throw new Error(locales.invalidFeedFormat);
10
+ const parsed = parseFeed(json, options);
9
11
  if (!parsed) throw new Error(locales.invalidFeedFormat);
10
12
  return parsed;
11
13
  };
@@ -9,6 +9,7 @@ import { SyNs } from "../../../namespaces/sy/common/types.cjs";
9
9
  import { WfwNs } from "../../../namespaces/wfw/common/types.cjs";
10
10
  import { AtomNs } from "../../../namespaces/atom/common/types.cjs";
11
11
  import { ContentNs } from "../../../namespaces/content/common/types.cjs";
12
+ import { RdfNs } from "../../../namespaces/rdf/common/types.cjs";
12
13
 
13
14
  //#region src/feeds/rdf/common/types.d.ts
14
15
  declare namespace Rdf {
@@ -16,17 +17,20 @@ declare namespace Rdf {
16
17
  title: string;
17
18
  link: string;
18
19
  url?: string;
20
+ rdf?: RdfNs.About;
19
21
  };
20
22
  type TextInput = {
21
23
  title: string;
22
24
  description: string;
23
25
  name: string;
24
26
  link: string;
27
+ rdf?: RdfNs.About;
25
28
  };
26
29
  type Item<TDate extends DateLike> = {
27
30
  title: string;
28
31
  link: string;
29
32
  description?: string;
33
+ rdf?: RdfNs.About;
30
34
  atom?: AtomNs.Entry<TDate>;
31
35
  dc?: DcNs.ItemOrFeed<TDate>;
32
36
  content?: ContentNs.Item;
@@ -43,6 +47,7 @@ declare namespace Rdf {
43
47
  image?: Image;
44
48
  items?: Array<Item<TDate>>;
45
49
  textInput?: TextInput;
50
+ rdf?: RdfNs.About;
46
51
  atom?: AtomNs.Feed<TDate>;
47
52
  dc?: DcNs.ItemOrFeed<TDate>;
48
53
  sy?: SyNs.Feed<TDate>;
@@ -9,6 +9,7 @@ import { SyNs } from "../../../namespaces/sy/common/types.js";
9
9
  import { WfwNs } from "../../../namespaces/wfw/common/types.js";
10
10
  import { AtomNs } from "../../../namespaces/atom/common/types.js";
11
11
  import { ContentNs } from "../../../namespaces/content/common/types.js";
12
+ import { RdfNs } from "../../../namespaces/rdf/common/types.js";
12
13
 
13
14
  //#region src/feeds/rdf/common/types.d.ts
14
15
  declare namespace Rdf {
@@ -16,17 +17,20 @@ declare namespace Rdf {
16
17
  title: string;
17
18
  link: string;
18
19
  url?: string;
20
+ rdf?: RdfNs.About;
19
21
  };
20
22
  type TextInput = {
21
23
  title: string;
22
24
  description: string;
23
25
  name: string;
24
26
  link: string;
27
+ rdf?: RdfNs.About;
25
28
  };
26
29
  type Item<TDate extends DateLike> = {
27
30
  title: string;
28
31
  link: string;
29
32
  description?: string;
33
+ rdf?: RdfNs.About;
30
34
  atom?: AtomNs.Entry<TDate>;
31
35
  dc?: DcNs.ItemOrFeed<TDate>;
32
36
  content?: ContentNs.Item;
@@ -43,6 +47,7 @@ declare namespace Rdf {
43
47
  image?: Image;
44
48
  items?: Array<Item<TDate>>;
45
49
  textInput?: TextInput;
50
+ rdf?: RdfNs.About;
46
51
  atom?: AtomNs.Feed<TDate>;
47
52
  dc?: DcNs.ItemOrFeed<TDate>;
48
53
  sy?: SyNs.Feed<TDate>;
@@ -9,18 +9,29 @@ const require_utils$7 = require('../../../namespaces/sy/parse/utils.cjs');
9
9
  const require_utils$8 = require('../../../namespaces/wfw/parse/utils.cjs');
10
10
  const require_utils$9 = require('../../../namespaces/atom/parse/utils.cjs');
11
11
  const require_utils$10 = require('../../../namespaces/content/parse/utils.cjs');
12
+ const require_utils$11 = require('../../../namespaces/rdf/parse/utils.cjs');
12
13
 
13
14
  //#region src/feeds/rdf/parse/utils.ts
15
+ const retrieveByAbout = (elements, resourceUri) => {
16
+ if (!resourceUri) return;
17
+ return (Array.isArray(elements) ? elements : [elements]).find((el) => el?.["@about"] === resourceUri);
18
+ };
19
+ const findByTocReference = (value, property) => {
20
+ if (!require_utils.isObject(value)) return;
21
+ const resourceUri = require_utils.parseString(require_utils.parseSingular(require_utils.parseSingular(value.channel)?.[property])?.["@resource"]);
22
+ return retrieveByAbout(value[property], resourceUri);
23
+ };
14
24
  const parseImage = (value) => {
15
25
  if (!require_utils.isObject(value)) return;
16
26
  return require_utils.trimObject({
17
27
  title: require_utils.parseSingularOf(value.title, (value$1) => require_utils.parseString(require_utils.retrieveText(value$1))),
18
28
  link: require_utils.parseSingularOf(value.link, (value$1) => require_utils.parseString(require_utils.retrieveText(value$1))),
19
- url: require_utils.parseSingularOf(value.url, (value$1) => require_utils.parseString(require_utils.retrieveText(value$1)))
29
+ url: require_utils.parseSingularOf(value.url, (value$1) => require_utils.parseString(require_utils.retrieveText(value$1))),
30
+ rdf: require_utils$11.retrieveAbout(value)
20
31
  });
21
32
  };
22
33
  const retrieveImage = (value) => {
23
- return require_utils.parseSingularOf(value?.image, parseImage);
34
+ return parseImage(findByTocReference(value, "image")) ?? require_utils.parseSingularOf(value?.image, parseImage);
24
35
  };
25
36
  const parseTextInput = (value) => {
26
37
  if (!require_utils.isObject(value)) return;
@@ -28,11 +39,12 @@ const parseTextInput = (value) => {
28
39
  title: require_utils.parseSingularOf(value.title, (value$1) => require_utils.parseString(require_utils.retrieveText(value$1))),
29
40
  description: require_utils.parseSingularOf(value.description, (value$1) => require_utils.parseString(require_utils.retrieveText(value$1))),
30
41
  name: require_utils.parseSingularOf(value.name, (value$1) => require_utils.parseString(require_utils.retrieveText(value$1))),
31
- link: require_utils.parseSingularOf(value.link, (value$1) => require_utils.parseString(require_utils.retrieveText(value$1)))
42
+ link: require_utils.parseSingularOf(value.link, (value$1) => require_utils.parseString(require_utils.retrieveText(value$1))),
43
+ rdf: require_utils$11.retrieveAbout(value)
32
44
  });
33
45
  };
34
46
  const retrieveTextInput = (value) => {
35
- return require_utils.parseSingularOf(value?.textinput, parseTextInput);
47
+ return parseTextInput(findByTocReference(value, "textinput")) ?? require_utils.parseSingularOf(value?.textinput, parseTextInput);
36
48
  };
37
49
  const parseItem = (value) => {
38
50
  if (!require_utils.isObject(value)) return;
@@ -41,6 +53,7 @@ const parseItem = (value) => {
41
53
  title: require_utils.parseSingularOf(value.title, (value$1) => require_utils.parseString(require_utils.retrieveText(value$1))),
42
54
  link: require_utils.parseSingularOf(value.link, (value$1) => require_utils.parseString(require_utils.retrieveText(value$1))),
43
55
  description: require_utils.parseSingularOf(value.description, (value$1) => require_utils.parseString(require_utils.retrieveText(value$1))),
56
+ rdf: require_utils$11.retrieveAbout(value),
44
57
  atom: namespaces.has("atom") ? require_utils$9.retrieveEntry(value) : void 0,
45
58
  dc: namespaces.has("dc") ? require_utils$2.retrieveItemOrFeed(value) : void 0,
46
59
  content: namespaces.has("content") ? require_utils$10.retrieveItem(value) : void 0,
@@ -52,6 +65,9 @@ const parseItem = (value) => {
52
65
  });
53
66
  };
54
67
  const retrieveItems = (value, options) => {
68
+ if (!require_utils.isObject(value)) return;
69
+ const items = require_utils.trimArray(require_utils.parseArrayOf(require_utils.parseSingular(require_utils.parseSingular(require_utils.parseSingular(value.channel)?.items)?.seq)?.li, (li) => require_utils.parseString(li?.["@resource"]), options?.maxItems)?.map((uri) => retrieveByAbout(value.item, uri)), parseItem);
70
+ if (items?.length) return items;
55
71
  return require_utils.parseArrayOf(value?.item, parseItem, options?.maxItems);
56
72
  };
57
73
  const parseFeed = (value, options) => {
@@ -65,6 +81,7 @@ const parseFeed = (value, options) => {
65
81
  image: retrieveImage(value),
66
82
  items: retrieveItems(value, options),
67
83
  textInput: retrieveTextInput(value),
84
+ rdf: require_utils$11.retrieveAbout(channel),
68
85
  atom: namespaces.has("atom") ? require_utils$9.retrieveFeed(channel) : void 0,
69
86
  dc: namespaces.has("dc") ? require_utils$2.retrieveItemOrFeed(channel) : void 0,
70
87
  sy: namespaces.has("sy") ? require_utils$7.retrieveFeed(channel) : void 0,
@@ -1,4 +1,4 @@
1
- import { detectNamespaces, isObject, parseArrayOf, parseSingular, parseSingularOf, parseString, retrieveText, trimObject } from "../../../common/utils.js";
1
+ import { detectNamespaces, isObject, parseArrayOf, parseSingular, parseSingularOf, parseString, retrieveText, trimArray, trimObject } from "../../../common/utils.js";
2
2
  import { retrieveFeed } from "../../../namespaces/admin/parse/utils.js";
3
3
  import { retrieveItemOrFeed } from "../../../namespaces/dc/parse/utils.js";
4
4
  import { retrieveItemOrFeed as retrieveItemOrFeed$1 } from "../../../namespaces/dcterms/parse/utils.js";
@@ -9,18 +9,29 @@ import { retrieveFeed as retrieveFeed$2 } from "../../../namespaces/sy/parse/uti
9
9
  import { retrieveItem as retrieveItem$2 } from "../../../namespaces/wfw/parse/utils.js";
10
10
  import { retrieveEntry, retrieveFeed as retrieveFeed$1 } from "../../../namespaces/atom/parse/utils.js";
11
11
  import { retrieveItem } from "../../../namespaces/content/parse/utils.js";
12
+ import { retrieveAbout } from "../../../namespaces/rdf/parse/utils.js";
12
13
 
13
14
  //#region src/feeds/rdf/parse/utils.ts
15
+ const retrieveByAbout = (elements, resourceUri) => {
16
+ if (!resourceUri) return;
17
+ return (Array.isArray(elements) ? elements : [elements]).find((el) => el?.["@about"] === resourceUri);
18
+ };
19
+ const findByTocReference = (value, property) => {
20
+ if (!isObject(value)) return;
21
+ const resourceUri = parseString(parseSingular(parseSingular(value.channel)?.[property])?.["@resource"]);
22
+ return retrieveByAbout(value[property], resourceUri);
23
+ };
14
24
  const parseImage = (value) => {
15
25
  if (!isObject(value)) return;
16
26
  return trimObject({
17
27
  title: parseSingularOf(value.title, (value$1) => parseString(retrieveText(value$1))),
18
28
  link: parseSingularOf(value.link, (value$1) => parseString(retrieveText(value$1))),
19
- url: parseSingularOf(value.url, (value$1) => parseString(retrieveText(value$1)))
29
+ url: parseSingularOf(value.url, (value$1) => parseString(retrieveText(value$1))),
30
+ rdf: retrieveAbout(value)
20
31
  });
21
32
  };
22
33
  const retrieveImage = (value) => {
23
- return parseSingularOf(value?.image, parseImage);
34
+ return parseImage(findByTocReference(value, "image")) ?? parseSingularOf(value?.image, parseImage);
24
35
  };
25
36
  const parseTextInput = (value) => {
26
37
  if (!isObject(value)) return;
@@ -28,11 +39,12 @@ const parseTextInput = (value) => {
28
39
  title: parseSingularOf(value.title, (value$1) => parseString(retrieveText(value$1))),
29
40
  description: parseSingularOf(value.description, (value$1) => parseString(retrieveText(value$1))),
30
41
  name: parseSingularOf(value.name, (value$1) => parseString(retrieveText(value$1))),
31
- link: parseSingularOf(value.link, (value$1) => parseString(retrieveText(value$1)))
42
+ link: parseSingularOf(value.link, (value$1) => parseString(retrieveText(value$1))),
43
+ rdf: retrieveAbout(value)
32
44
  });
33
45
  };
34
46
  const retrieveTextInput = (value) => {
35
- return parseSingularOf(value?.textinput, parseTextInput);
47
+ return parseTextInput(findByTocReference(value, "textinput")) ?? parseSingularOf(value?.textinput, parseTextInput);
36
48
  };
37
49
  const parseItem = (value) => {
38
50
  if (!isObject(value)) return;
@@ -41,6 +53,7 @@ const parseItem = (value) => {
41
53
  title: parseSingularOf(value.title, (value$1) => parseString(retrieveText(value$1))),
42
54
  link: parseSingularOf(value.link, (value$1) => parseString(retrieveText(value$1))),
43
55
  description: parseSingularOf(value.description, (value$1) => parseString(retrieveText(value$1))),
56
+ rdf: retrieveAbout(value),
44
57
  atom: namespaces.has("atom") ? retrieveEntry(value) : void 0,
45
58
  dc: namespaces.has("dc") ? retrieveItemOrFeed(value) : void 0,
46
59
  content: namespaces.has("content") ? retrieveItem(value) : void 0,
@@ -52,6 +65,9 @@ const parseItem = (value) => {
52
65
  });
53
66
  };
54
67
  const retrieveItems = (value, options) => {
68
+ if (!isObject(value)) return;
69
+ const items = trimArray(parseArrayOf(parseSingular(parseSingular(parseSingular(value.channel)?.items)?.seq)?.li, (li) => parseString(li?.["@resource"]), options?.maxItems)?.map((uri) => retrieveByAbout(value.item, uri)), parseItem);
70
+ if (items?.length) return items;
55
71
  return parseArrayOf(value?.item, parseItem, options?.maxItems);
56
72
  };
57
73
  const parseFeed = (value, options) => {
@@ -65,6 +81,7 @@ const parseFeed = (value, options) => {
65
81
  image: retrieveImage(value),
66
82
  items: retrieveItems(value, options),
67
83
  textInput: retrieveTextInput(value),
84
+ rdf: retrieveAbout(channel),
68
85
  atom: namespaces.has("atom") ? retrieveFeed$1(channel) : void 0,
69
86
  dc: namespaces.has("dc") ? retrieveItemOrFeed(channel) : void 0,
70
87
  sy: namespaces.has("sy") ? retrieveFeed$2(channel) : void 0,