wiki-entity 0.4.5 → 0.4.6

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
@@ -34,6 +34,7 @@ Required. `ids` or `titles` require. Params properties:
34
34
  - **redirects** : *boolean* - get wikipedia redirects titles. Default: `false`. Works only if `sitelinks` is present.
35
35
  - **categories** : *boolean* - get wikipedia article categories. Default: `false`. Works only if `sitelinks` is present.
36
36
  - **httpTimeout**: *number* - http requests timeout
37
+ - **languages**: "string"[] - languages for `WikiEntity.labels`
37
38
 
38
39
  ### convertToSimpleEntity(wikiEntity: WikiEntity): SimpleEntity
39
40
 
@@ -48,6 +49,7 @@ Convert a complex WikiEntity object to SimpleEntity object.
48
49
  type WikiEntity = {
49
50
  id: string;
50
51
  label?: string;
52
+ labels?: IIndexType<string>;
51
53
  description?: string;
52
54
  extract?: string;
53
55
  pageid?: number;
@@ -8,11 +8,13 @@ function getEntityData(wikiEntity) {
8
8
  for (let key in wikiEntity.claims) {
9
9
  const values = wikiEntity.claims[key].values;
10
10
  data[key] = [];
11
- values.forEach(value => {
11
+ values.forEach((value) => {
12
12
  if (!value.value_string && value.value === null) {
13
13
  throw new Error(`WikiEntity claim value cannot be null: ${wikiEntity.id}:${key}`);
14
14
  }
15
- const v = { value: value.value_string || value.value.toString() };
15
+ const v = {
16
+ value: value.value_string || value.value.toString()
17
+ };
16
18
  if (value.label && v.value !== value.label) {
17
19
  v.label = value.label;
18
20
  }
@@ -27,7 +27,9 @@ function getEntities(params) {
27
27
  types_1.WikidataPropsParam.claims,
28
28
  types_1.WikidataPropsParam.datatype
29
29
  ]).join("|"),
30
- languages: getStringArrayParam(params.language, "en"),
30
+ languages: params.languages
31
+ ? params.languages.join("|")
32
+ : params.language || "en",
31
33
  redirects: params.redirect || "yes",
32
34
  format: "json",
33
35
  sites: ""
@@ -7,7 +7,8 @@ function simplifyEntity(lang, data, options = {}) {
7
7
  entity.pageid = data.pageid;
8
8
  }
9
9
  if (options.labels !== false && data.labels) {
10
- entity.label = simplifyLabels(data.labels)[lang];
10
+ entity.labels = simplifyLabels(data.labels);
11
+ entity.label = entity.labels[lang];
11
12
  }
12
13
  if (options.descriptions !== false && data.descriptions) {
13
14
  entity.description = simplifyDescriptions(data.descriptions)[lang];
@@ -45,7 +46,9 @@ exports.simplifyLabels = simplifyLabels;
45
46
  function simplifySitelinks(data) {
46
47
  if (data) {
47
48
  const result = {};
48
- Object.keys(data).forEach(site => { result[site.replace(/wiki$/, '')] = data[site].title; });
49
+ Object.keys(data).forEach((site) => {
50
+ result[site.replace(/wiki$/, "")] = data[site].title;
51
+ });
49
52
  return result;
50
53
  }
51
54
  return null;
@@ -54,7 +57,9 @@ exports.simplifySitelinks = simplifySitelinks;
54
57
  function getLangValue(data) {
55
58
  if (data) {
56
59
  const result = {};
57
- Object.keys(data).forEach(lang => { result[lang] = data[lang].value; });
60
+ Object.keys(data).forEach((lang) => {
61
+ result[lang] = data[lang].value;
62
+ });
58
63
  return result;
59
64
  }
60
65
  return null;
@@ -62,7 +67,9 @@ function getLangValue(data) {
62
67
  function getManyLangValue(data) {
63
68
  if (data) {
64
69
  const result = {};
65
- Object.keys(data).forEach(lang => { result[lang] = data[lang].map((item) => item.value); });
70
+ Object.keys(data).forEach((lang) => {
71
+ result[lang] = data[lang].map((item) => item.value);
72
+ });
66
73
  return result;
67
74
  }
68
75
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-entity",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "description": "Wiki entity fetcher",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./types/index.d.ts",
package/types/types.d.ts CHANGED
@@ -26,6 +26,7 @@ export interface WikidataEntity extends WikidataBaseEntity {
26
26
  aliases?: string[];
27
27
  sitelinks?: PlainObject<string>;
28
28
  claims?: WikidataEntityClaims;
29
+ labels?: PlainObject<string>;
29
30
  }
30
31
  export declare type WikidataEntities = PlainObject<WikidataEntity>;
31
32
  export interface WikiEntity extends WikidataEntity {
@@ -44,6 +45,7 @@ export interface WikidataEntitiesParams {
44
45
  redirect?: string;
45
46
  claims?: ParamClaimsType;
46
47
  httpTimeout?: number;
48
+ languages?: string[];
47
49
  }
48
50
  export declare enum WikidataPropsParam {
49
51
  info = "info",
@@ -1,4 +1,4 @@
1
- import { WikidataEntity } from '../types';
1
+ import { WikidataEntity } from "../types";
2
2
  export declare type SimplifyEntityOptionsType = {
3
3
  labels?: boolean;
4
4
  descriptions?: boolean;