Skip to content

Commit

Permalink
rename Mwn.table class to Mwn.Table
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Sep 18, 2023
1 parent 8a99adc commit 3e936ea
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;

Expand Down
5 changes: 4 additions & 1 deletion src/static_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -149,6 +149,9 @@ export class table {
}
}

/** @deprecated Use {@link Table} instead **/
export class table extends Table {}

/**
* Encode the string like PHP's rawurlencode
*
Expand Down
22 changes: 11 additions & 11 deletions tests/static_utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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' },
Expand All @@ -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']);
Expand Down

0 comments on commit 3e936ea

Please sign in to comment.