Code Monkey home page Code Monkey logo

mw-category's Introduction

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

mw-category's People

Contributors

dependabot[bot] avatar eisverticker avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

mw-category's Issues

Improve API

Proposals

Simplification

  • buildSourceUrl() - Methode can be replaced by an second constructor on CategoryLoader with two arguments
  • buildSourceUrl should be marked deprecated in 1.1 and discontinued in 2.0

Better error handling

In some cases error will not be catched. For instance if a remote page is being loaded but it is no category, then the response body will not have the right format and we don't handle that at the moment.

consider magic terms

Consider magic terms like

  • 'Appendix:'
  • 'Category:'

in category title and maybe handle them separetly

improve linting

Things to consider:

  • switch to standard linter? --> easier but no options like jsdoc
  • align eslint4 rules to standard rules plus custom rules? (jsdoc)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.