RSS Pulse Feed Parser
This is a lightweight and robust RSS, Atom and JSON feeds parser with no dependencies.
Pulse Feed Reader is an example of using this parser.
NOTE: The library is under development, so the bugs can happen, and the API may change.
It was designed to be running right in the browser, but you can easily use it in the Node.js environment.
- 📦 Lightweight (~5kb)
- 🚀 Fast (using Web API)
- 👌 No dependencies
- 😲 IE 9+ (note)
- 🏗 Extendable
- 👮♂️ Typed with TypeScript
Supported Feed Types:
- RSS 0.90, 0.92, 0.93, 0.94, 1.0, 2.0
- Atom 0.3, 1.0
- Netscape RSS 0.91
- Userland RSS 0.91
Core Concepts
pulse-feed-parser
is build upon DOMParser and TreeWalker.
Nowadays there's no need in third-party XML or JSON parsers.
All things we need work well out of the box in every modern browser since IE9.
It parses the given URL or Document instance, detecting the type of the given feed, and unifies the result into common Feed structure.
Feed is the universal Feed type that Atom and RSS gets translated to. It represents a web feed.
;
Extensions
Extensions found in feeds will be saved into extensions
property this way:
You can use this data on your own - mix it with the main feed data (like titles, dates, descriptions, etc.) or handle it differently.
Invalid Feeds
This library can successfully handle any XML document, no matter it follows strictly the RSS spec, or not. As long as it can be parsed with DOMParser, it should work.
Polyfills
If you are running pulse-rss-parser
in the browser environment, and you indeed need to support too old browsers, you have to include some polyfills, which with high probability you are already using:
- Array.includes
- Map
- fetch
- Promise
Running in Node.js
Node.js doesn't have some Web APIs used in pulse-rss-parser
, so you should take care of them.
You can use jest's jsdom for things such as DOMParser and TreeWalker. For fetch
node-fetch can be used.
Error Handling
There are 2 exception types, representing different circumstances that broke the parsing process:
- NetworkError - thrown if fetch got in response status different from 2xx
- FeedTypeError - thrown if it's impossible to detect the type of the feed
Examples
Parsing from a URL
; ;;
Parsing a Document instance
; ;;;
Error handling
; try catch e
Manually detecting feed type
; ;
Calling concrete parser directly
; ;;