@extractus/feed-extractor

中文文档
8.0.3发布于 2026/08/06MITTypeScriptESM + CJS近 30 天下载 8.6万

To read and normalize RSS/ATOM/JSON feed data

原始使用文档
文档目录11 节
  1. Installation
  2. Deno
  3. Node.js / Bun
  4. Usage
  5. APIs
  6. extract()
  7. extractFromJson()
  8. extractFromXml()
  9. Development
  10. License
  11. Support the project

feed-extractor

To read & normalize RSS/ATOM/JSON feed data.

JSR npm version CI test

Installation

Deno

deno add jsr:@extractus/feed-extractor

Node.js / Bun

pnpm add jsr:@extractus/feed-extractor
# or
npx jsr add @extractus/feed-extractor
# or
bunx jsr add @extractus/feed-extractor

Alternatively, install from npm:

npm install @extractus/feed-extractor
# or
bun add @extractus/feed-extractor

Usage

import { extract } from "@extractus/feed-extractor";

const data = await extract("https://news.google.com/atom");
console.log(data);

APIs


extract()

Load and extract feed data from given RSS/ATOM/JSON source.

Syntax

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
  }>;
}

Parameters

url required

URL of a valid feed source.

Feed content must be accessible and conform to one of the following standards:

options optional

Object with all or several of the following properties:

  • normalization: boolean, normalize feed data or keep original. Default true.
  • useISODateFormat: boolean, convert datetime to ISO format. Default true.
  • descriptionMaxLen: number, to truncate description. Default 250 characters. Set to 0 = 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"],
      },
    };
  },
});
fetcher optional

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);

extractFromJson()

Extract feed data from a JSON object or string.

Syntax

extractFromJson(json: Record<string, unknown> | string): FeedData
extractFromJson(json: Record<string, unknown> | string, options?: ParserOptions): FeedData

Example:

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);

Parameters

json required

JSON object or string from a JSON Feed resource.

options optional

See options above.


extractFromXml()

Extract feed data from an XML string.

Syntax

extractFromXml(xml: string): FeedData
extractFromXml(xml: string, options?: ParserOptions): FeedData

Example:

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);

Parameters

xml required

XML string from an RSS/ATOM feed resource.

options optional

See options above.


Development

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 build

License

The MIT License (MIT)

Support the project

This project is maintained in my spare time. If you find it helpful, there are a few simple ways to support its continued development:

Every bit of support helps keep this project actively maintained. Thank you! ❤️


版本与发布记录

@extractus/feed-extractor 共发布 39 个版本,首次发布于 2022/11/29;过去 12 个月发布了 4 个版本。

版本发布日期距今
8.0.3latest2026/08/063 个月前
8.0.22026/08/063 个月前
7.2.12026/05/036 个月前
7.2.02026/05/036 个月前
7.1.72025/09/041.2 年前
7.1.62025/05/141.5 年前

关于 @extractus/feed-extractor 的常见问题

@extractus/feed-extractor 是什么?

To read and normalize RSS/ATOM/JSON feed data

如何安装 @extractus/feed-extractor?

在项目目录运行 npm install @extractus/feed-extractor,或使用 pnpm add / yarn add / bun add。

@extractus/feed-extractor 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@extractus/feed-extractor 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@extractus/feed-extractor 可以商用吗?

@extractus/feed-extractor 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@extractus/feed-extractor 的下载量有多少?

根据 npm 官方下载统计,@extractus/feed-extractor 在 2026/10/14 – 2026/11/12 这 30 天内被下载 85,978 次,日均约 2,866 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@extractus/feed-extractor 还在维护吗?

最新版本 8.0.3 发布于 2026/08/06(3 个月前);至今共发布 39 个版本,其中过去 12 个月发布了 4 个;首次发布于 2022/11/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。