Skip to content

Commit 1c2ac63

Browse files
Merge pull request #586 from spencermountain/dev
10.4.0
2 parents 0e1146d + 015abc2 commit 1c2ac63

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2052
-1672
lines changed

.eslintignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 87 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ Some wikis, (like wikia) have intentionally disabled this.
719719
wikitext is (amazingly) used across all languages, wikis, and even in right-to-left languages.
720720
This parser actually does an okay job at it too.
721721

722-
Wikipedia I18n langauge information for _Redirects, Infoboxes, Categories, and Images_ are included in the library, with pretty-decent coverage.
722+
Wikipedia I18n language information for _Redirects, Infoboxes, Categories, and Images_ are included in the library, with pretty-decent coverage.
723723

724724
To improve coverage of i18n templates, use [wtf-plugin-i18n](./plugins/i18n)
725725

@@ -730,12 +730,12 @@ Please make a PR if you see something missing for your language.
730730

731731
## Builds:
732732

733-
this library ships seperate client-side and server-side builds, to preserve filesize.
733+
this library ships separate client-side and server-side builds, to preserve filesize.
734734

735735
- _[./wtf_wikipedia-client.mjs](./builds/wtf_wikipedia-client.mjs)_ - as es-module (or Deno)
736736
- _[./wtf_wikipedia-client.min.js](./builds/wtf_wikipedia-client.min.js)_ - for production
737737

738-
- _[./wtf_wikipedia.cjs](./builds/wtf_wikipedia.js)_ - node commonjs build
738+
- _[./wtf_wikipedia.cjs](./builds/wtf_wikipedia.cjs)_ - node commonjs build
739739
- _[./wtf_wikipedia.mjs](./builds/wtf_wikipedia.mjs)_ - node/deno/typescript esm build
740740

741741
the browser version uses `fetch()` and the server version uses `require('https')`.

builds/wtf_wikipedia-client.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builds/wtf_wikipedia-client.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

builds/wtf_wikipedia.cjs

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @returns {{domain: string, title: string}} The domain and title of a url
1414
*/
1515
const parseUrl = function (url) {
16-
let parsed = new URL(url); // eslint-disable-line
16+
let parsed = new URL(url); //eslint-disable-line
1717
let title = parsed.pathname.replace(/^\/(wiki\/)?/, '');
1818
title = decodeURIComponent(title);
1919
return {
@@ -1208,20 +1208,17 @@
12081208
let name = t.template || '';
12091209
// try i18n templates like 'stubo'
12101210
if (allStubs.has(name)) {
1211-
// console.log(name)
12121211
return true
12131212
}
12141213
// english forms
12151214
if (name === 'stub' || name.endsWith('-stub')) {
1216-
// console.log(name)
12171215
return true
12181216
}
12191217
// look for i18n in last-word, like {{foo-stubo}}
12201218
let words = name.split(/[- ]/);
12211219
if (words.length > 1) {
12221220
let word = words[words.length - 1];
12231221
if (allStubs.has(word)) {
1224-
// console.log(name)
12251222
return true
12261223
}
12271224
}
@@ -2157,7 +2154,6 @@
21572154
}
21582155
//kill off just these just-anchor links [[#history]]
21592156
// if (link.match(/^#/i)) {
2160-
// console.log(s)
21612157
// return s
21622158
// }
21632159
//remove anchors from end [[toronto#history]]
@@ -8399,6 +8395,33 @@
83998395
return str
84008396
};
84018397

8398+
const toTextBritish = function (date) {
8399+
//eg '1995'
8400+
let str = String(date.year || '');
8401+
if (date.month !== undefined && months$1.hasOwnProperty(date.month) === true) {
8402+
if (date.date === undefined) {
8403+
//January 1995
8404+
str = `${months$1[date.month]} ${date.year}`;
8405+
} else {
8406+
//5 January 1995
8407+
str = `${date.date} ${months$1[date.month]} ${date.year}`;
8408+
//add times, if available
8409+
if (date.hour !== undefined && date.minute !== undefined) {
8410+
let time = `${pad(date.hour)}:${pad(date.minute)}`;
8411+
if (date.second !== undefined) {
8412+
time = time + ':' + pad(date.second);
8413+
}
8414+
str = time + ', ' + str;
8415+
//add timezone, if there, at the end in brackets
8416+
}
8417+
if (date.tz) {
8418+
str += ` (${date.tz})`;
8419+
}
8420+
}
8421+
}
8422+
return str
8423+
};
8424+
84028425
// console.log(toText(ymd([2018, 3, 28])));
84038426

