syndication
Version:
A library written in NodeJS for Syndicating RSS & ATOM based feeds. It is a Promise based library which extends feedparser.
102 lines (76 loc) • 2.46 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: feedparserPromise.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: feedparserPromise.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* Require Statements to get the two dependencies
* 1. Require Module
* 2. FeedParser Module
*/
var request = require('request'),
FeedParser = require('feedparser');
/**
* Represents a FeedParserPromise
* @constructor
*/
var FeedParserPromise = function() {
};
/**
* This is an instance member of FeedParserPromise class, FeedParserPromise#fetch.
* @memberof FeedParserPromise.prototype
* @param {string} URL for which the feed is required.
*/
FeedParserPromise.prototype.fetch = function(options) {
return new Promise(function(resolve, reject) {
const feedparser = new FeedParser();
var items=[];
feedparser.on('error', (error) => {
reject(error);
});
feedparser.on('readable', () => {
var item;
while (item = feedparser.read()) {
items.push(item);
}
return items;
});
request.get(options)
.on('error', (error) => {
reject(error);
})
.pipe(feedparser)
.on('end', () => {
return resolve(items);
});
});
}
module.exports = FeedParserPromise;
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="FeedParserPromise.html">FeedParserPromise</a></li></ul><h3>Global</h3><ul><li><a href="global.html#request">request</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Sat Aug 06 2016 08:50:45 GMT+0000 (UTC)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>