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

ts-newsapi

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-newsapi - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

79

lib/index.js

@@ -13,14 +13,2 @@ "use strict";

}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __exportStar = (this && this.__exportStar) || function(m, exports) {

@@ -42,4 +30,4 @@ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);

Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
const querystring = __importStar(require("querystring"));
const node_fetch_1 = __importDefault(require("node-fetch"));
const querystring_1 = __importDefault(require("querystring"));
__exportStar(require("./types"), exports);

@@ -72,23 +60,24 @@ /**

}
const queries = [querystring.stringify({ apiKey: this._apiKey })];
const queries = [querystring_1.default.stringify({ apiKey: this._apiKey })];
if (params.q) {
queries.push(querystring.stringify({ q: params.q }));
queries.push(querystring_1.default.stringify({ q: params.q }));
}
if (params.country) {
queries.push(querystring.stringify({ country: params.country }));
queries.push(querystring_1.default.stringify({ country: params.country }));
}
if (params.category) {
queries.push(querystring.stringify({ category: params.category }));
queries.push(querystring_1.default.stringify({ category: params.category }));
}
if (params.sources && params.sources.length) {
queries.push(querystring.stringify({ sources: params.sources.join(',') }));
queries.push(querystring_1.default.stringify({ sources: params.sources.join(',') }));
}
if (params.pageSize) {
queries.push(querystring.stringify({ pageSize: params.pageSize }));
queries.push(querystring_1.default.stringify({ pageSize: params.pageSize }));
}
if (params.page) {
queries.push(querystring.stringify({ page: params.page }));
queries.push(querystring_1.default.stringify({ page: params.page }));
}
const response = yield axios_1.default.get(`${endpointUrl}?${queries.join('&')}`);
return response.data;
const response = yield (0, node_fetch_1.default)(`${endpointUrl}?${queries.join('&')}`);
const data = yield response.json();
return data;
});

@@ -105,38 +94,39 @@ }

const endpointUrl = `${NewsAPI._URL}/everything`;
const queries = [querystring.stringify({ apiKey: this._apiKey })];
const queries = [querystring_1.default.stringify({ apiKey: this._apiKey })];
if (params.q) {
queries.push(querystring.stringify({ q: params.q }));
queries.push(querystring_1.default.stringify({ q: params.q }));
}
if (params.qInTitle) {
queries.push(querystring.stringify({ qInTitle: params.qInTitle }));
queries.push(querystring_1.default.stringify({ qInTitle: params.qInTitle }));
}
if (params.sources && params.sources.length) {
queries.push(querystring.stringify({ sources: params.sources.join(',') }));
queries.push(querystring_1.default.stringify({ sources: params.sources.join(',') }));
}
if (params.domains && params.domains.length) {
queries.push(querystring.stringify({ domains: params.domains.join(',') }));
queries.push(querystring_1.default.stringify({ domains: params.domains.join(',') }));
}
if (params.excludeDomains && params.excludeDomains.length) {
queries.push(querystring.stringify({ excludeDomains: params.excludeDomains.join(',') }));
queries.push(querystring_1.default.stringify({ excludeDomains: params.excludeDomains.join(',') }));
}
if (params.from) {
queries.push(querystring.stringify({ from: params.from }));
queries.push(querystring_1.default.stringify({ from: params.from }));
}
if (params.to) {
queries.push(querystring.stringify({ to: params.to }));
queries.push(querystring_1.default.stringify({ to: params.to }));
}
if (params.language) {
queries.push(querystring.stringify({ language: params.language }));
queries.push(querystring_1.default.stringify({ language: params.language }));
}
if (params.sortBy) {
queries.push(querystring.stringify({ sortBy: params.sortBy }));
queries.push(querystring_1.default.stringify({ sortBy: params.sortBy }));
}
if (params.pageSize) {
queries.push(querystring.stringify({ pageSize: params.pageSize }));
queries.push(querystring_1.default.stringify({ pageSize: params.pageSize }));
}
if (params.page) {
queries.push(querystring.stringify({ page: params.page }));
queries.push(querystring_1.default.stringify({ page: params.page }));
}
const response = yield axios_1.default.get(`${endpointUrl}?${queries.join('&')}`);
return response.data;
const response = yield (0, node_fetch_1.default)(`${endpointUrl}?${queries.join('&')}`);
const data = yield response.json();
return data;
});

@@ -152,14 +142,15 @@ }

const endpointUrl = `${NewsAPI._URL}/sources`;
const queries = [querystring.stringify({ apiKey: this._apiKey })];
const queries = [querystring_1.default.stringify({ apiKey: this._apiKey })];
if (params.category) {
queries.push(querystring.stringify({ category: params.category }));
queries.push(querystring_1.default.stringify({ category: params.category }));
}
if (params.language) {
queries.push(querystring.stringify({ language: params.language }));
queries.push(querystring_1.default.stringify({ language: params.language }));
}
if (params.country) {
queries.push(querystring.stringify({ country: params.country }));
queries.push(querystring_1.default.stringify({ country: params.country }));
}
const response = yield axios_1.default.get(`${endpointUrl}?${queries.join('&')}`);
return response.data;
const response = yield (0, node_fetch_1.default)(`${endpointUrl}?${queries.join('&')}`);
const data = yield response.json();
return data;
});

@@ -169,2 +160,2 @@ }

exports.default = NewsAPI;
NewsAPI._URL = 'http://newsapi.org/v2';
NewsAPI._URL = 'https://newsapi.org/v2';
{
"name": "ts-newsapi",
"version": "1.0.1",
"version": "1.0.2",
"description": "Client library (SDK) to quickly and easily get started with News API without worrying about the underlying set up",

@@ -31,3 +31,3 @@ "main": "lib/index.js",

"dependencies": {
"axios": "^1.2.0"
"node-fetch": "^2.6.7"
},

@@ -37,2 +37,3 @@ "devDependencies": {

"@types/node": "^18.11.10",
"@types/node-fetch": "^2.6.2",
"@typescript-eslint/eslint-plugin": "^5.45.0",

@@ -39,0 +40,0 @@ "@typescript-eslint/parser": "^5.45.0",

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