wiki-entity 0.5.12 → 0.6.1

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/lib/index.js CHANGED
@@ -19,7 +19,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
19
19
  });
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.getEntities = exports.WikipediaApi = exports.simplifyEntity = void 0;
22
+ exports.mapRedirects = exports.getEntities = exports.WikipediaApi = exports.simplifyEntity = void 0;
23
23
  const wikidata_1 = require("./wikidata");
24
24
  const api_1 = require("./wikipedia/api");
25
25
  Object.defineProperty(exports, "WikipediaApi", { enumerable: true, get: function () { return api_1.Api; } });
@@ -100,3 +100,27 @@ function getEntities(params) {
100
100
  });
101
101
  }
102
102
  exports.getEntities = getEntities;
103
+ function mapRedirects(titles, lang) {
104
+ return __awaiter(this, void 0, void 0, function* () {
105
+ const wikiApi = new api_1.Api();
106
+ return wikiApi
107
+ .redirects()
108
+ .query(lang, {
109
+ titles: titles.map((it) => it.replace(/\s+/g, "_")).join("|"),
110
+ redirects: "yes"
111
+ })
112
+ .then((apiResults) => {
113
+ const result = {};
114
+ apiResults.forEach((r) => {
115
+ var _a;
116
+ if ((_a = r.redirects) === null || _a === void 0 ? void 0 : _a.length) {
117
+ const it = r.redirects.find((it) => titles.includes(it));
118
+ if (it && it !== r.title)
119
+ result[it] = r.title;
120
+ }
121
+ });
122
+ return result;
123
+ });
124
+ });
125
+ }
126
+ exports.mapRedirects = mapRedirects;
@@ -62,7 +62,7 @@ function exploreEntitiesProperties(entities, lang) {
62
62
  }
63
63
  });
64
64
  });
65
- return null;
65
+ return entities;
66
66
  });
67
67
  }
68
68
  function exploreEntityClaims(claims, params) {
@@ -33,19 +33,19 @@ class Api {
33
33
  if (data && data.query && data.query.pages) {
34
34
  return Object.keys(data.query.pages)
35
35
  .map((id) => data.query.pages[id])
36
- .map((data) => {
36
+ .map((page) => {
37
37
  const item = {
38
- pageid: data.pageid,
39
- title: data.title
38
+ pageid: page.pageid,
39
+ title: page.title
40
40
  };
41
- if (data["categories"]) {
42
- item.categories = data["categories"].map((it) => it.title);
41
+ if (page["categories"]) {
42
+ item.categories = page["categories"].map((it) => it.title);
43
43
  }
44
- if (data["redirects"]) {
45
- item.redirects = data["redirects"].map((it) => it.title);
44
+ if (page["redirects"]) {
45
+ item.redirects = page["redirects"].map((it) => it.title);
46
46
  }
47
- if (data["extract"]) {
48
- item.extract = data["extract"];
47
+ if (page["extract"]) {
48
+ item.extract = page["extract"];
49
49
  }
50
50
  return item;
51
51
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-entity",
3
- "version": "0.5.12",
3
+ "version": "0.6.1",
4
4
  "description": "Wiki entity fetcher",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export { WikipediaApi };
5
5
  export * from "./simpleEntity";
6
6
  export * from "./types";
7
7
  export declare function getEntities(params: WikiEntitiesParams): Promise<WikiEntity[]>;
8
+ export declare function mapRedirects(titles: string[], lang: string): Promise<Record<string, string>>;