A JavaScript library for querying People
using the Wikidata API.
npm install wikidata-person
yarn add wikidata-person
var wdp = require('wikidata-person');
wdp.person("Mohandas Karamchand Gandhi", function(person) {
console.log(person);
});
The above code will log:
{
name:"Mahatma Gandhi",
description:"pre-eminent leader of Indian nationalism during British-ruled India",
birthdate: 1869,
deathdate: 1948,
imageUrl:"https://upload.wikimedia.org/wikipedia/commons/d/d1/Portrait_Gandhi.jpg"
}
require('wikidata-person').category(<category>)
takes in the name of a Wikipedia Category and returns a list of all people who belong to the <category>
or its subcategories.
var wdp = require('wikidata-person');
wdp.category("2nd-century_Roman_usurpers", function(people) {
console.log(person);
});
The above code will log:
[
{
name: 'Avidius Cassius',
description: 'Roman consul',
birthdate: '+0130',
deathdate: '+0175',
imageUrl: ''
},
{
name: 'Clodius Albinus',
description: 'Roman usurper proclaimed emperor by the legions in Britain and Hispania',
birthdate: '+0150',
deathdate: '+0197',
imageUrl: 'https://upload.wikimedia.org/wikipedia/commons/b/bc/Clodius01_pushkin.jpg'
}
]
If the number of category members exceeds the Wikidata API's cmlimit
, the returned list of people will not be complete.
Querying a huge category containing a large amount of people (for example, Category:People
), the query may not complete.
npm test
In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.