mw-category

2.0.0 • Public • Published

mw-category

Tool for displaying members of a category from a mediawiki-compatible source.

Resources

API Reference

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

License

MIT

Package Sidebar

Install

npm i mw-category

Weekly Downloads

5

Version

2.0.0

License

MIT

Unpacked Size

15.3 kB

Total Files

11

Last publish

Collaborators

  • eisverticker