Skip to content

Commit

Permalink
Merge pull request #535 from spencermountain/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
spencermountain committed May 11, 2023
2 parents 4a3bc7e + 6bab0b6 commit 81e8869
Show file tree
Hide file tree
Showing 18 changed files with 605 additions and 372 deletions.
4 changes: 2 additions & 2 deletions builds/wtf_wikipedia-client.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions builds/wtf_wikipedia-client.mjs

Large diffs are not rendered by default.

100 changes: 88 additions & 12 deletions builds/wtf_wikipedia.cjs
@@ -1,14 +1,10 @@
/*! wtf_wikipedia 10.1.4 MIT */
/*! wtf_wikipedia MIT */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('isomorphic-unfetch')) :
typeof define === 'function' && define.amd ? define(['isomorphic-unfetch'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.wtf = factory(global.unfetch));
})(this, (function (unfetch) { 'use strict';

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var unfetch__default = /*#__PURE__*/_interopDefaultLegacy(unfetch);

/**
* Parses out the domain and title from a url
*
Expand Down Expand Up @@ -1941,7 +1937,7 @@

const isRedirect = function (wiki) {
//too long to be a redirect?
if (!wiki || wiki.length > 500) {
if (!wiki) {
return false
}
return REDIRECT_REGEX.test(wiki)
Expand Down Expand Up @@ -2669,6 +2665,8 @@
];

//split text into sentences, using regex
//@spencermountain MIT

const abbreviations = literalAbbreviations.concat('[^]][^]]');
const abbrev_reg = new RegExp("(^| |')(" + abbreviations.join('|') + `)[.!?] ?$`, 'i');
const acronym_reg = /[ .'][A-Z].? *$/i;
Expand Down Expand Up @@ -3488,6 +3486,10 @@
if (hasKey.test(str) === true) {
let res = parseKey(str);
if (res.key) {
// don't overwrite if empty
if (h[res.key] && !res.val) {
return h
}
h[res.key] = res.val;
return h
}
Expand Down Expand Up @@ -4158,7 +4160,10 @@
'metrod': 'metro',
'fw': 'ferry',
'rws': 'stnlnk',
sclass2: 'sclass'
sclass2: 'sclass',
under: 'underline',
brackets: 'bracket',
raise: 'lower'
};

//multiple aliases
Expand Down Expand Up @@ -4456,7 +4461,7 @@
"'": `'`,
'\\': ' /',
'`': '`',
bracket: '[',
// bracket: '[',
'[': '[',
'*': '*',
asterisk: '*',
Expand All @@ -4481,6 +4486,8 @@
checked: '✔️',
'thumbs up': '👍',
'thumbs down': '👎',
'minusplus': '∓',
'plusminus': '±'
};

//grab the first, second or third pipe..
Expand All @@ -4491,6 +4498,7 @@
resize: 1, //https://en.wikipedia.org/wiki/'Resize',
lang: 1,
'rtl-lang': 1,
'line-height': 1,
l: 2,
h: 1, //https://en.wikipedia.org/wiki/'Hover_title',
sort: 1, //https://en.wikipedia.org/wiki/'Sort',
Expand Down Expand Up @@ -4557,10 +4565,34 @@
'nowiki',
'nowiki2',
'unstrip',
'UnstripNoWiki',
'unstripnowiki',
'plain text',
'make code',
'killmarkers',
'longitem',
'longlink',
'strikethrough',
'underline',
'uuline',
'not a typo',
'text',
'var serif',
'double underline',
'nee',
'ne',
'left',
'right',
'center',
'centered',
'justify',
'smalldiv',
'bold div',
'monodiv',
'italic div',
'bigdiv',
'strikethroughdiv',
'strikethrough color',
'pbpe'//pt
];
zeros.forEach((k) => {
templates$b[k] = 0;
Expand Down Expand Up @@ -5176,6 +5208,13 @@
let data = parser(tmpl, ['text']);
return (data.text || '').replace(/[^0-9]/g, '')
},
'resize': (tmpl) => {
let { n, text } = parser(tmpl, ['n', 'text']);
if (!text) {
return n || ''
}
return text || ''
},
'last word': (tmpl) => {
let data = parser(tmpl, ['text']);
let arr = (data.text || '').split(/ /g);
Expand Down Expand Up @@ -5388,6 +5427,43 @@
let { cl, type } = parser(tmpl, ['cl', 'type', 'fmt']);
return `[[${cl}-class ${type} |''${cl}''-class]] [[${type}]]`
},
'center block': (tmpl) => {
let { text } = parser(tmpl, ['text']);
return text || ''
},
'align': (tmpl) => {
let { text } = parser(tmpl, ['dir', 'text']);
return text || ''
},
'font': (tmpl) => {
let { text } = parser(tmpl, ['text']);
return text || ''
},
'float': (tmpl) => {
let { text, dir } = parser(tmpl, ['dir', 'text']);
if (!text) {
return dir
}
return text || ''
},
'lower': (tmpl) => {
let { text, n } = parser(tmpl, ['n', 'text']);
if (!text) {
return n
}
return text || ''
},
'splitspan': (tmpl) => {
let list = parser(tmpl).list || [];
return (list[0] || '') + '\n' + (list[1] || '')
},
'bracket': (tmpl) => {
let { text } = parser(tmpl, ['text']);
if (text) {
return `[${text}]`
}
return '['
},


// https://en.wikipedia.org/wiki/Template:In_title
Expand Down Expand Up @@ -10403,7 +10479,7 @@
const url = makeUrl(options);
const headers = makeHeaders(options);

return unfetch__default["default"](url, headers)
return unfetch(url, headers)
.then((res) => res.json())
.then((res) => {
let data = getResult(res, options);
Expand All @@ -10422,7 +10498,7 @@
})
};

var version = '10.1.4';
var version = '10.1.5';

/**
* use the native client-side fetch function
Expand All @@ -10433,7 +10509,7 @@
* @returns {Promise<any>} the response from fetch
*/
const request = function (url, opts) {
return unfetch__default["default"](url, opts).then(function (res) {
return unfetch(url, opts).then(function (res) {
return res.json()
}).catch((e) => {
console.error('\n\n=-=- http response error =-=-=-');
Expand Down
92 changes: 86 additions & 6 deletions builds/wtf_wikipedia.mjs
@@ -1,4 +1,4 @@
/*! wtf_wikipedia 10.1.4 MIT */
/*! wtf_wikipedia MIT */
import unfetch from 'isomorphic-unfetch';

/**
Expand Down Expand Up @@ -1933,7 +1933,7 @@ const REDIRECT_REGEX = new RegExp('^[ \n\t]*?#(' + redirects.join('|') + ') *?(\

const isRedirect = function (wiki) {
//too long to be a redirect?
if (!wiki || wiki.length > 500) {
if (!wiki) {
return false
}
return REDIRECT_REGEX.test(wiki)
Expand Down Expand Up @@ -2661,6 +2661,8 @@ var literalAbbreviations = [
];

//split text into sentences, using regex
//@spencermountain MIT

const abbreviations = literalAbbreviations.concat('[^]][^]]');
const abbrev_reg = new RegExp("(^| |')(" + abbreviations.join('|') + `)[.!?] ?$`, 'i');
const acronym_reg = /[ .'][A-Z].? *$/i;
Expand Down Expand Up @@ -3480,6 +3482,10 @@ const keyMaker = function (arr, order) {
if (hasKey.test(str) === true) {
let res = parseKey(str);
if (res.key) {
// don't overwrite if empty
if (h[res.key] && !res.val) {
return h
}
h[res.key] = res.val;
return h
}
Expand Down Expand Up @@ -4150,7 +4156,10 @@ let aliases = {
'metrod': 'metro',
'fw': 'ferry',
'rws': 'stnlnk',
sclass2: 'sclass'
sclass2: 'sclass',
under: 'underline',
brackets: 'bracket',
raise: 'lower'
};

//multiple aliases
Expand Down Expand Up @@ -4448,7 +4457,7 @@ var hardcoded = {
"'": `'`,
'\\': ' /',
'`': '`',
bracket: '[',
// bracket: '[',
'[': '[',
'*': '*',
asterisk: '*',
Expand All @@ -4473,6 +4482,8 @@ var hardcoded = {
checked: '✔️',
'thumbs up': '👍',
'thumbs down': '👎',
'minusplus': '∓',
'plusminus': '±'
};

//grab the first, second or third pipe..
Expand All @@ -4483,6 +4494,7 @@ let templates$b = {
resize: 1, //https://en.wikipedia.org/wiki/'Resize',
lang: 1,
'rtl-lang': 1,
'line-height': 1,
l: 2,
h: 1, //https://en.wikipedia.org/wiki/'Hover_title',
sort: 1, //https://en.wikipedia.org/wiki/'Sort',
Expand Down Expand Up @@ -4549,10 +4561,34 @@ let zeros = [
'nowiki',
'nowiki2',
'unstrip',
'UnstripNoWiki',
'unstripnowiki',
'plain text',
'make code',
'killmarkers',
'longitem',
'longlink',
'strikethrough',
'underline',
'uuline',
'not a typo',
'text',
'var serif',
'double underline',
'nee',
'ne',
'left',
'right',
'center',
'centered',
'justify',
'smalldiv',
'bold div',
'monodiv',
'italic div',
'bigdiv',
'strikethroughdiv',
'strikethrough color',
'pbpe'//pt
];
zeros.forEach((k) => {
templates$b[k] = 0;
Expand Down Expand Up @@ -5168,6 +5204,13 @@ var functions = {
let data = parser(tmpl, ['text']);
return (data.text || '').replace(/[^0-9]/g, '')
},
'resize': (tmpl) => {
let { n, text } = parser(tmpl, ['n', 'text']);
if (!text) {
return n || ''
}
return text || ''
},
'last word': (tmpl) => {
let data = parser(tmpl, ['text']);
let arr = (data.text || '').split(/ /g);
Expand Down Expand Up @@ -5380,6 +5423,43 @@ var functions = {
let { cl, type } = parser(tmpl, ['cl', 'type', 'fmt']);
return `[[${cl}-class ${type} |''${cl}''-class]] [[${type}]]`
},
'center block': (tmpl) => {
let { text } = parser(tmpl, ['text']);
return text || ''
},
'align': (tmpl) => {
let { text } = parser(tmpl, ['dir', 'text']);
return text || ''
},
'font': (tmpl) => {
let { text } = parser(tmpl, ['text']);
return text || ''
},
'float': (tmpl) => {
let { text, dir } = parser(tmpl, ['dir', 'text']);
if (!text) {
return dir
}
return text || ''
},
'lower': (tmpl) => {
let { text, n } = parser(tmpl, ['n', 'text']);
if (!text) {
return n
}
return text || ''
},
'splitspan': (tmpl) => {
let list = parser(tmpl).list || [];
return (list[0] || '') + '\n' + (list[1] || '')
},
'bracket': (tmpl) => {
let { text } = parser(tmpl, ['text']);
if (text) {
return `[${text}]`
}
return '['
},


// https://en.wikipedia.org/wiki/Template:In_title
Expand Down Expand Up @@ -10414,7 +10494,7 @@ const fetch = function (title, options, callback) {
})
};

var version = '10.1.4';
var version = '10.1.5';

/**
* use the native client-side fetch function
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Expand Up @@ -3,6 +3,11 @@
- **[new]** - fallbackTemplateFn handler #509
-->
#### 10.1.5 [May 2023]
- **[fix]** - support inline templates
- **[change]** - dont overwrite duplicate props in infobox #530
- **[update]** - deps

#### 10.1.4 [Apr 2023]
- **[fix]** - #528 template runtime errors
- **[fix]** - remove stray console.log (thank you @mxunknown)
Expand Down

0 comments on commit 81e8869

Please sign in to comment.