Gathering detailed insights and metrics for @extractus/feed-extractor
Gathering detailed insights and metrics for @extractus/feed-extractor
Gathering detailed insights and metrics for @extractus/feed-extractor
Gathering detailed insights and metrics for @extractus/feed-extractor
Simplest way to read & normalize RSS/ATOM/JSON feed data
npm install @extractus/feed-extractor
Typescript
Module System
Min. Node Version
Node Version
NPM Version
57.4
Supply Chain
99
Quality
81.8
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
231,572
Last Day
238
Last Week
2,409
Last Month
13,754
Last Year
143,182
170 Stars
272 Commits
33 Forks
5 Watching
1 Branches
11 Contributors
Minified
Minified + Gzipped
Latest Version
7.1.3
Package Id
@extractus/feed-extractor@7.1.3
Unpacked Size
118.61 kB
Size
29.96 kB
File Count
28
NPM Version
10.7.0
Node Version
20.12.2
Publised On
07 May 2024
Cumulative downloads
Total Downloads
Last day
-66.9%
238
Compared to previous day
Last week
-36%
2,409
Compared to previous week
Last month
-23.8%
13,754
Compared to previous month
Last year
63.5%
143,182
Compared to previous year
4
To read & normalize RSS/ATOM/JSON feed data.
(This library is derived from feed-reader renamed.)
1npm i @extractus/feed-extractor
1import { extract } from '@extractus/feed-extractor' 2 3// extract a RSS 4const result = await extract('https://news.google.com/rss') 5console.log(result)
1import { extract } from 'npm:@extractus/feed-extractor'
1import { extract } from 'https://esm.sh/@extractus/feed-extractor'
Please check the examples for reference.
RSS Feed Fetch Action is a GitHub Action designed to automate the fetching of RSS feeds. It fetches an RSS feed from a given URL and saves it to a specified file in your GitHub repository. This action is particularly useful for populating content on GitHub Pages websites or other static site generators.
CJS is deprecated for this package. When calling require('@extractus/feed-extractor')
a deprecation warning is now logged. You should update your code to use the ESM export.
FEED_EXTRACTOR_CJS_IGNORE_WARNING=true
FEED_EXTRACTOR_CJS_TRACE_WARNING=true
read()
has been marked as deprecated and will be removed in next major release.extract()
Load and extract feed data from given RSS/ATOM/JSON source. Return a Promise object.
1extract(String url) 2extract(String url, Object parserOptions) 3extract(String url, Object parserOptions, Object fetchOptions)
Example:
1import { extract } from '@extractus/feed-extractor'
2
3const result = await extract('https://news.google.com/atom')
4console.log(result)
Without any options, the result should have the following structure:
1{ 2 title: String, 3 link: String, 4 description: String, 5 generator: String, 6 language: String, 7 published: ISO Date String, 8 entries: Array[ 9 { 10 id: String, 11 title: String, 12 link: String, 13 description: String, 14 published: ISO Datetime String 15 }, 16 // ... 17 ] 18}
url
requiredURL of a valid feed source
Feed content must be accessible and conform one of the following standards:
parserOptions
optionalObject 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, used by xml parser, view fast-xml-parser's docsgetExtraFeedFields
: Function, to get more fields from feed datagetExtraEntryFields
: Function, to get more fields from feed entry databaseUrl
: URL string, to absolutify the links within feed contentFor example:
1import { extract } from '@extractus/feed-extractor' 2 3await extract('https://news.google.com/atom', { 4 useISODateFormat: false 5}) 6 7await extract('https://news.google.com/rss', { 8 useISODateFormat: false, 9 getExtraFeedFields: (feedData) => { 10 return { 11 subtitle: feedData.subtitle || '' 12 } 13 }, 14 getExtraEntryFields: (feedEntry) => { 15 const { 16 enclosure, 17 category 18 } = feedEntry 19 return { 20 enclosure: { 21 url: enclosure['@_url'], 22 type: enclosure['@_type'], 23 length: enclosure['@_length'] 24 }, 25 category: isString(category) ? category : { 26 text: category['@_text'], 27 domain: category['@_domain'] 28 } 29 } 30 } 31})
fetchOptions
optionalfetchOptions
is an object that can have the following properties:
headers
: to set request headersproxy
: another endpoint to forward the request toagent
: a HTTP proxy agentsignal
: AbortController signal or AbortSignal timeout to terminate the requestFor example, you can use this param to set request headers to fetch as below:
1import { extract } from '@extractus/feed-extractor' 2 3const url = 'https://news.google.com/rss' 4await extract(url, null, { 5 headers: { 6 'user-agent': 'Opera/9.60 (Windows NT 6.0; U; en) Presto/2.1.1' 7 } 8})
You can also specify a proxy endpoint to load remote content, instead of fetching directly.
For example:
1import { extract } from '@extractus/feed-extractor' 2 3const url = 'https://news.google.com/rss' 4 5await extract(url, null, { 6 headers: { 7 'user-agent': 'Opera/9.60 (Windows NT 6.0; U; en) Presto/2.1.1' 8 }, 9 proxy: { 10 target: 'https://your-secret-proxy.io/loadXml?url=', 11 headers: { 12 'Proxy-Authorization': 'Bearer YWxhZGRpbjpvcGVuc2VzYW1l...' 13 } 14 } 15})
Passing requests to proxy is useful while running @extractus/feed-extractor
on browser.
View examples/browser-feed-reader
as reference example.
Another way to work with proxy is use agent
option instead of proxy
as below:
1import { extract } from '@extractus/feed-extractor' 2 3import { HttpsProxyAgent } from 'https-proxy-agent' 4 5const proxy = 'http://abc:RaNdoMpasswORd_country-France@proxy.packetstream.io:31113' 6 7const url = 'https://news.google.com/rss' 8 9const feed = await extract(url, null, { 10 agent: new HttpsProxyAgent(proxy), 11}) 12console.log('Run feed-extractor with proxy:', proxy) 13console.log(feed)
For more info about https-proxy-agent, check its repo.
By default, there is no request timeout. You can use the option signal
to cancel request at the right time.
The common way is to use AbortControler:
1const controller = new AbortController() 2 3// stop after 5 seconds 4setTimeout(() => { 5 controller.abort() 6}, 5000) 7 8const data = await extract(url, null, { 9 signal: controller.signal, 10})
A newer solution is AbortSignal's timeout()
static method:
1// stop after 5 seconds 2const data = await extract(url, null, { 3 signal: AbortSignal.timeout(5000), 4})
For more info:
extractFromJson()
Extract feed data from JSON string. Return an object which contains feed data.
1extractFromJson(String json) 2extractFromJson(String json, Object parserOptions)
Example:
1import { extractFromJson } from '@extractus/feed-extractor' 2 3const url = 'https://www.jsonfeed.org/feed.json' 4// this resource provides data in JSON feed format 5// so we fetch remote content as json 6// then pass to feed-extractor 7const res = await fetch(url) 8const json = await res.json() 9 10const feed = extractFromJson(json) 11console.log(feed)
json
requiredJSON string loaded from JSON feed resource.
parserOptions
optionalSee parserOptions above.
extractFromXml()
Extract feed data from XML string. Return an object which contains feed data.
1extractFromXml(String xml) 2extractFromXml(String xml, Object parserOptions)
Example:
1import { extractFromXml } from '@extractus/feed-extractor' 2 3const url = 'https://news.google.com/atom' 4// this resource provides data in ATOM feed format 5// so we fetch remote content as text 6// then pass to feed-extractor 7const res = await fetch(url) 8const xml = await res.text() 9 10const feed = extractFromXml(xml) 11console.log(feed)
xml
requiredXML string loaded from RSS/ATOM feed resource.
parserOptions
optionalSee parserOptions above.
1git clone https://github.com/extractus/feed-extractor.git 2cd feed-extractor 3pnpm i 4pnpm test
1git clone https://github.com/extractus/feed-extractor.git 2cd feed-extractor 3pnpm i 4pnpm eval https://news.google.com/rss
The MIT License (MIT)
If you find value from this open source project, you can support in the following ways:
Thank you.
No vulnerabilities found.
No security vulnerabilities found.