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

wikiq

v0.0.8

Published

Query wikipedia with MediaWiki | Wiki Pages | Categories

Downloads

3

Readme

WikiQ

WikiQ allows you to query wikipedia pages and other info using WikiMedia API. WikiMedia is pretty well documented, this provides a NodeJS adapter to query different information from Wikipedia as:

See APIs details here

Install using npm:

npm install ---save wikiq

Parse Pages

To parse and get content of page Zika_virus:

var wiki = require("wikiq")();

wiki.page("Zika_virus").parse(function(err, resp) {

    console.log("got page resp, err: %s", err);
    console.log(resp);
});

To get custom properties:

var wiki = require("wikiq")();

wiki.page("Zika_virus").prop(["sections", "templates"])
    .parse(function(err, resp) {

    console.log("got page resp, err: %s", err);
    console.log(resp);
});

See more detail about properties here

Query Pages

To query page Zika_virus:

var wiki = require("wikiq")();

wiki.page("Zika_virus").query(function(err, resp) {

    console.log("got page resp, err: %s", err);
    console.log(resp);
});

Similary can specify custom properties, as in parse using prop method

See more detail about properties here

Get Category Tree

Category tree provides the category tree for a page title, you can query the same using:

var wiki = require("wikiq")();

wiki.category("Malaria").tree(function(err, resp) {

    console.log("got category resp, err: %s", err);
    console.log(resp);
});

See more detail about properties here

Query Template Info

Wikipedia has lot of templates, or you can create a new template - which are used across lot of pages in Wikipedia. To query a template info:

var wiki = require("wikiq")();

wiki.template("About").data(function(err, resp) {

    console.log("got template info resp, err: %s", err);
    console.log(resp);
});

See more detail about properties here

API

Wikiq API is simple, once you have required wikiq, you simply select the type of api:

Every type has these common methods:

  • format (string): format of the response. Wikipedia suppports
    • json
    • none
    • php
    • xml
  • prop (string or array): specify list of properties to fetch, varies as per the API type

Also the method follows fluent interface, so you can kepp on piping API calls.

wiki.api()
      .format('json')
      .action('query')
      ...

Page API

Page API has following methods:

  • query (callback): query a page, using action:query
  • parse (callback): parse a page, using action:parse
  • templates (callback): gets the templates in a page
  • sections (callback): gets the sections in a page
  • xml (callback): gets the complete xml parsetree of page
  • images (callback): gets the images of page

Category API

Category API has following methods:

  • tree (callback): gets the category tree

Template API

Template API has following methods:

  • data (callback): gets the template data

Custom API

You can hit your own custom API or action as they are in Wikimedia:

wiki.api()
      .format('json')
      .action('query')
      .title('Malaria')
      .props('images')
      .hit(done)