To read & normalize RSS/ATOM/JSON feed data.
deno add jsr:@extractus/feed-extractorpnpm add jsr:@extractus/feed-extractor
# or
npx jsr add @extractus/feed-extractor
# or
bunx jsr add @extractus/feed-extractorAlternatively, install from npm:
npm install @extractus/feed-extractor
# or
bun add @extractus/feed-extractorimport { extract } from "@extractus/feed-extractor";
const data = await extract("https://news.google.com/atom");
console.log(data);Load and extract feed data from given RSS/ATOM/JSON source.
extract(url: string): Promise<FeedData>
extract(url: string, options?: ParserOptions): Promise<FeedData>
extract(url: string, options?: ParserOptions, fetcher?: Fetcher): Promise<FeedData>Example:
import { extract } from "@extractus/feed-extractor";
const result = await extract("https://news.google.com/atom");
console.log(result);Without any options, the result should have the following structure:
{
title: string;
link: string;
description: string;
generator: string;
language: string;
published: string; // ISO datetime
entries: Array<{
id: string;
title: string;
link: string;
description: string;
published: string; // ISO datetime
}>;
}URL of a valid feed source.
Feed content must be accessible and conform to one of the following standards:
Object with all or several of the following properties:
normalization: boolean, normalize feed data or keep original. Defaulttrue.useISODateFormat: boolean, convert datetime to ISO format. Defaulttrue.descriptionMaxLen: number, to truncate description. Default250characters. Set to0= no truncation.xmlParserOptions: object, options passed to the XML parser.getExtraFeedFields: function, to get more fields from feed data.getExtraEntryFields: function, to get more fields from feed entry data.baseUrl: URL string, to absolutify the links within feed content.
For example:
import { extract } from "@extractus/feed-extractor";
await extract("https://news.google.com/atom", {
useISODateFormat: false,
});
await extract("https://news.google.com/rss", {
useISODateFormat: false,
getExtraFeedFields: (feedData) => {
return {
subtitle: feedData.subtitle || "",
};
},
getExtraEntryFields: (feedEntry) => {
const { enclosure, category } = feedEntry;
return {
enclosure: {
url: enclosure["@_url"],
type: enclosure["@_type"],
length: enclosure["@_length"],
},
};
},
});A custom fetch function with the signature (url: string) => Promise<Response>.
Use this to customize HTTP behavior: proxy, headers, TLS, authentication, timeouts, etc.
Defaults to globalThis.fetch.
Deno (with proxy):
import { extract } from "@extractus/feed-extractor";
const client = Deno.createHttpClient({
proxy: { url: "http://proxy.example.com:8080" },
});
const myFetcher = (url: string) => fetch(url, { client });
const result = await extract("https://news.google.com/rss", {}, myFetcher);Node.js (with proxy via undici):
import { extract } from "@extractus/feed-extractor";
import { fetch, ProxyAgent } from "undici";
const dispatcher = new ProxyAgent("http://proxy.example.com:8080");
const myFetcher = (url: string) => fetch(url, { dispatcher });
const result = await extract("https://news.google.com/rss", {}, myFetcher);Bun (with proxy):
import { extract } from "@extractus/feed-extractor";
const myFetcher = (url: string) =>
fetch(url, {
proxy: "http://proxy.example.com:8080",
});
const result = await extract("https://news.google.com/rss", {}, myFetcher);Custom headers:
const myFetcher = (url: string) =>
fetch(url, {
headers: {
"user-agent": "MyBot/1.0",
authorization: "Bearer token123",
},
});
const result = await extract(url, {}, myFetcher);Request timeout:
const myFetcher = (url: string) =>
fetch(url, {
signal: AbortSignal.timeout(5000),
});
const result = await extract(url, {}, myFetcher);Extract feed data from a JSON object or string.
extractFromJson(json: Record<string, unknown> | string): FeedData
extractFromJson(json: Record<string, unknown> | string, options?: ParserOptions): FeedDataExample:
import { extractFromJson } from "@extractus/feed-extractor";
const url = "https://www.jsonfeed.org/feed.json";
const res = await fetch(url);
const json = await res.json();
const feed = extractFromJson(json);
console.log(feed);JSON object or string from a JSON Feed resource.
See options above.
Extract feed data from an XML string.
extractFromXml(xml: string): FeedData
extractFromXml(xml: string, options?: ParserOptions): FeedDataExample:
import { extractFromXml } from "@extractus/feed-extractor";
const url = "https://news.google.com/atom";
const res = await fetch(url);
const xml = await res.text();
const feed = extractFromXml(xml);
console.log(feed);XML string from an RSS/ATOM feed resource.
See options above.
git clone https://github.com/extractus/feed-extractor.git
cd feed-extractor
# Run tests
deno test --allow-all
# Lint
deno lint
# Build npm package
deno task buildThe MIT License (MIT)
This project is maintained in my spare time. If you find it helpful, there are a few simple ways to support its continued development:
- ⭐ Star this repository to help more people discover it.
- ☕ Buy me a coffee: https://paypal.me/ndaidong
- 🚀 Subscribe to the Feed Reader service on RapidAPI.
Every bit of support helps keep this project actively maintained. Thank you! ❤️