wiki-entity 0.5.3 → 0.5.7

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/README.md CHANGED
@@ -59,6 +59,7 @@ type WikiEntity = {
59
59
  types?: string[];
60
60
  redirects?: string[];
61
61
  categories?: string[];
62
+ redirectsToId?: string;
62
63
  }
63
64
 
64
65
  type WikidataProperty = {
@@ -113,6 +114,7 @@ export type SimpleEntity = {
113
114
  countryCodes?: string[]
114
115
  data?: SimpleEntityData
115
116
  categories?: string[]
117
+ redirectsToId?: string;
116
118
  }
117
119
 
118
120
  ```
package/lib/index.js CHANGED
@@ -1,42 +1,50 @@
1
1
  "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
5
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.getEntities = exports.WikipediaApi = exports.simplifyEntity = void 0;
6
23
  const wikidata_1 = require("./wikidata");
7
24
  const api_1 = require("./wikipedia/api");
8
- exports.WikipediaApi = api_1.Api;
25
+ Object.defineProperty(exports, "WikipediaApi", { enumerable: true, get: function () { return api_1.Api; } });
9
26
  const utils_1 = require("./utils");
10
27
  const get_entity_types_1 = require("./wikidata/get_entity_types");
11
28
  var simplify_entity_1 = require("./wikidata/simplify_entity");
12
- exports.simplifyEntity = simplify_entity_1.simplifyEntity;
13
- __export(require("./simpleEntity"));
14
- __export(require("./types"));
29
+ Object.defineProperty(exports, "simplifyEntity", { enumerable: true, get: function () { return simplify_entity_1.simplifyEntity; } });
30
+ __exportStar(require("./simpleEntity"), exports);
31
+ __exportStar(require("./types"), exports);
15
32
  function getEntities(params) {
16
- const lang = params.language || "en";
17
- return wikidata_1.getEntities(params)
18
- .then(function (wikiDataEntities) {
19
- const entities = wikiDataEntities;
20
- const ids = Object.keys(entities).filter((id) => utils_1.isValidWikiId(id));
21
- if (ids.length === 0) {
22
- return entities;
23
- }
24
- const tasks = [];
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const lang = params.language || "en";
35
+ const entities = yield (0, wikidata_1.getEntities)(params);
36
+ const ids = Object.keys(entities).filter((id) => (0, utils_1.isValidWikiId)(id));
37
+ if (ids.length === 0)
38
+ return [];
25
39
  const wikiApi = new api_1.Api({}, params.httpTimeout);
26
- let callWikiApi = false;
27
- if (params.extract) {
28
- callWikiApi = true;
40
+ if (params.extract)
29
41
  wikiApi.extract(params.extract);
30
- }
31
- if (params.redirects) {
32
- callWikiApi = true;
42
+ if (params.redirects)
33
43
  wikiApi.redirects();
34
- }
35
- if (params.categories) {
36
- callWikiApi = true;
44
+ if (params.categories)
37
45
  wikiApi.categories();
38
- }
39
- if (callWikiApi && entities[ids[0]] && entities[ids[0]].sitelinks) {
46
+ const tasks = [];
47
+ if (entities[ids[0]] && entities[ids[0]].sitelinks) {
40
48
  const titleIds = ids.reduce((prev, id) => {
41
49
  if (entities[id] &&
42
50
  entities[id].sitelinks &&
@@ -57,15 +65,13 @@ function getEntities(params) {
57
65
  })
58
66
  .then((apiResults) => apiResults.forEach((result) => {
59
67
  const entity = entities[titleIds[result.title]];
60
- if (params.extract) {
68
+ entity.pageid = result.pageid;
69
+ if (params.extract)
61
70
  entity.extract = result.extract;
62
- }
63
- if (params.redirects) {
71
+ if (params.redirects)
64
72
  entity.redirects = result.redirects;
65
- }
66
- if (params.categories) {
73
+ if (params.categories)
67
74
  entity.categories = result.categories;
68
- }
69
75
  })));
70
76
  }
71
77
  if (params.types === true || Array.isArray(params.types)) {
@@ -76,18 +82,16 @@ function getEntities(params) {
76
82
  if (entities[id] && entities[id].sitelinks) {
77
83
  const enName = entities[id].sitelinks["en"];
78
84
  if (enName) {
79
- tasks.push(get_entity_types_1.getEntityTypesByName(enName, prefixes).then((types) => {
85
+ tasks.push((0, get_entity_types_1.getEntityTypesByName)(enName, prefixes).then((types) => {
80
86
  entities[id].types = types;
81
87
  }));
82
88
  }
83
89
  }
84
90
  });
85
91
  }
86
- return Promise.all(tasks).then(() => entities);
87
- })
88
- .then(function (resultEntities) {
89
- return Object.keys(resultEntities)
90
- .map((id) => resultEntities[id])
92
+ yield Promise.all(tasks);
93
+ return Object.keys(entities)
94
+ .map((id) => entities[id])
91
95
  .filter((it) => !!it);
92
96
  });
93
97
  }
package/lib/request.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
4
5
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
6
  function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
@@ -11,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
12
  const axios_1 = require("axios");
12
13
  function default_1(url, options) {
13
14
  return __awaiter(this, void 0, void 0, function* () {
14
- const response = yield axios_1.default(url, Object.assign({ method: "GET", responseType: "json", headers: { "User-Agent": "entity-finder" } }, options, { timeout: options.timeout || 10 * 1000 }));
15
+ const response = yield (0, axios_1.default)(url, Object.assign(Object.assign({ method: "GET", responseType: "json", headers: { "User-Agent": "entity-finder" } }, options), { timeout: options.timeout || 10 * 1000 }));
15
16
  return response.data;
16
17
  });
17
18
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToSimpleEntity = void 0;
3
4
  const getEntityType_1 = require("./getEntityType");
4
5
  const getEntityInstanceType_1 = require("./getEntityInstanceType");
5
6
  const getEntityTypeByExtract_1 = require("./getEntityTypeByExtract");
@@ -15,14 +16,16 @@ function convertToSimpleEntity(wikiEntity, lang, options) {
15
16
  entity.description = wikiEntity.description;
16
17
  entity.wikiPageId = wikiEntity.pageid;
17
18
  entity.about = wikiEntity.extract;
19
+ if (wikiEntity.redirectsToId)
20
+ entity.redirectsToId = wikiEntity.redirectsToId;
18
21
  if (wikiEntity.types) {
19
- entity.types = utils_1.uniq(wikiEntity.types.filter((item) => !/:(Thing|Agent)$/.test(item)));
22
+ entity.types = (0, utils_1.uniq)(wikiEntity.types.filter((item) => !/:(Thing|Agent)$/.test(item)));
20
23
  }
21
- entity.type = getEntityType_1.getEntityType(wikiEntity);
24
+ entity.type = (0, getEntityType_1.getEntityType)(wikiEntity);
22
25
  if (!entity.type) {
23
- entity.type = getEntityInstanceType_1.getEntityType(wikiEntity);
26
+ entity.type = (0, getEntityInstanceType_1.getEntityType)(wikiEntity);
24
27
  if (!entity.type && entity.about && !entity.types) {
25
- entity.type = getEntityTypeByExtract_1.getEntityTypeByExtract(entity.about, lang);
28
+ entity.type = (0, getEntityTypeByExtract_1.getEntityTypeByExtract)(entity.about, lang);
26
29
  }
27
30
  if (!entity.type && options.defaultType) {
28
31
  entity.type = options.defaultType;
@@ -35,14 +38,14 @@ function convertToSimpleEntity(wikiEntity, lang, options) {
35
38
  if (wikiEntity.claims) {
36
39
  const ids = Object.keys(wikiEntity.claims);
37
40
  if (ids.length) {
38
- entity.data = getEntityData_1.getEntityData(wikiEntity);
41
+ entity.data = (0, getEntityData_1.getEntityData)(wikiEntity);
39
42
  }
40
- entity.countryCodes = getEntityCountry_1.getEntityCountryCode(wikiEntity);
43
+ entity.countryCodes = (0, getEntityCountry_1.getEntityCountryCode)(wikiEntity);
41
44
  }
42
45
  return entity;
43
46
  }
44
47
  exports.convertToSimpleEntity = convertToSimpleEntity;
45
48
  function createCategories(entity) {
46
49
  let categories = entity.categories || [];
47
- return utils_1.uniq(categories);
50
+ return (0, utils_1.uniq)(categories);
48
51
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntityCountryCode = void 0;
3
4
  const countries = require('../../data/countries.json');
4
5
  function getEntityCountryCode(wikiEntity) {
5
6
  if (!wikiEntity) {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntityData = void 0;
3
4
  function getEntityData(wikiEntity) {
4
5
  if (!wikiEntity.claims) {
5
6
  return null;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntityType = void 0;
3
4
  const simpleEntity_1 = require("./simpleEntity");
4
5
  function getEntityType(wikiEntity) {
5
6
  if (!wikiEntity.claims) {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntityType = void 0;
3
4
  const simpleEntity_1 = require("./simpleEntity");
4
5
  const TYPES_MAP = {
5
6
  'dbo:FictionalCharacter': simpleEntity_1.SimpleEntityType.WORK,
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntityTypeByExtract = void 0;
3
4
  const simpleEntity_1 = require("./simpleEntity");
4
5
  const MAP = {
5
6
  ro: [
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToSimpleEntity = exports.SimpleEntityType = void 0;
3
4
  var simpleEntity_1 = require("./simpleEntity");
4
- exports.SimpleEntityType = simpleEntity_1.SimpleEntityType;
5
+ Object.defineProperty(exports, "SimpleEntityType", { enumerable: true, get: function () { return simpleEntity_1.SimpleEntityType; } });
5
6
  var convertToSimpleEntity_1 = require("./convertToSimpleEntity");
6
- exports.convertToSimpleEntity = convertToSimpleEntity_1.convertToSimpleEntity;
7
+ Object.defineProperty(exports, "convertToSimpleEntity", { enumerable: true, get: function () { return convertToSimpleEntity_1.convertToSimpleEntity; } });
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SIMPLE_ENTITY_TYPES = exports.SimpleEntityType = void 0;
3
4
  var SimpleEntityType;
4
5
  (function (SimpleEntityType) {
5
6
  SimpleEntityType["EVENT"] = "E";
@@ -15,5 +16,5 @@ exports.SIMPLE_ENTITY_TYPES = [
15
16
  SimpleEntityType.PLACE,
16
17
  SimpleEntityType.ORG,
17
18
  SimpleEntityType.PRODUCT,
18
- SimpleEntityType.WORK,
19
+ SimpleEntityType.WORK
19
20
  ];
package/lib/types.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WikidataPropsParam = void 0;
3
4
  var WikidataPropsParam;
4
5
  (function (WikidataPropsParam) {
5
6
  WikidataPropsParam["info"] = "info";
package/lib/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidWikiId = exports.uniq = exports.eachSeries = void 0;
3
4
  function eachSeries(arr, iteratorFn) {
4
5
  return arr.reduce((p, item) => p.then(() => iteratorFn(item)), Promise.resolve());
5
6
  }
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
4
5
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
6
  function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.validateParams = exports.getManyEntities = exports.getEntities = void 0;
11
13
  const request_1 = require("../request");
12
14
  const types_1 = require("../types");
13
15
  const utils_1 = require("../utils");
@@ -38,7 +40,7 @@ function getEntities(params) {
38
40
  else {
39
41
  delete qs.sites;
40
42
  }
41
- const data = yield request_1.default(API_URL, {
43
+ const data = yield (0, request_1.default)(API_URL, {
42
44
  params: qs,
43
45
  timeout: params.httpTimeout
44
46
  });
@@ -46,7 +48,10 @@ function getEntities(params) {
46
48
  throw getError(data);
47
49
  const entities = (data && data.entities) || {};
48
50
  for (let id of Object.keys(entities)) {
49
- if (!utils_1.isValidWikiId(id) || ~Object.keys(entities[id]).indexOf("missing")) {
51
+ const entity = entities[id];
52
+ if (entity.redirects && entity.redirects.to)
53
+ entity.redirectsToId = entity.redirects.to;
54
+ if (!(0, utils_1.isValidWikiId)(id) || ~Object.keys(entities[id]).indexOf("missing")) {
50
55
  delete entities[id];
51
56
  }
52
57
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntityTypesByName = void 0;
3
4
  const request_1 = require("../request");
4
5
  const PREFIXES_MAP = {
5
6
  "http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#": "dul",
@@ -33,15 +34,17 @@ function parseTypes(types) {
33
34
  return types.map((item) => item.type.value);
34
35
  }
35
36
  function dbpediaTypes(name) {
36
- const query = `
37
- SELECT ?type
38
- WHERE {
39
- <http://dbpedia.org/resource/${encodeURIComponent(name.replace(/\s+/g, "_"))}> rdf:type ?type
40
- }`;
41
- return request_1.default("http://dbpedia.org/sparql", {
37
+ const url = `http://dbpedia.org/resource/${name.replace(/\s+/g, "_")}`;
38
+ const query = `SELECT ?type WHERE { <${url}> rdf:type ?type }`;
39
+ return (0, request_1.default)("http://dbpedia.org/sparql", {
42
40
  params: { query: query },
43
- timeout: 10 * 1000
44
- }).then((data) => data.results && data.results.bindings);
41
+ timeout: 30 * 1000
42
+ })
43
+ .then((data) => data.results && data.results.bindings)
44
+ .catch((error) => {
45
+ console.error(`${error.message}: ${url}`);
46
+ return [];
47
+ });
45
48
  }
