0.4.0 • Published 5 years ago
feedify v0.4.0
Feedify
A package for parsing RSS 2.0, Atom 1.0.
Installation
npm add feedify
Usage
Simple
import { parse } from 'feedify';
fetch('https://overreacted.io/rss.xml')
.then(resp => {
return resp.text();
})
.then(text => {
return parse(text);
})
.then(data => {
console.log('Feed: ', data.feed);
console.log('Items: ', data.items);
});
Stream-like
If you want more control you can use parsers directly. E.g.:
import { RSSParser } from 'feedify';
const parser = new RSSParser();
parser.write('<rss> ....');
parser.write('... </rss>');
// ...
// You MUST close the stream or an infinite loop might happen
parser.close();
for (let item of parser.items()) {
console.log(item);
}
console.log(parser.feed());
Error handling
import { parse } from 'feedify';
const text = 'borken feed';
// using .catch
parse(text)
.then(output => console.log(output))
.catch(err => {
console.log('Oops, ', err);
});
// OR, using try catch
try {
const output = await parse(text);
console.log(output);
} catch (err) {
console.log('Oops, ', err);
}
Contributors
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
License
MIT © Ahmed T. Ali