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

google-news-json

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-news-json - npm Package Compare versions

Comparing version 1.0.3 to 2.0.0

.idea/inspectionProfiles/Project_Default.xml

104

lib/index.js

@@ -8,2 +8,17 @@ const GEO = "geo";

let Topics = function() {
if (this.constructor === Topics) {
throw new Error("Can't instantiate abstract class");
}
};
Topics.prototype.WORLD = "WORLD";
Topics.prototype.NATION = "NATION";
Topics.prototype.BUSINESS = "BUSINESS";
Topics.prototype.TECHNOLOGY = "TECHNOLOGY";
Topics.prototype.ENTERTAINMENT = "ENTERTAINMENT";
Topics.prototype.SCIENCE = "SCIENCE";
Topics.prototype.SCIENCE = "SPORTS";
Topics.prototype.SCIENCE = "HEALTH";
const _generateGoogleFeedURL = function(method, query, locale){

@@ -19,3 +34,3 @@ let feedUrl = "https://news.google.com/rss";

case "search":
feedUrl += "/search?q="+query+"&";
feedUrl += encodeURI("/search?q="+query+"&");
break;

@@ -33,2 +48,53 @@ default:

let _parseArr = function(arr){
if(Array.isArray(arr)) {
arr = _shiftArr(arr);
}
if(Array.isArray(arr)) {
for(let i=0; i < (arr || []).length; i++){
arr[i] = _parseArr(arr[i]);
}
} else if(typeof arr === 'object') {
if(arr['_']) arr['text'] = arr['_'];
if(arr['$']) arr = Object.assign({}, arr, arr['$']);
delete arr['_'];
delete arr['$'];
let keys = Object.keys(arr);
for(let n=0; n<keys.length; n++){
if(Array.isArray(arr[keys[n]])) arr[keys[n]] = _parseArr(arr[keys[n]]);
}
}
return arr;
};
let _shiftArr = function(arr){
if(!arr || arr.length > 1) return arr;
return arr.shift();
};
let request = function(url, callback){
let http = require('https');
http.get(url, function(res){
res.on('error',function(err){
callback(err);
});
let data = '';
res.on('data',function(chunk){
data += chunk.toString();
});
res.on('end',function(){
// follow redirect is status code is 302 and new location exists
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
request(res.headers.location, callback);
return;
}
callback(null, data);
});
});
};
/**

@@ -51,12 +117,34 @@ * Get Google's News Feed

// noinspection JSUnresolvedFunction
const Feed = require('rss-to-json');
// noinspection JSUnresolvedFunction
Feed.load(feedUrl, function(err, rss){
if(typeof callback === "function") callback(err, rss);
err ? reject(err) : resolve(rss);
request(feedUrl, function(err, data){
if(err){
if(typeof callback === "function") callback(err);
return reject(err);
}
// noinspection JSUnresolvedFunction,NodeJsCodingAssistanceForCoreModules
let xml2js = require('xml2js');
xml2js.parseString(data, function (err, result) {
if(err){
if(typeof callback === "function") callback(err);
return reject(err);
}
let rss = _parseArr(result['rss']['channel']);
if(typeof callback === "function") callback(err, rss);
resolve(rss);
});
});
// // noinspection JSUnresolvedFunction,NodeJsCodingAssistanceForCoreModules
// let http = require('https');
//
// // noinspection JSUnresolvedFunction
// const feed2json = require('feed2json');
// feed2json.fromStream(http.get(feedUrl), feedUrl, (err, rss) => {
// if(typeof callback === "function") callback(err, rss);
// err ? reject(err) : resolve(rss);
// });
});
};
module.exports = { HIGHLIGHTS, TOP_NEWS, LOCATION, SEARCH, TOPIC, GEO, getNews };
module.exports = { HIGHLIGHTS, TOP_NEWS, LOCATION, SEARCH, TOPIC, GEO, getNews, Topics };

8

package.json
{
"name": "google-news-json",
"version": "1.0.3",
"version": "2.0.0",
"description": "Simple to use google news api",

@@ -17,7 +17,7 @@ "main": "lib/index.js",

"dependencies": {
"rss-to-json": "^1.0.5"
"xml2js": "^0.4.23"
},
"devDependencies": {
"eslint": "^6.5.1",
"mocha": "^6.2.1"
"eslint": "^7.17.0",
"mocha": "^8.2.1"
},

@@ -24,0 +24,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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