From 3e936eac4ce3e8be35012c81d930e6da09ce9f98 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Mon, 18 Sep 2023 16:26:25 +0530 Subject: [PATCH] rename Mwn.table class to Mwn.Table --- CHANGELOG.md | 1 + src/bot.ts | 7 +++++-- src/static_utils.ts | 5 ++++- tests/static_utils.test.js | 22 +++++++++++----------- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d4dc1b..160cbae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Only breaking changes, deprecations and the like are documented in this change l - bot.user -> bot.User - bot.wikitext -> bot.Wikitext - bot.date -> bot.Date + - mwn.table -> Mwn.Table - Class for querying Wikimedia EventStreams have been removed. Consider using the dedicated library [wikimedia-streams](https://www.npmjs.com/package/wikimedia-streams) instead. - set* methods on MwnDate objects (eg. `setUTCDate`) used to be chainable as they returned `this`. Because MwnDate extends the native Date, the change in return values was not possible to represent in TypeScript types ([Liskov substitution principle](https://en.wikipedia.org/wiki/Liskov_substitution_principle)). This undocumented feature has now been removed for the sake of accurate types. - `printYaml` logging config option used by is no longer supported in Mwn.setLoggingConfig() method. diff --git a/src/bot.ts b/src/bot.ts index 9388fe9..738b09a 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -54,7 +54,7 @@ import MwnFileFactory, { MwnFile } from './file'; import { RawRequestParams, Request, Response } from './core'; import { log, updateLoggingConfig } from './log'; import { MwnError, rejectWithError, rejectWithErrorCode } from './error'; -import { link, table, template, util } from './static_utils'; +import { link, Table, template, util } from './static_utils'; import { arrayChunk, ispromise, makeTitle, makeTitles, merge, mergeDeep1, sleep } from './utils'; import type { @@ -283,7 +283,10 @@ export class Mwn { static link = link; static template = template; - static table = table; + static Table = Table; + + /** @deprecated Use {@link Table} instead **/ + static table = Table; static util = util; diff --git a/src/static_utils.ts b/src/static_utils.ts index 4aa03b2..0b200e2 100644 --- a/src/static_utils.ts +++ b/src/static_utils.ts @@ -49,7 +49,7 @@ export function template(title: string | MwnTitle, parameters: { [parameter: str ); } -export class table { +export class Table { text: string; multiline: boolean; numRows = 0; @@ -149,6 +149,9 @@ export class table { } } +/** @deprecated Use {@link Table} instead **/ +export class table extends Table {} + /** * Encode the string like PHP's rawurlencode * diff --git a/tests/static_utils.test.js b/tests/static_utils.test.js index c4b14ff..9a050c5 100644 --- a/tests/static_utils.test.js +++ b/tests/static_utils.test.js @@ -59,7 +59,7 @@ describe('static utils', function () { | Example || Example || Example |}`; - var table = new Mwn.table({ multiline: false }); + var table = new Mwn.Table({ multiline: false }); table.addHeaders(['Header text', 'Header text', 'Header text']); table.addRow(['Example', 'Example', 'Example']); table.addRow(['Example', 'Example', 'Example']); @@ -93,19 +93,19 @@ describe('static utils', function () { }, ]); - table = new Mwn.table({ sortable: false, multiline: false }); + table = new Mwn.Table({ sortable: false, multiline: false }); table.addHeaders(['Header1 text', 'Header2 text', 'Header3 text']); table.addRow(['Example11', 'Example12', 'Example13'], { style: 'background: green;' }); table.addRow(['Example21', 'Example22', 'Example23']); expect(table.getText()).to.equal(expected2); - expect(new Mwn.table().getText()).to.equal(`{| class="wikitable sortable"\n|}`); - expect(new Mwn.table({ plain: true }).getText()).to.equal(`{| class="sortable"\n|}`); - expect(new Mwn.table({ sortable: false, plain: true, style: 'text-align: center' }).getText()).to.equal( + expect(new Mwn.Table().getText()).to.equal(`{| class="wikitable sortable"\n|}`); + expect(new Mwn.Table({ plain: true }).getText()).to.equal(`{| class="sortable"\n|}`); + expect(new Mwn.Table({ sortable: false, plain: true, style: 'text-align: center' }).getText()).to.equal( `{| style="text-align: center"\n|}` ); - table = new Mwn.table(); + table = new Mwn.Table(); table.addHeaders([ { label: 'Header1 text', class: 'foobar' }, { style: 'width: 5em;', label: 'Header2 text' }, @@ -115,20 +115,20 @@ describe('static utils', function () { table.addRow([{ label: 'Example21', class: 'sampleclass' }, 'Example22', 'Example23']); expect(table.getText()).toMatchSnapshot(); - expect(new Mwn.table().getText()).to.equal(`{| class="wikitable sortable"\n|}`); - expect(new Mwn.table({ plain: true }).getText()).to.equal(`{| class="sortable"\n|}`); - expect(new Mwn.table({ sortable: false, plain: true, style: 'text-align: center' }).getText()).to.equal( + expect(new Mwn.Table().getText()).to.equal(`{| class="wikitable sortable"\n|}`); + expect(new Mwn.Table({ plain: true }).getText()).to.equal(`{| class="sortable"\n|}`); + expect(new Mwn.Table({ sortable: false, plain: true, style: 'text-align: center' }).getText()).to.equal( `{| style="text-align: center"\n|}` ); - table = new Mwn.table({ multiline: false, classes: ['plainlinks'] }); + table = new Mwn.Table({ multiline: false, classes: ['plainlinks'] }); table.addHeaders(['Header text', 'Header text', 'Header text']); table.addRow(['Example', 'Example', 'Example']); table.addRow(['Example', 'Example', 'Example']); expect(table.getText()).toMatchSnapshot(); // With multiline - table = new Mwn.table({ classes: ['plainlinks'] }); + table = new Mwn.Table({ classes: ['plainlinks'] }); table.addHeaders(['Header text', 'Header text', 'Header text']); table.addRow(['Example', { label: 'Example21', class: 'sampleclass' }, 'Example']); table.addRow(['Example', 'Example', 'Example']);