Wikiquote API
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
WikiquoteApi.searchQuotePage('Spiderman').then(console.log)
Get HTML content for a given page title
WikiquoteApi.getQuotePage('Spider-Man (2002 film)').then(console.log)
Get all content as HTMLElement
for a given subject
WikiquoteApi.getFullQuotePageDOM('Iron Man').then(console.log)
Powered by Wikidata
Don't forget to add Powered by Wikidata
to your project
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
So, i created this small API for Wikiquote
License
MIT