-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from cAttte/main
- Loading branch information
Showing
4 changed files
with
143 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
declare global { | ||
namespace mw { | ||
/** | ||
* Create an object that can be read from or written to via methods that allow interaction both | ||
* with single and multiple properties at once. | ||
* | ||
* **NOTE**: This is a private utility class for internal use by the framework. | ||
* Don't rely on its existence. | ||
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Map | ||
*/ | ||
class Map<V extends Record<string, any> = any> { | ||
private values: V; | ||
|
||
/** | ||
* Get the value of one or more keys. | ||
* | ||
* If called with no arguments, all values are returned. | ||
* @param selection Key or array of keys to retrieve values for. | ||
* @param fallback Value for keys that don't exist. | ||
* @returns If selection was a string, returns the value. If selection was an array, returns | ||
* an object of key/values. If no selection is passed, a new object with all key/values is returned. | ||
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Map-method-get | ||
*/ | ||
get(): V; | ||
get<S extends Array<keyof V>>( | ||
selection: S, | ||
fallback?: any | ||
): Pick<V, S extends Array<infer SS> ? SS : never>; | ||
get<S extends keyof V>(selection: S, fallback?: V[S]): V[S]; | ||
|
||
/** | ||
* Set the value of one or more keys. | ||
* | ||
* @param selection Key to set value for, or object mapping keys to values | ||
* @param value Value to set (optional, only in use when key is a string) | ||
* @returns True on success, false on failure | ||
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Map-method-set | ||
*/ | ||
set<S extends keyof V>(selection: S, value: V[S]): boolean; | ||
set(selection: Partial<V>): boolean; | ||
|
||
/** | ||
* Check if a given key exists in the map. | ||
* @param selection Key to check | ||
* @returns True if the key exists | ||
* @see https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Map-method-exists | ||
*/ | ||
exists(selection: keyof V): boolean; | ||
} | ||
} | ||
} | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Go to <https://www.mediawiki.org/wiki/Manual:Interface/JavaScript#mw.config> | ||
// paste this into the browser console, and copy the log output | ||
|
||
function processType(type) { | ||
type = type.toLowerCase(); | ||
type = type.replace(/or (unset|not defined)/, ""); | ||
type = type.replace("integer", "number"); | ||
type = type.replace(/ or /g, " | "); | ||
if (type.startsWith("array of")) { | ||
const element = type.replace(/array of (.*)s(\s|$)/, "$1"); | ||
type = `${element}[]`; | ||
} | ||
if (type === "array") type = "string[]"; | ||
if (type === "object") type = "Record<string, string>"; | ||
|
||
return type.trim(); | ||
} | ||
|
||
const types = {}; | ||
const tables = document.querySelectorAll(".wikitable"); | ||
for (const table of tables) { | ||
const rows = table.querySelectorAll("tr:not([colspan])"); | ||
for (const row of rows) { | ||
const cells = row.querySelectorAll("td"); | ||
if (!cells.length) continue; | ||
const name = cells[0].innerText.trim(); | ||
const type = processType(cells[1].innerText); | ||
types[name] = type; | ||
} | ||
} | ||
|
||
const entries = Object.entries(types).map(([k, v]) => `${" ".repeat(12)}${k}: ${v};`); | ||
console.log(`{\n${entries.join("\n")}${" ".repeat(8)}\n}`); |