bcomnes / jsonfeed-to-rss

📡Convert a jsonfeed to an RSS 2.0 feed with iTunes extensions
https://jsonfeed-to-rss.netlify.com
MIT License
38 stars 12 forks source link

Data Must be JavaScript object, not JSON Feed #43

Open alexstandiford opened 3 years ago

alexstandiford commented 3 years ago

Hi! Thanks for writing this, it's quite nice!

Currently the docs show this:

const someJSONFeed = require('./load-some-json-feed-data.json')

const rssFeed = jsonfeedToRSS(someJSONFeed) // Returns an rss 2.0.11 formatted json feed

Which implies that the data that is fed to the function needs to be a JSON string, however, it seems that this needs to be a JavaScript object.

I'm not sure if this is a bug, or if the documentation is just misleading.

By providing a JSON string, I received a misleading error mentioned in #32, which made me think that it was because I was missing an argument that I wasn't missing.

It would be helpful if:

  1. The documentation was clarified just a little bit more
  2. Error-handling was in place if the argument provided is not an object.

I'd be happy to spin up a PR, but didn't want to do that until after I raised the issue. Thanks again!

bcomnes commented 3 years ago

Which implies that the data that is fed to the function needs to be a JSON string, however, it seems that this needs to be a JavaScript object.

In CJS, when you require json, it gets passed through JSON.parse automatically resulting in a JS object, though one might not be familiar with that who are new to CJS or node.

I would accept a PR clarifying the API.

malcook commented 9 months ago

though one might not be familiar with that who are new to CJS or node.

... one such as myself ;)

Anyway, trying to write a command-line filter jsonfeed-to-rss, I figured out that I could write it

#!/bin/env node
const jsonfeedToRSS = require('jsonfeed-to-rss')
const someJSONFeed = require('/dev/stdin')
const rssFeed = jsonfeedToRSS(someJSONFeed) // Returns an rss 2.0.11 formatted json feed
console.log(rssFeed)

and invoke it as

./jsonfeed-to-rss <  load-some-json-feed-data.json >  load-some-json-feed-data.rss

which might serve as a good working example instead of (in addition to) your existing USAGE

bcomnes commented 9 months ago

Thats a nice trick! Maybe I should ship a simple CLI with something similar.