Need private packages and team management tools?Check out npm Teams »

mw-category

1.2.1 • Public • Published

mw-category

This library enables users to access members of a category from a mediawiki-compatible source.

Resources

Installation

Default

npm install mw-category

Global (CLI)

npm install -g mw-category

Usage

CLI example

mw-category https://en.wikipedia.org/w/api.php Category:Punctuation

If the --csv option is given then the resulting member strings will be quoted.

Javascript example

const MwCategory = require('mw-category')
 
const CategoryLoader = MwCategory.CategoryLoader
const MwSources = MwCategory.MwSources
 
let loader = CategoryLoader.createFromTemplate(MwSources.Wiktionary, 'en')
//let loader = CategoryLoader.createFromUrl('https://en.wikipedia.org/w/api.php')
 
loader.loadMembers('Category:Spanish basic words')
  .then(
    (members) => {
      members.forEach(
        (page) => {
          console.log('page id', page.id)
          console.log('page title', page.title)
        }
      )
    }
  )
  .catch(
    (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"
  }
]

If an error occurs then you can catch it.

License

MIT

Install

npm i mw-category

DownloadsWeekly Downloads

2

Version

1.2.1

License

MIT

Last publish

Collaborators

  • avatar