Skip to main content
Deno 2 is finally here 🎉️
Learn more

DenoWiki

GitHub license GitHub tag HitCount deno doc deno.land

A simple API for DenoJS to query Wikipedia and parse the results.

Usage

import * as wiki from "https://deno.land/x/denowiki/mod.ts";

const wikiSearchResult: wiki.WikiSearch_Query = await wiki.wikiSearch(
  { language: "en", srsearch: "doctor who", srlimit: 15 },
);
const pageID: number = wiki.getPageId(wikiSearchResult);
const wikiPage: wiki.WikiParse_Query = await wiki.wikiParse(
    { pageid: pageID, language: "en", prop: "wikitext|text" },
  );
const text: string = wiki.getWikiText(wikiPage);

console.log(text);

This module use the Wikipedia API:Search and API:Parsing wikitext.

Require deno (obviously) and --allow-net permission.

There are 2 demos available. The first demo queries Wikipedia and print the first result

deno run --allow-net .\demo_cmd.ts milan en false
deno run --allow-net .\demo_cmd.ts "doctor who" en true

The second demo searches a list of people and return how many exist in Wikipedia

deno run --allow-net .\demo_array.ts

You can run the demos directly from the repository with the commands:

deno run --allow-net https://deno.land/x/denowiki/demo_cmd.ts milan en false
deno run --allow-net https://deno.land/x/denowiki/demo_cmd.ts "doctor who" en true
deno run --allow-net https://raw.githubusercontent.com/el3um4s/DenoWiki/master/demo_array.ts

API: wikiSearch

  • function wikiSearch(options): Promise : Search for a term on Wikipedia and return the corresponding pages (max 500)
  • function getPageId(wikiJSON: WikiSearch_Query, position): number : Returns the pageID number of Wikipedia referring to the searched term
  • function getSearchTitle(wikiJSON: WikiSearch_Query, position): string : Returns the Title of Wikipedia referring to the searched term
  • function getNumberResults(wikiJSON: WikiSearch_Query): number : Returns the total number of matches found for the search term. May be bigger than the results returned by wikiSearch(options)
  • function getNumberResultsListed(wikiJSON: WikiSearch_Query): number : Returns the number of results found by wikiSearch(options)
  • function getSuggestion(wikiJSON: WikiSearch_Query): string : Returns the suggested term related to the searched term
  • function hasResult(wikiJSON: WikiSearch_Query): boolean : TRUE if there are results for the searched term
  • function hasSuggestion(wikiJSON: WikiSearch_Query): boolean : TRUE if there are suggested searches related to the searched term
  • function wikiSearchQuery(options): string : Returns the url address to be used as the source to obtain the information

API: wikiParse

  • function wikiParse(options): Promise : Returns the contents of a Wikipedia page
  • function getWikiText(wikiPage: WikiParse_Query): string : Returns the original wikitext.
  • function getHTMLText(wikiPage: WikiParse_Query): string : Returns the parsed text of the wikitext.
  • function getPageTitle(wikiPage: WikiParse_Query): string : Returns the Title of Wikipedia referring to the page searched
  • function wikiParseQuery(options): string: Returns the url address to be used as the source to obtain the information