npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wikipedia-api

v0.0.3

Published

wikipedia api

Downloads

16

Readme

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

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