Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wikimedia-gadgets/types-mediawiki
TypeScript definitions for MediaWiki JS interface
https://github.com/wikimedia-gadgets/types-mediawiki
mediawiki
Last synced: 4 months ago
JSON representation
TypeScript definitions for MediaWiki JS interface
- Host: GitHub
- URL: https://github.com/wikimedia-gadgets/types-mediawiki
- Owner: wikimedia-gadgets
- License: gpl-3.0
- Created: 2020-12-17T14:50:34.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-06-04T17:22:36.000Z (8 months ago)
- Last Synced: 2024-09-27T05:23:39.960Z (4 months ago)
- Topics: mediawiki
- Language: JavaScript
- Homepage:
- Size: 656 KB
- Stars: 23
- Watchers: 5
- Forks: 9
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![NPM version](https://img.shields.io/npm/v/types-mediawiki.svg)](https://www.npmjs.com/package/types-mediawiki)
![Linter](https://github.com/wikimedia-gadgets/types-mediawiki/workflows/Lint/badge.svg)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)# types-mediawiki
TypeScript definitions for MediaWiki JS interface.
This package covers the functions and classes in the `mw` global object, as well some jQuery plugins used in MediaWiki core. All commonly used parts of the interface are covered.
[`@types/jquery`](https://www.npmjs.com/package/@types/jquery) and [`@types/oojs-ui`](https://www.npmjs.com/package/@types/oojs-ui) from [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped) are included as dependencies, so you don't need to install them separately.
[![Download stats](https://nodei.co/npm/types-mediawiki.png?downloads=true&downloadRank=true)](https://nodei.co/npm/types-mediawiki/)
## Usage
To use types from this package, run
```bash
npm i types-mediawiki
```Edit your project's `tsconfig.json` file so that it includes
```
"include": [
"./node_modules/types-mediawiki"
]
```You should be all set! `mw` will be available in the global scope. There is no need to put any import statements in the TypeScript source files.
**If you find any errors or have suggestions for more specific typings, please open a PR or file an issue.**
### mw.config
Types for mw.config are included:
```ts
let NS = mw.config.get("wgNamespaceNumber"); // NS gets type number
let pageName = mw.config.get("wgPageName"); // pageName gets type string
```mw.config entries added by MediaWiki extensions can also be used but their type is not known, so they need to be explicitly cast:
```ts
let namespaces = mw.config.get("pageTriageNamespaces") as number[];
```(`mw.config.get('pageTriageNamespaces')` gets the type `unknown` without a cast.)
### MediaWiki API parameters
This package also provides typings for API request parameters for the [MediaWiki Action API](https://www.mediawiki.org/wiki/Special:MyLanguage/API:Main_page). API endpoints defined in MediaWiki core and by a number of common extensions (the ones enabled on English Wikipedia) are covered. These aren't exported to the global scope, however. For usage, you need to import them. For example:
```ts
import type { ApiEditPageParams, ApiParseParams } from "types-mediawiki/api_params";
```Since it is just a type import, it doesn't generate any JavaScript. Hence, such imports can also be used in non-modular applications.