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

v2.1.2

Published

A JavaScript wrapper for the wikipedia apis

Downloads

34,386

Readme

WIKIPEDIA build Test Coverage Contributions npm version

Wikipedia for node. Works in the browser as well.

Implements legacy wiki endpoints and also the newer REST API.

Try out the new summary() REST endpoint for a introduction to your page and the main images optimized for browsers and mobile!

You can also now get the events which happened on a particular day using the onThisDay() api, which supports filtering by event types as well.

Built with latest ES6 and native support for async/await and promises.

Built with TypeScript - exports all the types used.

INSTALLATION

$ npm install wikipedia

Highlights

For detailed documentation of methods available on wiki and page,

What can it do?

  • Get a summary for a page which contains the intro and main image optimized for web and mobile with the new wikipedia REST APIs
  • Fetch article content
  • Find all links/images/categories in a page
  • Gets all the relevant events that happened on a particular day. You can further filter this by event type
  • Find related articles from the given article
  • Find articles by geographical location
  • Get a wikipedia page as a pdf document
  • Supports switching languages
  • Parses infoboxes using infobox-parser

Usage

const wiki = require('wikipedia');

(async () => {
	try {
		const page = await wiki.page('Batman');
		console.log(page);
		//Response of type @Page object
		const summary = await page.summary();
		console.log(summary);
		//Response of type @wikiSummary - contains the intro and the main image
	} catch (error) {
		console.log(error);
		//=> Typeof wikiError
	}
})();

The page method returns a Page class object which has fields like pageid, title, parentid, revisionid and methods like summary(), intro(), images(), html() and more.

All the page methods can take a title parameter or a pageId. Read up on the Page documentation here to see a detailed overview of the methods available in page.

You can also call methods like summary() on the wiki object directly. Read up here to see when you should use the page object and when you should call summary() directly. There's a performance difference! Long story short, use the method directly if you are using only the summary of the page and are not expecting to use any of the other page attributes.

const wiki = require('wikipedia');

(async () => {
	try {
		const summary = await wiki.summary('Batman');
		console.log(summary);
		//Response of type @wikiSummary - contains the intro and the main image
	} catch (error) {
		console.log(error);
		//=> Typeof wikiError
	}
})();

You can now get the events which happened on a particular day using the new onThisDay() api on the wiki object.

const wiki = require('wikipedia');

(async () => {
	try {
		const events = await wiki.onThisDay();
		const deaths = await wiki.onThisDay({type:'deaths', month:'2', day:'28'});
		console.log(events); // returns all the events which happened today
		console.log(deaths); // returns all deaths which happened on Feb 28
	} catch (error) {
		console.log(error);
		//=> Typeof wikiError
	}
})();

There are other methods like search(), geoSearch(), suggest(), setLang(), setUserAgent() which should be called on the wiki object directly. Read up on the wiki documentation to see a complete list of methods available on the wiki default object.

const wiki = require('wikipedia');

(async () => {
	try {
		const searchResults = await wiki.search('Batma');
		console.log(searchResults);
		//Response of type @wikiSearchResult - contains results and optionally a suggestion
		const newUrl = await wiki.setLang('fr');
		console.log(newUrl);
		//Returns the api url with language changed - use `languages()` method to see a list of available langs
	} catch (error) {
		console.log(error);
		//=> Typeof wikiError
	}
})();

You can export types or even specific methods if you are using modern ES6 js or TypeScript.

import wiki from 'wikipedia';
import { wikiSummary, summaryError } from 'wikipedia';
import { summary } from 'wikipedia';

(async () => {
	try {
        let summary: wikiSummary; //sets the object as type wikiSummary
		summary = await wiki.summary('Batman');
		console.log(summary);
        let summary2 = await summary('Batman');//using summary directly
	} catch (error) {
		console.log(error);
		//=> Typeof summaryError, helpful in case you want to handle this error separately
	}
})();

Options

All methods have options you can pass them. You can find them in optionTypes documentation.

Result Types

All the returned result types are documented as well. You can find them here.

Contributing

Before opening a pull request please make sure your changes follow the contribution guidelines.

Contributors

The project would not be the way it is without these rockstars.