wikipedia
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -50,1 +50,4 @@ export declare class wikiError extends Error { | ||
} | ||
export declare class eventsError extends wikiError { | ||
constructor(message: string); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.mediaError = exports.relatedError = exports.introError = exports.preloadError = exports.infoboxError = exports.coordinatesError = exports.geoSearchError = exports.linksError = exports.categoriesError = exports.contentError = exports.htmlError = exports.imageError = exports.summaryError = exports.pageError = exports.searchError = exports.wikiError = void 0; | ||
exports.eventsError = exports.mediaError = exports.relatedError = exports.introError = exports.preloadError = exports.infoboxError = exports.coordinatesError = exports.geoSearchError = exports.linksError = exports.categoriesError = exports.contentError = exports.htmlError = exports.imageError = exports.summaryError = exports.pageError = exports.searchError = exports.wikiError = void 0; | ||
class wikiError extends Error { | ||
@@ -117,1 +117,8 @@ constructor(message, code) { | ||
exports.mediaError = mediaError; | ||
class eventsError extends wikiError { | ||
constructor(message) { | ||
super(message); | ||
this.name = 'eventsError'; | ||
} | ||
} | ||
exports.eventsError = eventsError; |
@@ -1,4 +0,4 @@ | ||
import { pageOptions, searchOptions, geoOptions, listOptions } from './optionTypes'; | ||
import { pageOptions, searchOptions, geoOptions, listOptions, eventOptions } from './optionTypes'; | ||
import Page from './page'; | ||
import { coordinatesResult, geoSearchResult, imageResult, langLinksResult, languageResult, wikiMediaResult, wikiSearchResult, wikiSummary } from './resultTypes'; | ||
import { coordinatesResult, eventResult, geoSearchResult, imageResult, langLinksResult, languageResult, wikiMediaResult, wikiSearchResult, wikiSummary } from './resultTypes'; | ||
/** | ||
@@ -237,3 +237,13 @@ * The default wiki export | ||
suggest(query: string): Promise<string | null>; | ||
/** | ||
* Returns the events for a given day | ||
* | ||
* @remarks | ||
* The api returns the events that happened on a particular month and day | ||
* | ||
* @param eventOptions - the event types, and the month and day {@link eventOptions | eventOptions} | ||
* @returns Returns the results as array of {@link eventResult | eventResult} | ||
*/ | ||
onThisDay(eventOptions?: eventOptions): Promise<eventResult>; | ||
}; | ||
export default wiki; |
@@ -497,2 +497,24 @@ "use strict"; | ||
}; | ||
/** | ||
* Returns the events for a given day | ||
* | ||
* @remarks | ||
* The api returns the events that happened on a particular month and day | ||
* | ||
* @param eventOptions - the event types, and the month and day {@link eventOptions | eventOptions} | ||
* @returns Returns the results as array of {@link eventResult | eventResult} | ||
*/ | ||
wiki.onThisDay = async (eventOptions = {}) => { | ||
try { | ||
const type = eventOptions.type || 'all'; | ||
const mm = (eventOptions.month || utils_1.getCurrentMonth()).toString().padStart(2, "0"); | ||
const dd = (eventOptions.day || utils_1.getCurrentDay()).toString().padStart(2, "0"); | ||
const path = `feed/onthisday/${type}/${mm}/${dd}`; | ||
const result = await request_1.makeRestRequest(path, true); | ||
return result; | ||
} | ||
catch (error) { | ||
throw new errors_1.eventsError(error); | ||
} | ||
}; | ||
exports.default = wiki; | ||
@@ -499,0 +521,0 @@ // For CommonJS default export support |
@@ -21,1 +21,7 @@ export interface searchOptions { | ||
export declare type pageFunctions = 'summary' | 'images' | 'intro' | 'html' | 'content' | 'categories' | 'links' | 'references' | 'coordinates' | 'langLinks' | 'infobox' | 'tables' | 'related'; | ||
export interface eventOptions { | ||
type?: eventTypes; | ||
month?: string; | ||
day?: string; | ||
} | ||
export declare type eventTypes = 'all' | 'selected' | 'births' | 'deaths' | 'events' | 'holidays'; |
@@ -100,2 +100,7 @@ export interface wikiSearchResult { | ||
extract_html: string; | ||
normalizedtitle?: string; | ||
coordinates?: { | ||
lat: number; | ||
lon: number; | ||
}; | ||
} | ||
@@ -122,1 +127,27 @@ export interface wikiMediaResult { | ||
} | ||
export interface eventResult { | ||
births?: [{ | ||
text: string; | ||
pages: Array<wikiSummary>; | ||
year?: number; | ||
}]; | ||
deaths?: [{ | ||
text: string; | ||
pages: Array<wikiSummary>; | ||
year?: number; | ||
}]; | ||
events?: [{ | ||
text: string; | ||
pages: Array<wikiSummary>; | ||
year?: number; | ||
}]; | ||
holidays?: [{ | ||
text: string; | ||
pages: Array<wikiSummary>; | ||
}]; | ||
selected?: [{ | ||
text: string; | ||
pages: Array<wikiSummary>; | ||
year?: number; | ||
}]; | ||
} |
@@ -5,1 +5,3 @@ export declare function isString(title: any): boolean; | ||
export declare function setPageId(params: any, results: any): number; | ||
export declare function getCurrentMonth(): number; | ||
export declare function getCurrentDay(): number; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setPageId = exports.setPageIdOrTitleParam = exports.setTitleForPage = exports.isString = void 0; | ||
exports.getCurrentDay = exports.getCurrentMonth = exports.setPageId = exports.setPageIdOrTitleParam = exports.setTitleForPage = exports.isString = void 0; | ||
const _1 = require("."); | ||
@@ -47,1 +47,15 @@ const errors_1 = require("./errors"); | ||
exports.setPageId = setPageId; | ||
//Get current month | ||
function getCurrentMonth() { | ||
const date = new Date(); | ||
const month = date.getMonth(); | ||
return (month + 1); //javascript months are indexed at zero for some reason | ||
} | ||
exports.getCurrentMonth = getCurrentMonth; | ||
//Get current day | ||
function getCurrentDay() { | ||
const date = new Date(); | ||
const day = date.getDate(); | ||
return day; | ||
} | ||
exports.getCurrentDay = getCurrentDay; |
{ | ||
"name": "wikipedia", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A JavaScript wrapper for the wikipedia apis", | ||
@@ -5,0 +5,0 @@ "main": "dist", |
@@ -8,4 +8,6 @@ # WIKIPEDIA [![build](https://github.com/dopecodez/Wikipedia/workflows/build/badge.svg)](https://github.com/dopecodez/Wikipedia/actions) [![Test Coverage](https://api.codeclimate.com/v1/badges/a44c826dbef8c7f5ea45/test_coverage)](https://codeclimate.com/github/dopecodez/Wikipedia/test_coverage) [![Contributions](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dopecodez/Wikipedia/issues) [![npm version](https://badge.fury.io/js/wikipedia.svg)](https://badge.fury.io/js/wikipedia) | ||
Try out the new `summary()` REST endpoint for a introduction to your page and the main images optimized for browsers and mobile! | ||
Try out the new [`summary()`][9] REST endpoint for a introduction to your page and the main images optimized for browsers and mobile! | ||
You can also now get the events which happened on a particular day using the [`onThisDay()`][8] api, which supports filtering by [event types][7] as well. | ||
Built with latest ES6 and native support for async/await and promises. | ||
@@ -38,2 +40,3 @@ | ||
- Find all links/images/categories in a page | ||
- Gets all the relevant events that happened on a particular day. You can further filter this by [event type][7] | ||
- Find related articles from the given article | ||
@@ -83,2 +86,20 @@ - Find articles by geographical location | ||
``` | ||
You can now get the events which happened on a particular day using the new `onThisDay()` api on the wiki object. | ||
```js | ||
const wiki = require('wikipedia'); | ||
(async () => { | ||
try { | ||
const events = await wiki.onThisDay(); | ||
const deaths = await wiki.onThisDay({type:'deaths', month:'2', day:'28'}); | ||
console.log(events); // returns all the events which happened today | ||
console.log(deaths); // returns all deaths which happened on Feb 28 | ||
} catch (error) { | ||
console.log(error); | ||
//=> Typeof wikiError | ||
} | ||
})(); | ||
``` | ||
There are other methods like `search()`, `geoSearch()`, `suggest()`, `setLang()` which should be called on the wiki object directly. Read up on the [wiki documentation][4] to see a complete list of methods available on the wiki default object. | ||
@@ -122,1 +143,4 @@ | ||
[6]: https://github.com/dopecodez/wikipedia/blob/master/docs/resultTypes.md | ||
[7]: https://github.com/dopecodez/wikipedia/blob/master/docs/optionTypes.md#eventOptions | ||
[8]: https://github.com/dopecodez/wikipedia/blob/master/docs/wiki.md#onThisDay | ||
[9]: https://github.com/dopecodez/wikipedia/blob/master/docs/PAGE.md#summary |
93228
2406
143