84048427
//wrap it up as a template
@@ -8785,6 +8808,36 @@
87858808
// 'birth date and age2': date,
87868809
// 'age in years, months, weeks and days': true,
87878810
// 'age as of date': true,
8811+
// https://en.wikipedia.org/wiki/Template:As_of
8812+
'as of': (tmpl) => {
8813+
let obj = parser(tmpl, ['year', 'month', 'day']);
8814+
if (obj.alt) {
8815+
return obj.alt
8816+
}
8817+
let out = 'As of ';
8818+
if (obj.since) {
8819+
out = 'Since ';
8820+
}
8821+
if (obj.lc) {
8822+
out = out.toLowerCase();
8823+
}
8824+
if (obj.bare) {
8825+
out = '';
8826+
}
8827+
if (obj.pre) {
8828+
out += obj.pre + ' ';
8829+
}
8830+
let format = toTextBritish;
8831+
if (obj.df == "US") {
8832+
format = toText;
8833+
}
8834+
let dateObj = ymd([obj.year, obj.month, obj.day]);
8835+
out += format(dateObj);
8836+
if (obj.post) {
8837+
out += obj.post;
8838+
}
8839+
return out
8840+
}
87888841
};
87898842

87908843
/**
@@ -9246,6 +9299,8 @@
92469299
sports,
92479300
);
92489301

9302+
/* eslint-disable no-console */
9303+
92499304
let templates = Object.assign({}, textTmpl, dataTmpl, bothTmpl);
92509305

92519306
Object.keys(aliases).forEach((k) => {
@@ -9255,8 +9310,6 @@
92559310
templates[k] = templates[aliases[k]];
92569311
});
92579312

9258-
// console.log(Object.keys(templates).length)
9259-
92609313
const nums = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
92619314

92629315
//this gets all the {{template}} objects and decides how to parse them
@@ -10518,7 +10571,7 @@
1051810571
};
1051910572
});
1052010573

10521-
const heading_reg = /^(={1,6})(.{1,200}?)={1,6}$/;
10574+
const heading_reg = /^(={1,6})(.{1,200}?)={1,6}$/; //eslint-disable-line
1052210575
const hasTemplate = /\{\{.+?\}\}/;
1052310576

1052410577
const doInlineTemplates = function (wiki, doc) {
@@ -10666,6 +10719,8 @@
1066610719
return [categories, newWiki]
1066710720
};
1066810721

10722+
/* eslint-disable no-console */
10723+
1066910724
const defaults$1 = {
1067010725
tables: true,
1067110726
lists: true,
@@ -11251,6 +11306,7 @@
1125111306
* @returns {null| Document | Document[]} null if there are no results or Document if there is one responses and Document array if there are multiple responses
1125211307
*/
1125311308
const parseDoc = function (res, title) {
11309+
res = res || [];
1125411310
// filter out undefined
1125511311
res = res.filter((o) => o);
1125611312

@@ -11303,6 +11359,7 @@
1130311359
}
1130411360
};
1130511361

11362+
/* eslint-disable no-console */
1130611363
const isUrl = /^https?:\/\//;
1130711364

1130811365
/**
@@ -11384,7 +11441,9 @@
1138411441
})
1138511442
};
1138611443

11387-
var version = '10.3.2';
11444+
var version = '10.4.0';
11445+
11446+
/* eslint-disable no-console */
1138811447

1138911448
/**
1139011449
* use the native client-side fetch function

0 commit comments

Comments
 (0)