@huijiwiki/mwclient
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

@huijiwiki/mwclient

An opinionated Node.js wrapper for MediaWiki APIs.

Currently under alpha development.

This library is built for ESM only.

Requirements

  • Node.js 16.3+

Installation

npm install @huijiwiki/mwclient

or if you use yarn

yarn add @huijiwiki/mwclient

Features

  • Everyday actions for your bots, with optional advanced options.
  • Promise-based API.
  • TypeScript is supported.

Usage

  • The names of functions (actions) are kind of self-descriptive.
  • Critical or commonly used parameters will be function arguments;
    With an optional object as the last argument, which contains other parameters that make sense for the action.
  • Consult the MediaWiki API documentation for explainations of the parameters.
  • This library is aiming to work with the latest MediaWiki LTS version, older versions may have compatibility issues.

Creating a client instance

import { Client } from '@huijiwiki/mwclient';

const client = new Client({
    host: 'en.wikipedia.org', // Required. Site host name, do not include protocol
    protocol: 'https', // Optional. Defaults to 'https'
    apiPath: '/w/api.php' // Optional. Defaults to '/w/api.php'
});

Login [Details]

await client.login('User', 'Password');

Creating/Editing a page [Details]

await client.page('Page').edit('Content', { summary: 'Some changes' });

More APIs are on the way...

Error handling

The MediaWiki API returns errors as 200 OK but this lib will parse it and throw an Error, so remember to use try/catch when calling an API.

Contribution

This lib developed and is being internally used by HuijiWiki, a wiki farm in Chinese.

The code is too simple to accept help, mostly we will expand it based on our own demands. But you're welcome to make any suggestion.

Package Sidebar

Install

npm i @huijiwiki/mwclient

Weekly Downloads

1

Version

0.1.2

License

MIT

Unpacked Size

53.8 kB

Total Files

23

Last publish

Collaborators

  • kurax