-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
373 lines (337 loc) · 7.83 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// Definitions by: Balazs Mocsai <https://github.com/mbale>
declare module 'wikijs' {
/**
* Default Options
*
* @interface Options
*/
interface Options {
/**
* URL of Wikipedia API
*
* @type {string}
* @memberof Options
*/
apiUrl?: string;
/**
* When accessing the API using a cross-domain AJAX request (CORS), set this to the originating domain.
* This must be included in any pre-flight request, and therefore must be part of the request URI (not the POST body).
* This must match one of the origins in the Origin header exactly, so it has to be set to something like https://en.wikipedia.org or https://meta.wikimedia.org.
* If this parameter does not match the Origin header, a 403 response will be returned.
* If this parameter matches the Origin header and the origin is whitelisted, an Access-Control-Allow-Origin header will be set.
*
* @type {string}
* @memberof Options
*/
origin?: string;
/**
* The Headers sent to be sent along with the request
*
* @type {HeadersInit}
* @memberof Options
*/
headers?: HeadersInit;
}
/**
* Coordinate object
*
* @interface Coordinates
*/
interface Coordinates {
lat: number;
lon: number;
primary: string;
globe: string;
}
/**
* Link object { lang, title }
*
* @interface Link
*/
interface Link {
lang: string;
title: string;
}
/**
* Image container
*
* @interface Image
*/
interface Image {
ns: number;
title: string;
missing: string;
known: string;
imagerepository: string;
imageinfo: object[];
}
interface Result {
results: string[];
query: string;
next(): Promise<Result>;
}
interface RawPage {
pageid: number;
ns: number;
title: string;
touched: string;
lastrevid: number;
counter: number;
length: number;
fullurl: string;
editurl: string;
}
/**
* WikiPage
*
* @interface Page
*/
interface Page {
raw: RawPage;
/**
* Paginated backlinks from page
*
* @param {boolean} aggregated
* @param {number} limit
* @returns {Promise<string[]>}
* @memberof Page
*/
backlinks(aggregated?: boolean, limit?: number): Promise<string[]>;
/**
* Paginated categories from page
*
* @param {boolean} aggregated
* @param {number} limit
* @returns {Promise<string[]>}
* @memberof Page
*/
categories(aggregated?: boolean, limit?: number): Promise<string[]>;
/**
* Text content from page
*
* @returns {Promise<string>}
* @memberof Page
*/
content(): Promise<string>;
/**
* Geographical coordinates from page
*
* @returns {Promise<Coordinates>}
* @memberof Page
*/
coordinates(): Promise<Coordinates>;
/**
* Get full information from page
*
* @returns {Promise<object>}
* @memberof Page
*/
fullInfo(): Promise<object>;
/**
* HTML from page
*
* @returns {Promise<string>}
* @memberof Page
*/
html(): Promise<string>;
/**
* Image URL's from page
*
* info Object contains key/value pairs of infobox data, or specific value if key given
* @returns {Promise<string[]>}
* @memberof Page
*/
images(): Promise<string[]>;
/**
* Get information from page
*
* @param {string} [key]
* Information key. Falsy keys are ignored
* @returns {Promise<object>}
* @memberof Page
*/
info(key?: string): Promise<object>;
/**
* Get list of links to different translations
*
* @returns {Promise<Link[]>}
* @memberof Page
*/
langlinks(): Promise<Link[]>;
/**
* Paginated links from page
*
* @param {boolean} [aggregated]
* return all links (default is true)
* @param {number} [limit]
* number of links per page
* @returns {Promise<string[]>}
* @memberof Page
*/
links(aggregated?: boolean, limit?: number): Promise<string[]>;
/**
* Main image URL from infobox on page
*
* @returns {Promise<string>}
* @memberof Page
*/
mainImage(): Promise<string>;
/**
* Raw content from page
*
* @returns {Promise<string>}
* @memberof Page
*/
rawContent(): Promise<string>;
/**
* Raw data from images from page
*
* @returns {Promise<Image[]>}
* @memberof Page
*/
rawImages(): Promise<Image[]>;
/**
* References from page
*
* @returns {Promise<string[]>}
* @memberof Page
*/
references(): Promise<string[]>;
/**
* Text summary from page
*
* @returns {Promise<string>}
* @memberof Page
*/
summary(): Promise<string>;
/**
* Tables from page
*
* @returns {Promise<any>}
* @memberof Page
*/
tables(): Promise<any>;
/**
* Get URL for wiki page
*
* @return {String}
* @memberof Page
*/
url(): string;
}
/**
* WikiJs is a node.js library which serves as an interface to Wikipedia (or any MediaWiki).
*
* @param {Options} [options]
*/
export default function WikiJS(
options?: Options
): {
/**
* Get Page by PageId
*
* @param {string} pageID
* id of the page
* @returns {Promise<Page>}
*/
findById(pageID: string): Promise<Page>;
/**
* Find page by query and optional predicate
* @example
* wiki.find('luke skywalker').then(page => console.log(page.title));
* @method Wiki#find
* @param {string} search query
* @param {function} [predicate] - testing function for choosing which page result to fetch. Default is first result.
* @return {Promise}
*/
find(query: string, predicate?: (pages: Page[]) => Page): Promise<Page>;
/**
* Geographical Search
*
* @param {number} lat
* latitude
* @param {number} lon
* longitude
* @param {number} [radius]
* search radius in kilometers (default: 1km)
* @returns {Promise<string[]>}
*/
geoSearch(lat: number, lon: number, radius?: number): Promise<string[]>;
/**
* Get Page
*
* @param {string} title
* title of article
* @returns {Promise<Page>}
*/
page(title: string): Promise<Page>;
/**
* Fetch all page titles in wiki
* @method Wiki#allPages
* @return {Array} Array of pages
*/
allPages(): Promise<string[]>;
/**
* Random articles
*
* @param {number} [limit]
* limits the number of random articles
* @returns {Promise<string[]>}
*/
random(limit?: number): Promise<string[]>;
/**
* Search articles
*
* @param {string} query
* keyword query
* @param {number} [limit]
* limits the number of results
* @returns {Promise<Result>}
*/
search(query: string, limit?: number): Promise<Result>;
/**
* Opensearch (mainly used as a backup to normal text search)
* @param {string} query - keyword query
* @param {Number} limit - limits the number of results
* @return {Promise<string[]>} List of page title results
*/
opensearch(query: string, limit?: number): Promise<string[]>;
/**
* Search articles using "fuzzy" prefixsearch
*
* @param {string} query
* keyword query
* @param {number} [limit]
* limits the number of results
* @returns {Promise<Result>}
*/
prefixSearch(query: string, limit?: number): Promise<Result>;
/**
* @summary Find the most viewed pages with counts
* @example
* wiki.mostViewed().then(list => console.log(`${list[0].title}: ${list[0].count}`))
* @method Wiki#mostViewed
* @returns {Promise} - Array of {title,count}
*/
mostViewed(): Promise<{ title: string; count: number }[]>;
/**
* Fetch all page titles in wiki
* @method Wiki#allPages
* @return {Promise<string[]>} Array of pages
*/
allPages(): Promise<string[]>;
/**
* Fetch all categories in wiki
* @method Wiki#allCategories
* @return {Promise<string[]>} Array of categories
*/
allCategories(): Promise<string[]>;
/**
* Fetch all pages in category
* @method Wiki#pagesInCategory
* @param {String} category Category to fetch from
* @return {Promise<string[]>} Array of pages
*/
pagesInCategory(category: string): Promise<string[]>;
};
}