feedsmith 2.0.0-next.6 → 2.0.0-next.7
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 +11 -10
- package/dist/common/config.d.ts +1 -0
- package/dist/common/config.js +1 -0
- package/dist/feeds/rss/common/types.d.ts +3 -0
- package/dist/feeds/rss/generate/utils.js +3 -0
- package/dist/feeds/rss/parse/utils.js +3 -0
- package/dist/namespaces/source/common/types.d.ts +32 -0
- package/dist/namespaces/source/common/types.js +2 -0
- package/dist/namespaces/source/generate/utils.d.ts +8 -0
- package/dist/namespaces/source/generate/utils.js +68 -0
- package/dist/namespaces/source/parse/utils.d.ts +8 -0
- package/dist/namespaces/source/parse/utils.js +69 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/feedsmith)
|
|
6
6
|
[](https://github.com/macieklamberski/feedsmith/blob/main/LICENSE)
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Fast, all‑in‑one JavaScript parser and generator for RSS, Atom, JSON Feed, and RDF feeds, with support for popular namespaces and OPML files.
|
|
9
9
|
|
|
10
|
-
Feedsmith
|
|
10
|
+
Feedsmith offers universal and format‑specific parsers that maintain the original feed structure in a clean, object-oriented format while intelligently normalizing legacy elements. Access all feed data without compromising simplicity.
|
|
11
11
|
|
|
12
12
|
**[Read full docs ↗](https://feedsmith.dev)**
|
|
13
13
|
·
|
|
@@ -23,18 +23,18 @@ Feedsmith provides both universal and format-specific parsers that maintain the
|
|
|
23
23
|
|
|
24
24
|
### Core
|
|
25
25
|
|
|
26
|
-
* **Comprehensive
|
|
27
|
-
* **
|
|
28
|
-
* **Smart
|
|
29
|
-
* **Parsing &
|
|
26
|
+
* **Comprehensive support** 🎯 — Supports all major feed formats and namespaces.
|
|
27
|
+
* **Preserves structure** 📦 — Parsed feed object maintains the original feed structure making it easy to access the data.
|
|
28
|
+
* **Smart namespace handling** 🧠 — Normalizes custom namespace prefixes to standard ones (e.g., `<custom:creator>` becomes `dc.creator`).
|
|
29
|
+
* **Parsing & generating** 🔩 — Use one package for both parsing and generating feeds.
|
|
30
30
|
|
|
31
31
|
### Leniency
|
|
32
|
-
* **Normalizes
|
|
32
|
+
* **Normalizes legacy elements** ✨ — Upgrades feed elements to their modern equivalents so that you never need to worry about reading feeds in older formats.
|
|
33
33
|
* **CaSe INSENsiTive** 🐍 — Handles fields and attributes in any case (lowercase, uppercase, mixed).
|
|
34
|
-
* **Forgiving** 🤝 —
|
|
34
|
+
* **Forgiving** 🤝 — Gracefully handles malformed or incomplete feeds and extracts valid data. This makes it suitable for use with real-world feeds that may not strictly follow specifications.
|
|
35
35
|
|
|
36
36
|
### Performance and Type-Safety
|
|
37
|
-
* **Ultrafast parsing** ⚡ — One of the fastest feed parsers
|
|
37
|
+
* **Ultrafast parsing** ⚡ — One of the fastest JavaScript feed parsers ([see benchmarks](/benchmarks)).
|
|
38
38
|
* **Type-safe API** 🛟 — Built with TypeScript from the ground up, it provides complete type definitions for every feed format and namespace.
|
|
39
39
|
* **Tree-shakable** 🍃 — Only include the parts of the library you need, reducing bundle size.
|
|
40
40
|
* **Well-tested** 🔬 — Comprehensive test suite with over 2000 tests and 99% code coverage.
|
|
@@ -78,6 +78,7 @@ Feedsmith aims to fully support all major feed formats and namespaces in complet
|
|
|
78
78
|
| [Atom Threading](https://www.ietf.org/rfc/rfc4685.txt) | `<thr:*>` | RSS, Atom | ✅ | ✅ |
|
|
79
79
|
| [Dublin Core Terms](http://purl.org/dc/terms/) | `<dcterms:*>` | RSS, Atom, RDF | ✅ | ✅ |
|
|
80
80
|
| [Well-Formed Web](http://wellformedweb.org/CommentAPI/) | `<wfw:*>` | RSS, Atom, RDF | ✅ | ✅ |
|
|
81
|
+
| [Source](http://source.scripting.com/) | `<source:*>` | RSS | ✅ | ✅ |
|
|
81
82
|
| [YouTube](https://www.youtube.com/feeds/videos.xml) | `<yt:*>` | Atom | ✅ | ✅ |
|
|
82
83
|
|
|
83
84
|
### Other
|
|
@@ -98,7 +99,7 @@ For a full overview of all the features, visit the [documentation website](https
|
|
|
98
99
|
npm install feedsmith
|
|
99
100
|
```
|
|
100
101
|
|
|
101
|
-
> **
|
|
102
|
+
> **Migrating from v1.x?** Check out the [migration guide](https://feedsmith.dev/migration-to-2.x).
|
|
102
103
|
|
|
103
104
|
### Parse Any Feed
|
|
104
105
|
|
package/dist/common/config.d.ts
CHANGED
package/dist/common/config.js
CHANGED
|
@@ -36,6 +36,7 @@ export const namespaceUrls = {
|
|
|
36
36
|
podcast: 'https://podcastindex.org/namespace/1.0',
|
|
37
37
|
rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
|
|
38
38
|
slash: 'http://purl.org/rss/1.0/modules/slash/',
|
|
39
|
+
source: 'http://source.scripting.com/',
|
|
39
40
|
sy: 'http://purl.org/rss/1.0/modules/syndication/',
|
|
40
41
|
thr: 'http://purl.org/syndication/thread/1.0',
|
|
41
42
|
wfw: 'http://wellformedweb.org/CommentAPI/',
|
|
@@ -8,6 +8,7 @@ import type { Feed as ItunesFeed, Item as ItunesItem } from '../../../namespaces
|
|
|
8
8
|
import type { ItemOrFeed as MediaItemOrFeed } from '../../../namespaces/media/common/types.js';
|
|
9
9
|
import type { Feed as PodcastFeed, Item as PodcastItem } from '../../../namespaces/podcast/common/types.js';
|
|
10
10
|
import type { Item as SlashItem } from '../../../namespaces/slash/common/types.js';
|
|
11
|
+
import type { Feed as SourceFeed, Item as SourceItem } from '../../../namespaces/source/common/types.js';
|
|
11
12
|
import type { Feed as SyFeed } from '../../../namespaces/sy/common/types.js';
|
|
12
13
|
import type { Item as ThrItem } from '../../../namespaces/thr/common/types.js';
|
|
13
14
|
import type { Item as WfwItem } from '../../../namespaces/wfw/common/types.js';
|
|
@@ -74,6 +75,7 @@ export type Item<TDate extends DateLike> = {
|
|
|
74
75
|
georss?: GeoRssItemOrFeed;
|
|
75
76
|
thr?: ThrItem;
|
|
76
77
|
wfw?: WfwItem;
|
|
78
|
+
src?: SourceItem;
|
|
77
79
|
} & ({
|
|
78
80
|
title: string;
|
|
79
81
|
} | {
|
|
@@ -108,4 +110,5 @@ export type Feed<TDate extends DateLike> = {
|
|
|
108
110
|
podcast?: PodcastFeed<TDate>;
|
|
109
111
|
media?: MediaItemOrFeed;
|
|
110
112
|
georss?: GeoRssItemOrFeed;
|
|
113
|
+
src?: SourceFeed;
|
|
111
114
|
};
|
|
@@ -9,6 +9,7 @@ import { generateFeed as generateItunesFeed, generateItem as generateItunesItem,
|
|
|
9
9
|
import { generateItemOrFeed as generateMediaItemOrFeed } from '../../../namespaces/media/generate/utils.js';
|
|
10
10
|
import { generateFeed as generatePodcastFeed, generateItem as generatePodcastItem, } from '../../../namespaces/podcast/generate/utils.js';
|
|
11
11
|
import { generateItem as generateSlashItem } from '../../../namespaces/slash/generate/utils.js';
|
|
12
|
+
import { generateFeed as generateSourceFeed, generateItem as generateSourceItem, } from '../../../namespaces/source/generate/utils.js';
|
|
12
13
|
import { generateFeed as generateSyFeed } from '../../../namespaces/sy/generate/utils.js';
|
|
13
14
|
import { generateItem as generateThrItem } from '../../../namespaces/thr/generate/utils.js';
|
|
14
15
|
import { generateItem as generateWfwItem } from '../../../namespaces/wfw/generate/utils.js';
|
|
@@ -130,6 +131,7 @@ export const generateItem = (item) => {
|
|
|
130
131
|
...generateGeoRssItemOrFeed(item.georss),
|
|
131
132
|
...generateThrItem(item.thr),
|
|
132
133
|
...generateWfwItem(item.wfw),
|
|
134
|
+
...generateSourceItem(item.src),
|
|
133
135
|
};
|
|
134
136
|
return trimObject(value);
|
|
135
137
|
};
|
|
@@ -165,6 +167,7 @@ export const generateFeed = (feed) => {
|
|
|
165
167
|
...generatePodcastFeed(feed.podcast),
|
|
166
168
|
...generateMediaItemOrFeed(feed.media),
|
|
167
169
|
...generateGeoRssItemOrFeed(feed.georss),
|
|
170
|
+
...generateSourceFeed(feed.src),
|
|
168
171
|
item: trimArray(feed.items, generateItem),
|
|
169
172
|
};
|
|
170
173
|
const trimmedValue = trimObject(value);
|
|
@@ -8,6 +8,7 @@ import { retrieveFeed as retrieveItunesFeed, retrieveItem as retrieveItunesItem,
|
|
|
8
8
|
import { retrieveItemOrFeed as retrieveMediaItemOrFeed } from '../../../namespaces/media/parse/utils.js';
|
|
9
9
|
import { retrieveFeed as retrievePodcastFeed, retrieveItem as retrievePodcastItem, } from '../../../namespaces/podcast/parse/utils.js';
|
|
10
10
|
import { retrieveItem as retrieveSlashItem } from '../../../namespaces/slash/parse/utils.js';
|
|
11
|
+
import { retrieveFeed as retrieveSourceFeed, retrieveItem as retrieveSourceItem, } from '../../../namespaces/source/parse/utils.js';
|
|
11
12
|
import { retrieveFeed as retrieveSyFeed } from '../../../namespaces/sy/parse/utils.js';
|
|
12
13
|
import { retrieveItem as retrieveThrItem } from '../../../namespaces/thr/parse/utils.js';
|
|
13
14
|
import { retrieveItem as retrieveWfwItem } from '../../../namespaces/wfw/parse/utils.js';
|
|
@@ -118,6 +119,7 @@ export const parseItem = (value) => {
|
|
|
118
119
|
georss: namespaces.has('georss') ? retrieveGeoRssItemOrFeed(value) : undefined,
|
|
119
120
|
thr: namespaces.has('thr') ? retrieveThrItem(value) : undefined,
|
|
120
121
|
wfw: namespaces.has('wfw') ? retrieveWfwItem(value) : undefined,
|
|
122
|
+
src: namespaces.has('source') ? retrieveSourceItem(value) : undefined,
|
|
121
123
|
};
|
|
122
124
|
return trimObject(item);
|
|
123
125
|
};
|
|
@@ -155,6 +157,7 @@ export const parseFeed = (value) => {
|
|
|
155
157
|
podcast: namespaces.has('podcast') ? retrievePodcastFeed(value) : undefined,
|
|
156
158
|
media: namespaces.has('media') ? retrieveMediaItemOrFeed(value) : undefined,
|
|
157
159
|
georss: namespaces.has('georss') ? retrieveGeoRssItemOrFeed(value) : undefined,
|
|
160
|
+
src: namespaces.has('source') ? retrieveSourceFeed(value) : undefined,
|
|
158
161
|
};
|
|
159
162
|
return trimObject(feed);
|
|
160
163
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type Account = {
|
|
2
|
+
service: string;
|
|
3
|
+
value?: string;
|
|
4
|
+
};
|
|
5
|
+
export type Likes = {
|
|
6
|
+
server: string;
|
|
7
|
+
};
|
|
8
|
+
export type Archive = {
|
|
9
|
+
url: string;
|
|
10
|
+
startDay: string;
|
|
11
|
+
endDay?: string;
|
|
12
|
+
filename?: string;
|
|
13
|
+
};
|
|
14
|
+
export type SubscriptionList = {
|
|
15
|
+
url: string;
|
|
16
|
+
value?: string;
|
|
17
|
+
};
|
|
18
|
+
export type Feed = {
|
|
19
|
+
accounts?: Array<Account>;
|
|
20
|
+
likes?: Likes;
|
|
21
|
+
archive?: Archive;
|
|
22
|
+
subscriptionLists?: Array<SubscriptionList>;
|
|
23
|
+
cloud?: string;
|
|
24
|
+
blogroll?: string;
|
|
25
|
+
self?: string;
|
|
26
|
+
};
|
|
27
|
+
export type Item = {
|
|
28
|
+
markdown?: string;
|
|
29
|
+
outlines?: Array<string>;
|
|
30
|
+
localTime?: string;
|
|
31
|
+
linkFull?: string;
|
|
32
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GenerateFunction } from '../../../common/types.js';
|
|
2
|
+
import type { Account, Archive, Feed, Item, Likes, SubscriptionList } from '../common/types.js';
|
|
3
|
+
export declare const generateAccount: GenerateFunction<Account>;
|
|
4
|
+
export declare const generateLikes: GenerateFunction<Likes>;
|
|
5
|
+
export declare const generateArchive: GenerateFunction<Archive>;
|
|
6
|
+
export declare const generateSubscriptionList: GenerateFunction<SubscriptionList>;
|
|
7
|
+
export declare const generateFeed: GenerateFunction<Feed>;
|
|
8
|
+
export declare const generateItem: GenerateFunction<Item>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { generateCdataString, generatePlainString, isNonEmptyString, isObject, trimArray, trimObject, } from '../../../common/utils.js';
|
|
2
|
+
export const generateAccount = (account) => {
|
|
3
|
+
if (!isObject(account) || !isNonEmptyString(account.service)) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
const value = {
|
|
7
|
+
'@service': account.service,
|
|
8
|
+
'#text': generatePlainString(account.value),
|
|
9
|
+
};
|
|
10
|
+
return trimObject(value);
|
|
11
|
+
};
|
|
12
|
+
export const generateLikes = (likes) => {
|
|
13
|
+
if (!isObject(likes) || !isNonEmptyString(likes.server)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
'@server': likes.server,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export const generateArchive = (archive) => {
|
|
21
|
+
if (!isObject(archive) || !isNonEmptyString(archive.url) || !isNonEmptyString(archive.startDay)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const value = {
|
|
25
|
+
'source:url': archive.url,
|
|
26
|
+
'source:startDay': archive.startDay,
|
|
27
|
+
'source:endDay': generatePlainString(archive.endDay),
|
|
28
|
+
'source:filename': generatePlainString(archive.filename),
|
|
29
|
+
};
|
|
30
|
+
return trimObject(value);
|
|
31
|
+
};
|
|
32
|
+
export const generateSubscriptionList = (subscriptionList) => {
|
|
33
|
+
if (!isObject(subscriptionList) || !isNonEmptyString(subscriptionList.url)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const value = {
|
|
37
|
+
'@url': subscriptionList.url,
|
|
38
|
+
'#text': generatePlainString(subscriptionList.value),
|
|
39
|
+
};
|
|
40
|
+
return trimObject(value);
|
|
41
|
+
};
|
|
42
|
+
export const generateFeed = (feed) => {
|
|
43
|
+
if (!isObject(feed)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const value = {
|
|
47
|
+
'source:account': trimArray(feed.accounts, generateAccount),
|
|
48
|
+
'source:likes': generateLikes(feed.likes),
|
|
49
|
+
'source:archive': generateArchive(feed.archive),
|
|
50
|
+
'source:subscriptionList': trimArray(feed.subscriptionLists, generateSubscriptionList),
|
|
51
|
+
'source:cloud': generatePlainString(feed.cloud),
|
|
52
|
+
'source:blogroll': generatePlainString(feed.blogroll),
|
|
53
|
+
'source:self': generatePlainString(feed.self),
|
|
54
|
+
};
|
|
55
|
+
return trimObject(value);
|
|
56
|
+
};
|
|
57
|
+
export const generateItem = (item) => {
|
|
58
|
+
if (!isObject(item)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const value = {
|
|
62
|
+
'source:markdown': generateCdataString(item.markdown),
|
|
63
|
+
'source:outline': trimArray(item.outlines, generateCdataString),
|
|
64
|
+
'source:localTime': generatePlainString(item.localTime),
|
|
65
|
+
'source:linkFull': generatePlainString(item.linkFull),
|
|
66
|
+
};
|
|
67
|
+
return trimObject(value);
|
|
68
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ParsePartialFunction } from '../../../common/types.js';
|
|
2
|
+
import type { Account, Archive, Feed, Item, Likes, SubscriptionList } from '../common/types.js';
|
|
3
|
+
export declare const parseAccount: ParsePartialFunction<Account>;
|
|
4
|
+
export declare const parseLikes: ParsePartialFunction<Likes>;
|
|
5
|
+
export declare const parseArchive: ParsePartialFunction<Archive>;
|
|
6
|
+
export declare const parseSubscriptionList: ParsePartialFunction<SubscriptionList>;
|
|
7
|
+
export declare const retrieveFeed: ParsePartialFunction<Feed>;
|
|
8
|
+
export declare const retrieveItem: ParsePartialFunction<Item>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { isObject, parseArrayOf, parseSingularOf, parseString, retrieveText, trimObject, } from '../../../common/utils.js';
|
|
2
|
+
export const parseAccount = (value) => {
|
|
3
|
+
if (!isObject(value)) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
const account = {
|
|
7
|
+
service: parseString(value['@service']),
|
|
8
|
+
value: parseString(retrieveText(value)),
|
|
9
|
+
};
|
|
10
|
+
return trimObject(account);
|
|
11
|
+
};
|
|
12
|
+
export const parseLikes = (value) => {
|
|
13
|
+
if (!isObject(value)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const likes = {
|
|
17
|
+
server: parseString(value['@server']),
|
|
18
|
+
};
|
|
19
|
+
return trimObject(likes);
|
|
20
|
+
};
|
|
21
|
+
export const parseArchive = (value) => {
|
|
22
|
+
if (!isObject(value)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const archive = {
|
|
26
|
+
url: parseSingularOf(value['source:url'], (value) => parseString(retrieveText(value))),
|
|
27
|
+
startDay: parseSingularOf(value['source:startday'], (value) => parseString(retrieveText(value))),
|
|
28
|
+
endDay: parseSingularOf(value['source:endday'], (value) => parseString(retrieveText(value))),
|
|
29
|
+
filename: parseSingularOf(value['source:filename'], (value) => parseString(retrieveText(value))),
|
|
30
|
+
};
|
|
31
|
+
return trimObject(archive);
|
|
32
|
+
};
|
|
33
|
+
export const parseSubscriptionList = (value) => {
|
|
34
|
+
if (!isObject(value)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const subscriptionList = {
|
|
38
|
+
url: parseString(value['@url']),
|
|
39
|
+
value: parseString(retrieveText(value)),
|
|
40
|
+
};
|
|
41
|
+
return trimObject(subscriptionList);
|
|
42
|
+
};
|
|
43
|
+
export const retrieveFeed = (value) => {
|
|
44
|
+
if (!isObject(value)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const feed = {
|
|
48
|
+
accounts: parseArrayOf(value['source:account'], parseAccount),
|
|
49
|
+
likes: parseSingularOf(value['source:likes'], parseLikes),
|
|
50
|
+
archive: parseSingularOf(value['source:archive'], parseArchive),
|
|
51
|
+
subscriptionLists: parseArrayOf(value['source:subscriptionlist'], parseSubscriptionList),
|
|
52
|
+
cloud: parseSingularOf(value['source:cloud'], (value) => parseString(retrieveText(value))),
|
|
53
|
+
blogroll: parseSingularOf(value['source:blogroll'], (value) => parseString(retrieveText(value))),
|
|
54
|
+
self: parseSingularOf(value['source:self'], (value) => parseString(retrieveText(value))),
|
|
55
|
+
};
|
|
56
|
+
return trimObject(feed);
|
|
57
|
+
};
|
|
58
|
+
export const retrieveItem = (value) => {
|
|
59
|
+
if (!isObject(value)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const item = {
|
|
63
|
+
markdown: parseSingularOf(value['source:markdown'], (value) => parseString(retrieveText(value))),
|
|
64
|
+
outlines: parseArrayOf(value['source:outline'], (value) => parseString(retrieveText(value))),
|
|
65
|
+
localTime: parseSingularOf(value['source:localtime'], (value) => parseString(retrieveText(value))),
|
|
66
|
+
linkFull: parseSingularOf(value['source:linkfull'], (value) => parseString(retrieveText(value))),
|
|
67
|
+
};
|
|
68
|
+
return trimObject(item);
|
|
69
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "feedsmith",
|
|
3
|
-
"description": "
|
|
3
|
+
"description": "Fast, all‑in‑one parser and generator for RSS, Atom, JSON Feed, and RDF feeds, with support for Podcast, iTunes, Dublin Core, and OPML files.",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/macieklamberski/feedsmith.git"
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"vitepress": "^1.6.4",
|
|
64
64
|
"vitepress-plugin-llms": "^1.7.3"
|
|
65
65
|
},
|
|
66
|
-
"version": "2.0.0-next.
|
|
66
|
+
"version": "2.0.0-next.7"
|
|
67
67
|
}
|