46
49
  function repairTypes(types) {
47
50
  const personIndex = types.findIndex((item) => /:Person$/.test(item));
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exploreEntityClaims = exports.getEntities = void 0;
3
4
  const types_1 = require("../types");
4
5
  const api_1 = require("./api");
5
6
  const simplify_entity_1 = require("./simplify_entity");
@@ -7,17 +8,17 @@ const utils_1 = require("../utils");
7
8
  function getEntities(params) {
8
9
  const claims = params.claims || "none";
9
10
  const lang = params.language || "en";
10
- return api_1.getManyEntities(params).then(function (entities) {
11
- const ids = Object.keys(entities).filter((id) => utils_1.isValidWikiId(id));
11
+ return (0, api_1.getManyEntities)(params).then(function (entities) {
12
+ const ids = Object.keys(entities).filter((id) => (0, utils_1.isValidWikiId)(id));
12
13
  ids.forEach((id) => {
13
- entities[id] = simplify_entity_1.simplifyEntity(lang, entities[id]);
14
+ entities[id] = (0, simplify_entity_1.simplifyEntity)(lang, entities[id]);
14
15
  });
15
16
  const tasks = [];
16
17
  if (~["all", "property"].indexOf(claims)) {
17
18
  tasks.push(exploreEntitiesProperties(entities, lang));
18
19
  }
19
20
  if (~["all", "item"].indexOf(claims)) {
20
- tasks.push(utils_1.eachSeries(ids, (id) => exploreEntityClaims(entities[id].claims, { language: lang })));
21
+ tasks.push((0, utils_1.eachSeries)(ids, (id) => exploreEntityClaims(entities[id].claims, { language: lang })));
21
22
  }
22
23
  return Promise.all(tasks).then(() => entities);
23
24
  });
@@ -35,7 +36,7 @@ function exploreEntitiesProperties(entities, lang) {
35
36
  if (!ids.length) {
36
37
  return Promise.resolve();
37
38
  }
38
- ids = utils_1.uniq(ids);
39
+ ids = (0, utils_1.uniq)(ids);
39
40
  return getEntities({
40
41
  ids: ids,
41
42
  language: lang,
@@ -100,7 +101,7 @@ function exploreEntityClaims(claims, params) {
100
101
  pa.forEach((pai) => {
101
102
  const val = claims[pai.pid].values[pai.index];
102
103
  for (var prop in item) {
103
- if (~["label", "pageid", "description"].indexOf(prop)) {
104
+ if (~["label", "description"].indexOf(prop)) {
104
105
  val[prop] = item[prop];
105
106
  }
106
107
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simplifyClaim = exports.simplifyPropertyClaims = exports.simplifyClaims = void 0;
3
4
  function simplifyClaims(claims) {
4
5
  const simpleClaims = {};
5
6
  for (let id in claims) {
@@ -1,33 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simplifySitelinks = exports.simplifyLabels = exports.simplifyDescriptions = exports.simplifyAliases = exports.simplifyEntity = void 0;
3
4
  const simplify_claims_1 = require("./simplify_claims");
4
5
  function simplifyEntity(lang, data, options = {}) {
5
6
  const entity = { id: data.id };
6
- if (data.pageid) {
7
+ if (data.pageid)
7
8
  entity.pageid = data.pageid;
8
- }
9
+ if (data.redirectsToId)
10
+ entity.redirectsToId = data.redirectsToId;
9
11
  if (options.labels !== false && data.labels) {
10
12
  entity.labels = simplifyLabels(data.labels);
11
13
  entity.label = entity.labels[lang];
12
14
  }
13
15
  if (options.descriptions !== false && data.descriptions) {
14
16
  entity.description = simplifyDescriptions(data.descriptions)[lang];
15
- if (!entity.description) {
17
+ if (!entity.description)
16
18
  delete entity.description;
17
- }
18
19
  }
19
20
  if (options.aliases !== false && data.aliases) {
20
21
  entity.aliases = simplifyAliases(data.aliases)[lang];
21
- if (!entity.aliases) {
22
+ if (!entity.aliases)
22
23
  delete entity.aliases;
23
- }
24
24
  }
25
- if (options.sitelinks !== false && data.sitelinks) {
25
+ if (options.sitelinks !== false && data.sitelinks)
26
26
  entity.sitelinks = simplifySitelinks(data.sitelinks);
27
- }
28
- if (options.claims !== false && data.claims) {
29
- entity.claims = simplify_claims_1.simplifyClaims(data.claims);
30
- }
27
+ if (options.claims !== false && data.claims)
28
+ entity.claims = (0, simplify_claims_1.simplifyClaims)(data.claims);
31
29
  return entity;
32
30
  }
33
31
  exports.simplifyEntity = simplifyEntity;
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
4
5
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
6
  function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getRedirects = exports.getExtract = exports.getExtracts = exports.Api = void 0;
11
13
  const request_1 = require("../request");
12
14
  const API_URL = "https://$lang.wikipedia.org/w/api.php";
13
15
  class Api {
@@ -22,7 +24,7 @@ class Api {
22
24
  return __awaiter(this, void 0, void 0, function* () {
23
25
  if (qs)
24
26
  this.qs = Object.assign({}, this.qs, qs);
25
- const data = yield request_1.default(API_URL.replace("$lang", lang), {
27
+ const data = yield (0, request_1.default)(API_URL.replace("$lang", lang), {
26
28
  params: this.qs,
27
29
  timeout: this.httpTimeout
28
30
  });
@@ -33,14 +35,14 @@ class Api {
33
35
  .map((id) => data.query.pages[id])
34
36
  .map((data) => {
35
37
  const item = {
36
- pageid: data["pageid"],
37
- title: data["title"]
38
+ pageid: data.pageid,
39
+ title: data.title
38
40
  };
39
41
  if (data["categories"]) {
40
- item.categories = data["categories"].map((item) => item.title);
42
+ item.categories = data["categories"].map((it) => it.title);
41
43
  }
42
44
  if (data["redirects"]) {
43
- item.redirects = data["redirects"].map((item) => item.title);
45
+ item.redirects = data["redirects"].map((it) => it.title);
44
46
  }
45
47
  if (data["extract"]) {
46
48
  item.extract = data["extract"];
@@ -89,7 +91,7 @@ function getExtracts(params) {
89
91
  exsectionformat: "plain",
90
92
  format: "json"
91
93
  };
92
- const data = yield request_1.default(API_URL.replace("$lang", params.lang), {
94
+ const data = yield (0, request_1.default)(API_URL.replace("$lang", params.lang), {
93
95
  params: qs
94
96
  });
95
97
  if (hasError(data))
@@ -101,7 +103,7 @@ function getExtracts(params) {
101
103
  });
102
104
  }
103
105
  exports.getExtracts = getExtracts;
104
- exports.getExtract = (lang, title, sentences) => getExtracts({
106
+ const getExtract = (lang, title, sentences) => getExtracts({
105
107
  lang: lang,
106
108
  titles: [title],
107
109
  sentences: sentences
@@ -111,6 +113,7 @@ exports.getExtract = (lang, title, sentences) => getExtracts({
111
113
  }
112
114
  return null;
113
115
  });
116
+ exports.getExtract = getExtract;
114
117
  function getRedirects(lang, title) {
115
118
  return __awaiter(this, void 0, void 0, function* () {
116
119
  const qs = {
@@ -120,7 +123,7 @@ function getRedirects(lang, title) {
120
123
  grdlimit: "max",
121
124
  format: "json"
122
125
  };
123
- const data = yield request_1.default(API_URL.replace("$lang", lang), {
126
+ const data = yield (0, request_1.default)(API_URL.replace("$lang", lang), {
124
127
  params: qs
125
128
  });
126
129
  if (hasError(data))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-entity",
3
- "version": "0.5.3",
3
+ "version": "0.5.7",
4
4
  "description": "Wiki entity fetcher",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./types/index.d.ts",
@@ -35,10 +35,10 @@
35
35
  },
36
36
  "homepage": "https://github.com/entitizer/wiki-entity#readme",
37
37
  "devDependencies": {
38
- "@types/node": "^10.12.18",
38
+ "@types/node": "latest",
39
39
  "debug": "^4.1.1",
40
- "mocha": "^5.2.0",
41
- "typescript": "^3.2.2"
40
+ "mocha": "^9.1.2",
41
+ "typescript": "latest"
42
42
  },
43
43
  "dependencies": {
44
44
  "axios": "^0.21.1"
@@ -24,4 +24,5 @@ export declare type SimpleEntity = {
24
24
  countryCodes?: string[];
25
25
  data?: SimpleEntityData;
26
26
  categories?: string[];
27
+ redirectsToId?: string;
27
28
  };
package/types/types.d.ts CHANGED
@@ -35,6 +35,7 @@ export interface WikiEntity extends WikidataEntity {
35
35
  types?: string[];
36
36
  redirects?: string[];
37
37
  categories?: string[];
38
+ redirectsToId?: string;
38
39
  }
39
40
  export declare type WikiEntities = PlainObject<WikiEntity>;
40
41
  export declare type ParamClaimsType = "none" | "all" | "item" | "property";
@@ -27,5 +27,5 @@ export declare class Api {
27
27
  private addField;
28
28
  }
29
29
  export declare function getExtracts(params: ExtractsParamsType): Promise<ExtractType[]>;
30
- export declare const getExtract: (lang: string, title: string, sentences?: number) => Promise<ExtractType>;
30
+ export declare const getExtract: (lang: string, title: string, sentences?: number) => Promise<ExtractType | null>;
31
31
  export declare function getRedirects(lang: string, title: string): Promise<string[]>;