Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wikiquote-api

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wikiquote-api

Small API for Wikiquote

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

// 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

Keywords

FAQs

Package last updated on 11 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc