Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

find-rss

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-rss - npm Package Compare versions

Comparing version 1.3.6 to 1.3.7

178

lib/find-rss.js
(function() {
var async, htmlparser, iconv, jschardet, request, requestAndEncodeWithDetectCharset, url;
htmlparser = require("htmlparser2");
jschardet = require("jschardet");
iconv = require('iconv');
async = require('async');
url = require('url');
request = require('request');
module.exports = function(req, callback) {
var argumentIsCandidate, async, candidates, favicon, htmlparser, iconv, jschardet, parser, request, sitename, sitenameFlag, url;
htmlparser = require("htmlparser2");
jschardet = require("jschardet");
iconv = require('iconv');
async = require('async');
url = require('url');
request = require('request');
var argumentIsCandidate, candidates, favicon, feedTitle, parser, sitename, sitenameFlag, urlObject;
candidates = [];

@@ -14,2 +22,3 @@ sitename = '';

favicon = '';
feedTitle = '';
argumentIsCandidate = false;

@@ -32,2 +41,5 @@ parser = new htmlparser.Parser({

ontext: function(text) {
if (sitename === '' && argumentIsCandidate) {
feedTitle = text;
}
if (sitenameFlag) {

@@ -42,61 +54,101 @@ return sitename = text;

}
}, {
recognizeCDATA: true
});
return request.get({
uri: req,
encoding: null
}, function(err, res, body) {
var charset, converter, obj;
if (err != null) {
callback(err, null);
return;
urlObject = url.parse(req);
return requestAndEncodeWithDetectCharset(req, function(err, body) {
if (err) {
return callback(err, null);
}
obj = url.parse(req);
charset = jschardet.detect(body).encoding;
if (charset !== ('utf-8' || 'UTF-8')) {
converter = new iconv.Iconv(charset, 'utf-8');
body = converter.convert(body).toString();
}
parser.write(body);
parser.end();
if (argumentIsCandidate) {
candidates = [
{
title: req,
sitename: req,
url: req,
href: req
}
];
}
return async.forEach(candidates, function(cand, cb) {
var guess;
cand.sitename || (cand.sitename = sitename);
if (cand.href.match(/[http|https]:\/\//)) {
cand.url = cand.href;
} else {
cand.url = "" + obj.protocol + "//" + obj.host + cand.href;
}
if (favicon.length > 0) {
if (favicon.match(/[http|https]:\/\//)) {
cand.favicon = favicon;
return async.series([
function(cb) {
if (argumentIsCandidate) {
candidates = [
{
title: feedTitle,
sitename: req,
url: req,
href: req
}
];
return cb();
} else {
if (favicon.charAt(0) === '/') {
cand.favicon = "" + obj.protocol + "//" + obj.host + favicon;
return async.forEach(candidates, function(cand, _cb) {
cand.sitename = sitename;
if (cand.href.match(/[http|https]:\/\//)) {
cand.url = cand.href;
} else {
cand.url = "" + urlObject.protocol + "//" + urlObject.host + cand.href;
}
return requestAndEncodeWithDetectCharset(cand.url, function(err, body) {
var innerFeedTitle, innerParser, isFeed, titleFlag;
if (err) {
return _cb();
}
innerFeedTitle = '';
isFeed = false;
titleFlag = false;
innerParser = new htmlparser.Parser({
onopentag: function(name, attr) {
if (["feed", "rss", "atom"].indexOf(name) > -1) {
isFeed = true;
}
if (name === "title") {
return titleFlag = true;
}
},
ontext: function(text) {
if (titleFlag && isFeed) {
return innerFeedTitle || (innerFeedTitle = text);
}
},
onclosetag: function(name) {
if (name === "title") {
return titleFlag = false;
}
}
}, {
recognizeCDATA: true
});
innerParser.write(body);
innerParser.end();
cand.title = unescape(innerFeedTitle);
return _cb();
});
}, function() {
return cb();
});
}
}, function(cb) {
return async.forEach(candidates, function(cand, _cb) {
var guess;
if (favicon.length > 0) {
if (favicon.match(/[http|https]:\/\//)) {
cand.favicon = favicon;
return _cb();
} else {
if (favicon.charAt(0) === '/') {
cand.favicon = "" + urlObject.protocol + "//" + urlObject.host + favicon;
return _cb();
} else {
cand.favicon = "" + urlObject.protocol + "//" + urlObject.host + "/" + favicon;
return _cb();
}
}
} else {
cand.favicon = "" + obj.protocol + "//" + obj.host + "/" + favicon;
return cb();
guess = "" + urlObject.protocol + "//" + urlObject.host + "/favicon.ico";
return request(guess, function(err, res, body) {
if (res.statusCode === 200) {
cand.favicon = guess;
}
return _cb();
});
}
}
} else {
guess = "" + obj.protocol + "//" + obj.host + "/favicon.ico";
return request(guess, function(err, res, body) {
if (res.statusCode === 200) {
cand.favicon = guess;
}
}, function() {
return cb();
});
}
}, function() {
], function() {
if (candidates.length === 0) {

@@ -111,2 +163,20 @@ return callback(new Error('NotFoundRSSFeedError'), null);

requestAndEncodeWithDetectCharset = function(url, callback) {
return request.get({
uri: url,
encoding: null
}, function(err, res, body) {
var charset, converter;
if (err) {
return callback(err, null);
}
charset = jschardet.detect(body).encoding;
if (charset !== ('utf-8' || 'UTF-8')) {
converter = new iconv.Iconv(charset, 'utf-8');
body = converter.convert(body).toString();
}
return callback(null, body);
});
};
}).call(this);
{
"name": "find-rss",
"description": "find rss feeds",
"version": "1.3.6",
"version": "1.3.7",
"author": "nikezono",

@@ -6,0 +6,0 @@ "dependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc