Comparing version 1.0.6 to 1.1.0
@@ -5,3 +5,2 @@ "use strict"; | ||
const node_fetch_1 = require("node-fetch"); | ||
const url_1 = require("url"); | ||
const errors_1 = require("./errors"); | ||
@@ -16,17 +15,21 @@ let API_URL = 'http://en.wikipedia.org/w/api.php?', REST_API_URL = 'http://en.wikipedia.org/api/rest_v1/'; | ||
try { | ||
const search = new url_1.URLSearchParams({ ...params }); | ||
search.set('format', 'json'); | ||
const search = { ...params }; | ||
search['format'] = 'json'; | ||
if (redirect) { | ||
search.set('redirects', ''); | ||
search['redirects'] = ''; | ||
} | ||
if (!params.action) | ||
search.set('action', "query"); | ||
search['action'] = "query"; | ||
search['origin'] = '*'; | ||
const options = { | ||
headers: { | ||
'User-Agent': USER_AGENT | ||
'User-Agent': USER_AGENT, | ||
} | ||
}; | ||
const response = await node_fetch_1.default(new url_1.URL(API_URL + search), options); | ||
const responseBuffer = await response.buffer(); | ||
const result = JSON.parse(responseBuffer.toString()); | ||
let searchParam = ''; | ||
Object.keys(search).forEach(key => { | ||
searchParam += `${key}=${search[key]}&`; | ||
}); | ||
const response = await node_fetch_1.default(encodeURI(API_URL + searchParam), options); | ||
const result = await response.json(); | ||
return result; | ||
@@ -49,5 +52,4 @@ } | ||
}; | ||
const response = await node_fetch_1.default(new url_1.URL(REST_API_URL + path), options); | ||
const responseBuffer = await response.buffer(); | ||
const result = JSON.parse(responseBuffer.toString()); | ||
const response = await node_fetch_1.default(encodeURI(REST_API_URL + path), options); | ||
const result = await response.json(); | ||
return result; | ||
@@ -54,0 +56,0 @@ } |
{ | ||
"name": "wikipedia", | ||
"version": "1.0.6", | ||
"version": "1.1.0", | ||
"description": "A JavaScript wrapper for the wikipedia apis", | ||
@@ -5,0 +5,0 @@ "main": "dist", |
# WIKIPEDIA [![build](https://github.com/dopecodez/Wikipedia/workflows/build/badge.svg)](https://github.com/dopecodez/Wikipedia/actions) [![Test Coverage](https://api.codeclimate.com/v1/badges/a44c826dbef8c7f5ea45/test_coverage)](https://codeclimate.com/github/dopecodez/Wikipedia/test_coverage) [![Contributions](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dopecodez/Wikipedia/issues) [![npm version](https://badge.fury.io/js/wikipedia.svg)](https://badge.fury.io/js/wikipedia) | ||
Wikipedia for node. | ||
Wikipedia for node. Works in the browser as well. | ||
@@ -5,0 +5,0 @@ Implements [legacy](https://www.mediawiki.org/wiki/API:Main_page) wiki endpoints and also the newer |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2504
97343