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

wikiquote-api

v0.2.0

Published

Small API for Wikiquote

Downloads

38

Readme

Wikiquote API

Pipeline status Published on NPM

Small APi for Wikiquote

How to install

With Yarn

yarn add wikiquote-api

or with NPM

npm install wikiquote-api --save

How to use

Import library

ES2017 Module style

In browser
<script type="text/javascript" src="./node_modules/babel-polyfill/dist/polyfill.js"></script>
<script type="module" src="./node_modules/wikiquote-api/dist/WikiquoteApi.module.mjs"></script>
In Node
import 'babel-polyfill'
import WikiquoteApi from './node_modules/wikiquote-api/dist/WikiquoteApi.module.mjs'

Old style

Old style in browser
<script type="text/javascript" src="./node_modules/babel-polyfill/dist/polyfill.js"></script>
<script type="text/javascript" src="./node_modules/wikiquote-api/dist/WikiquoteApi.browser.js"></script>
Old style in Node
require('babel-polyfill')
const WikiquoteApi = require('wikiquote-api')

API

WikiquoteApi provides this functions

async function searchQuotePage(
	searchTerm: string,
	lang?: string,
	searchUrlConfig?: (lang: string) => string
): string[];

async function getQuotePage(
	pageTitle: string,
	lang?: string,
	pageUrlConfig?: (lang: string) => string,
	ambiguousPageConfig?: (lang: string) => string
): string;

async function getQuotePageDOM(
	pageTitle: string,
	lang?: string,
	pageUrlConfig?: (lang: string) => string,
	ambiguousPageConfig?: (lang: string) => string
): HTMLElement;

async function getFullQuotePage(
	searchTerm: string,
	lang?: string,
	searchUrlConfig?: (lang: string) => string,
	pageUrlConfig?: (lang: string) => string,
	ambiguousPageConfig?: (lang: string) => string
): Map<string, string>;

async function getFullQuotePageDOM(
	searchTerm: string,
	lang?: string,
	searchUrlConfig?: (lang: string) => string,
	pageUrlConfig?: (lang: string) => string,
	ambiguousPageConfig?: (lang: string) => string
): Map<string, HTMLElement>;

And this exceptions under the scope exception

  • WikiquoteApiException
  • UnsupportedLanguageException
  • NoSuchPageException
  • DisambiguationPageException

Examples

Get all pages tile related to a given subject

// returns a promise that resolve with all Spiderman related pages title
WikiquoteApi.searchQuotePage('Spiderman').then(console.log)
/*
Output:
[ 'Spider-Man',
  'Spider-Man 3',
  'Spider-Man 2',
  'Spider-Man: The Animated Series',
  'Spider-Man (2002 film)',
  'Spider-Man: Homecoming',
  'Spider-Man (2000 video game)',
  'Spider-Man: Shattered Dimensions',
  'Spider-Man 2: Enter Electro',
  'Spider-Man: Web of Shadows',
  'Spider-Man: Edge of Time',
  'Spider-Man 3 (video game)',
  'Spider-Man 2 (Video Game)' ]
*/

Get HTML content for a given page title

// returns a promise that resolve with a HTMLElement with the Spider-Man (2002 film)'s HTML content
WikiquoteApi.getQuotePage('Spider-Man (2002 film)').then(console.log)
/*
Output:
<div class="mw-parser-output"><p><i><b><a href="https://en.wikipedia.org/wiki/Spider-Man_(2002_film)" class="extiw" title="w:Spider-Man (2002 film)">Spider-Man</a></b></i> is a 2002 film based on the eponymous <a href="https://en.wikipedia.org/wiki/Marvel_Comics" class="extiw" title="w:Marvel Comics">Marvel comic</a>. It stars <a href="https://en.wikipedia.org/wiki/Tobey_Maguire" class="extiw" title="w:Tobey Maguire">Tobey Maguire</a> and <a href="https://en.wikipedia.org/wiki/Willem_Dafoe" class="extiw" title="w:Willem Dafoe">Willem Dafoe</a> and explains the story ofPeter Parker's struggle to balance between his normal life and his life as Spider Man. This movie is released theaters May 3, 2002 in United States.</p>
...
<li><i>(last words of the movie)</i> Whatever life holds in store for me, I will never forget these words: "With great power comes great responsibility." This is my gift, my curse. Who am I? I'm Spider-Man.</li>
...
*/

Get all content as HTMLElement for a given subject

// returns a promise that resolve with a Map<page's URL, HTMLElement with the content> of each pages related to Spiderman
WikiquoteApi.getFullQuotePageDOM('Iron Man').then(console.log)
/*
Output:
Map {
  'https://en.wikiquote.org/wiki/Iron%20Man%20(2008%20film)' => HTMLDivElement {},
  'https://en.wikiquote.org/wiki/Iron%20Man%3A%20Armored%20Adventures' => HTMLDivElement {},
  'https://en.wikiquote.org/wiki/Iron%20Man%20(comics)' => HTMLDivElement {},
  'https://en.wikiquote.org/wiki/Iron%20Man%203' => HTMLDivElement {},
  'https://en.wikiquote.org/wiki/Iron%20Man%202' => HTMLDivElement {},
  'https://en.wikiquote.org/wiki/Ted%20Hughes' => HTMLDivElement {},
  'https://en.wikiquote.org/wiki/Iron%20Maiden' => HTMLDivElement {} }
*/

Powered by Wikidata

Don't forget to add Powered by Wikidata to your project

Powered by Wikidata

Yet another Wikidata API

After tried severals Javascript API client for Wikidata nothing really suits to my needs or was too big :

  • too many dependencies
  • too many features not used

One more comic

Standards comic

So, i created this small API for Wikiquote

License

MIT