Socket
Socket
Sign inDemoInstall

wikipedia-api

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    wikipedia-api

wikipedia api


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

wikipedia logo

Github: repository Twitter: @falcon_stefano

wikipedia-api

This code exports a set of functions to interact with the Wikipedia API. The functions include:

autocomplete

Suggest Wikipedia article titles matching the input query. The function returns the list of suggestions and the status of the response.

The function accepts one parameter:

  • query: A string representing the search to be performed

The function uses the Fetch API to send an HTTP request to the Wikipedia API and returns the result as a JSON object. If the HTTP request returns a status other than 200, the function returns a response with a status of 400 and an undefined result.

@IAutocomplete

Example

const autocompleteResult:IAutocomplete = await autocomplete('batman');
console.log('autocompleteResult =>', autocompleteResult);

Search Wikipedia articles matching the input query. The function returns the search results, a suggestion if available, and the status of the response.

The function accepts two parameters:

  • query: A string representing the search to be performed.
  • limit: An optional number that indicates the maximum number of results to receive. By default, this number is 10. The max value is 500.

The function uses the Fetch API to send an HTTP request to the Wikipedia API and returns the result as a JSON object. If the HTTP request returns a status other than 200, the function returns a response with a status of 400 and an undefined result.

@ISearch

Example

const searchResult:ISearch = await search('batman');
console.log('searchResult =>', searchResult);

const searchResult:ISearch = await search('batman', 50);
console.log('searchResult =>', searchResult);

page

Retrieve information about a specific page using the REST API. The function returns the title, the content of the article, and the status of the response.

The function accepts one parameter:

  • query: A string representing the search to be performed.

The function uses the Fetch API to send an HTTP request to the Wikipedia API and returns the result as a JSON object. If the HTTP request returns a status other than 200, the function returns a response with a status of 400 and an undefined result.

@IPage

Example

const pageResult:IPage = await page('batman');
console.log('pageResult =>', pageResult);

pageOld

Retrieve information about a specific page using the the older version of Wikipedia . The function returns the result of the page, and the status of the response.

The function accepts one parameter:

  • query: A string representing the title of the page you want to retrieve information about.

The function uses the Fetch API to send an HTTP request to the Wikipedia API and returns the result as a JSON object. If the HTTP request returns a status other than 200, the function returns a response with a status of 400 and an undefined result.

@IPageOld

Example

const pageOldResult:IPageOld= await pageOld('superman');
console.log('pageOldResult =>', pageOldResult);

onThisDay

Retrieve a list of events that happened ont the same day of the month. The function returns the list of events, the type of events, and the status of the response.

The function accepts three parameters:

  • type:onThisDayType This parameter specifies the type of information to be fetched. It can be one of the following: 'all', 'selected', 'births', 'deaths', 'events', 'holidays'. The default value is 'all'.
  • month: string This parameter specifies the month for which the information is to be fetched. The default value is the current month.2 or 02.
  • day: string This parameter specifies the day for which the information is to be fetched. The default value is the current day.2 or 02.

The function uses the Fetch API to send an HTTP request to the Wikipedia API and returns the result as a JSON object. If the HTTP request returns a status other than 200, the function returns a response with a status of 400 and an undefined result.

@IOnThisDay

Example

const onThisDayResult:IOnThisDay = await onThisDay();
console.log('onThisDayResult =>', onThisDayResult?.result);

const onThisDayResult:IOnThisDay = await onThisDay('deaths');
console.log('onThisDayResult =>', onThisDayResult?.result?.deaths);

const onThisDayResult:IOnThisDay = await onThisDay('deaths', '01', '01');
console.log('onThisDayResult =>', onThisDayResult?.result?.deaths);

popup

Retrieve information about the hyperlink, The function returns an object of type IPopupItem and the status of the response.

The function accepts one parament:

  • query: A string representing the search to be performed.

The function uses the Fetch API to send an HTTP request to the Wikipedia API and returns the result as a JSON object. If the HTTP request returns a status other than 200, the function returns a response with a status of 400 and an undefined result.

@IPopup

Example

const popupResult:IPopup = await popup('batman');
console.log('popupResult =>', popupResult);

Autor

autor: alex falcon flores
Alex Stefano Falcon Flores

Github: alexfalconflores Twitter: @falcon_stefano

Keywords

FAQs

Last updated on 05 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc