extractus / feed-extractor

Simplest way to read & normalize RSS/ATOM/JSON feed data

Home Page:https://extractor-demos.pages.dev/feed-extractor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add support for fetch options

dsl101 opened this issue · comments

I needed to be able to pass options to the underlying fetch to adjust timeout, etc. Here's a patch to enable that, in case it's of use to anyone else:

@@ -15,9 +15,9 @@
 var isArray = bella.isArray;
 var isObject = bella.isObject;

-var toJSON = (source) => {
+var toJSON = (source, opts) => {
   return new Promise((resolve, reject) => {
-    fetch(source).then((res) => {
+    fetch(source, opts).then((res) => {
       if (res.ok && res.status === 200) {
         return res.text();
       }
@@ -174,9 +174,9 @@
 };


-var parse = (url) => {
+var parse = (url, opts = {}) => {
   return new Promise((resolve, reject) => {
-    toJSON(url).then((o) => {
+    toJSON(url, opts).then((o) => {
       let result;
       if (o.rss && o.rss.channel) {
         let t = o.rss.channel;

@dsl101 can you implement this feature and contribute 👍

Hi - sorry, I don't have time to go through the hoops now I'm afraid, as I decided to take a different approach (which doesn't use feed-reader). But those 2 lines above are all that's needed I think.

@dsl101 ok, thanks. I will try doing it by myself.