mediawiki-projects-list 2.3.0 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -80,7 +80,7 @@ declare module 'mediawiki-projects-list' {
80
80
 
81
81
  export function idStringToUrl(idString: string, projectName: string): URL | null;
82
82
 
83
- export function inputToWikiProject(input: string): {
83
+ export function inputToFrontendProxy(input: string): {
84
84
  fullNamePath: string;
85
85
  fullArticlePath: string;
86
86
  fullScriptPath: string;
package/index.js CHANGED
@@ -127,12 +127,14 @@ function inputToWikiProject(input) {
127
127
  function urlToIdString(url) {
128
128
  if ( functionCache.urlToIdString.has(url.href) ) return functionCache.urlToIdString.get(url.href);
129
129
  let result = null;
130
- let wikiProject = wikiProjects.find( wikiProject => wikiProject.idString && url.hostname.endsWith( wikiProject.name ) );
131
- if ( wikiProject ) {
132
- let regex = url.href.match( new RegExp( wikiProject.regex ) )?.slice(2);
130
+ /** @type {WikiProject|FrontendProxy|undefined} */
131
+ let project = wikiProjects.find( wikiProject => wikiProject.idString && url.hostname.endsWith( wikiProject.name ) );
132
+ if ( !project ) project = frontendProxies.find( frontendProxy => frontendProxy.idString && url.hostname.endsWith( frontendProxy.name ) );
133
+ if ( project ) {
134
+ let regex = url.href.match( new RegExp( project.regex ) )?.slice(2);
133
135
  if ( regex?.length ) {
134
- if ( wikiProject.idString.direction === 'desc' ) regex.reverse();
135
- result = regex.join(wikiProject.idString.separator);
136
+ if ( project.idString.direction === 'desc' ) regex.reverse();
137
+ result = regex.join(project.idString.separator);
136
138
  }
137
139
  }
138
140
  functionCache.urlToIdString.set(url.href, result);
@@ -152,12 +154,12 @@ function idStringToUrl(idString, projectName) {
152
154
  return ( result ? new URL(result) : result );
153
155
  }
154
156
  let result = null;
155
- let idString = wikiProjects.find( wikiProject => wikiProject.idString && wikiProject.name === projectName )?.idString;
156
- if ( !idString ) idString = frontendProxies.find( frontendProxy => frontendProxy.idString && frontendProxy.name === projectName )?.idString;
157
- if ( idString ) {
158
- let regex = idString.match( new RegExp( '^' + idString.regex + '$' ) )?.[1].split(idString.separator);
159
- if ( regex && regex.length <= idString.scriptPaths.length ) {
160
- result = idString.scriptPaths[regex.length - 1].replace( /\$(\d)/g, (match, n) => regex[n - 1] );
157
+ let project = wikiProjects.find( wikiProject => wikiProject.idString && wikiProject.name === projectName )?.idString;
158
+ if ( !project ) project = frontendProxies.find( frontendProxy => frontendProxy.idString && frontendProxy.name === projectName )?.idString;
159
+ if ( project ) {
160
+ let regex = idString.match( new RegExp( '^' + project.regex + '$' ) )?.[1].split(project.separator);
161
+ if ( regex && regex.length <= project.scriptPaths.length ) {
162
+ result = project.scriptPaths[regex.length - 1].replace( /\$(\d)/g, (match, n) => regex[n - 1] );
161
163
  }
162
164
  }
163
165
  functionCache.idStringToUrl.set(cacheKey, result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mediawiki-projects-list",
3
- "version": "2.3.0",
3
+ "version": "2.3.2",
4
4
  "type": "commonjs",
5
5
  "description": "List of MediaWiki projects for use in discord-wiki-bot",
6
6
  "main": "index.js",
package/projects.json CHANGED
@@ -3,10 +3,10 @@
3
3
  "frontendProxies": [
4
4
  {
5
5
  "name": "wikiless.org",
6
- "regex": "wikiless\\.org/.*?\\?(?:.*?&)?lang=([a-z\\d-]{1,50})(?:&|/?$)",
7
- "namePath": "https://wikiless.org/?lang=$1",
8
- "articlePath": "https://wikiless.org/wiki/?lang=$1",
9
- "scriptPath": "https://$1.wikipedia.org/w/",
6
+ "regex": "(wikiless\\.org/.*?\\?(?:.*?&)?lang=([a-z\\d-]{1,50}))(?:&|/?$)",
7
+ "namePath": "https://wikiless.org/?lang=$2",
8
+ "articlePath": "https://wikiless.org/wiki/?lang=$2",
9
+ "scriptPath": "https://$2.wikipedia.org/w/",
10
10
  "idString": {
11
11
  "regex": "([a-z\\d-]{1,50})",
12
12
  "scriptPaths": [
@@ -16,10 +16,10 @@
16
16
  },
17
17
  {
18
18
  "name": "wikiwand.com",
19
- "regex": "(?:www\\.)?wikiwand\\.com/([a-z\\d-]{1,50})/?",
20
- "namePath": "https://www.wikiwand.com/$1/",
21
- "articlePath": "https://www.wikiwand.com/$1/",
22
- "scriptPath": "https://$1.wikipedia.org/w/",
19
+ "regex": "((?:www\\.)?wikiwand\\.com/([a-z\\d-]{1,50}))/?",
20
+ "namePath": "https://www.wikiwand.com/$2/",
21
+ "articlePath": "https://www.wikiwand.com/$2/",
22
+ "scriptPath": "https://$2.wikipedia.org/w/",
23
23
  "relativeFix": "^/wiki(?=/)",
24
24
  "idString": {
25
25
  "regex": "([a-z\\d-]{1,50})",
@@ -30,18 +30,18 @@
30
30
  },
31
31
  {
32
32
  "name": "breezewiki.com",
33
- "regex": "breezewiki\\.com/([a-z\\d-]{1,50})(?:/wiki/|/?$)",
34
- "namePath": "https://breezewiki.com/$1/",
35
- "articlePath": "https://breezewiki.com/$1/wiki/",
36
- "scriptPath": "https://$1.fandom.com/",
33
+ "regex": "(breezewiki\\.com/([a-z\\d-]{1,50}))(?:/wiki/|/?$)",
34
+ "namePath": "https://breezewiki.com/$2/",
35
+ "articlePath": "https://breezewiki.com/$2/wiki/",
36
+ "scriptPath": "https://$2.fandom.com/",
37
37
  "note": "Missing language support."
38
38
  },
39
39
  {
40
40
  "name": "breezewiki.pussthecat.org",
41
- "regex": "breezewiki\\.pussthecat\\.org/([a-z\\d-]{1,50})(?:/wiki/|/?$)",
42
- "namePath": "https://breezewiki.pussthecat.org/$1/",
43
- "articlePath": "https://breezewiki.pussthecat.org/$1/wiki/",
44
- "scriptPath": "https://$1.fandom.com/",
41
+ "regex": "(breezewiki\\.pussthecat\\.org/([a-z\\d-]{1,50}))(?:/wiki/|/?$)",
42
+ "namePath": "https://breezewiki.pussthecat.org/$2/",
43
+ "articlePath": "https://breezewiki.pussthecat.org/$2/wiki/",
44
+ "scriptPath": "https://$2.fandom.com/",
45
45
  "note": "Missing language support."
46
46
  }
47
47
  ],