mw-category
v2.0.0
Published
Retrieve category items from a mediawiki-compatible source
Downloads
10
Maintainers
Readme
mw-category
Tool for displaying members of a category from a mediawiki-compatible source.
Resources
Usage
CLI
There are several ways to provide the source platform of the category.
By using a preset:
npx mw-category wikipedia:en Category:Punctuation
Or by using a custom url:
npx mw-category https://en.wikipedia.org/w/api.php Category:Punctuation
If the --csv
option is given then the resulting member strings will be wrapped in double quotes.
Programmatic
Install as dependency:
npm install mw-category
And use the module like this:
import { CategoryLoader, MwSources } from 'mw-category'
let loader = CategoryLoader.createFromTemplate(MwSources.wiktionary, 'en')
// let loader = CategoryLoader.createFromUrl('https://en.wikipedia.org/w/api.php')
try {
const members = await loader.loadMembers('Category:Spanish basic words')
members.forEach(
(page) => {
console.log('page id', page.id)
console.log('page title', page.title)
}
)
} catch (error) {
(error) => console.log("error: could not load members", error)
}
loadMembers-Method
Returns an Array of CategoryItem as a Promise:
[
{
"id": 43130,
"title": "vino"
},
{
"id": 43709,
"title": "tortilla"
}
]
Make sure to catch errors.
Global Installation (CLI)
npm install -g mw-category