
OnThisDay.js is a lightweight JavaScript library that allows you to retrieve and display significant occurrences from history. It can be useful for history enthusiasts, educators, and anyone interested in daily historical tidbits.
This library works by fetching historical events, births, and deaths from Wikipedia for any date. You can integrate it into websites or applications to show “On This Day” facts, create historical timelines, or build educational tools.
How it works:
OnThisDay.js uses the wtf_wikipedia library to interact with Wikipedia’s API. The library fetches raw HTML content from Wikipedia pages for specific dates.
It then parses this content and uses regular expressions to extract relevant information like years and descriptions of events, births, and deaths. This data is then organized into structured JavaScript objects.
How to use it:
1. Download and import the OnThisDay into your web project.
import { OnThisDay } from './dist/onthisday.min.js';2. Now, you can fetch data for a specific date. Let’s use July 31st as an example:
try {
let onDate = await OnThisDay('Feb 29')
// or for today:: let onToday = await OnThisDay()
console.log('All Data:', onDate.getAll());
console.log('Births:', onDate.getBirths());
console.log('Deaths:', onDate.getDeaths());
console.log('Events:', onDate.getEvents());
} catch (error) {
console.log(error.message)
}3. The library will retrieve all data associated with February 29th and output it to the console. The returned data is in an easily parsable JavaScript object format like so:
{
"date": "July 31",
"events": [
null,
{
"year": 781,
"event": "The oldest recorded eruption of Mount Fuji (Traditional Japanese date: Sixth day of the seventh month of the first year of the Ten'o (天応) era)."
},
{
"year": 1009,
"event": "Pope Sergius IV becomes the 142nd pope, succeeding Pope John XVIII."
},
{
"year": 1201,
"event": "Attempted usurpation by John Komnenos the Fat for the throne of Alexios III Angelos."
},
]
"births": [
{
"year": 1143,
"event": "Emperor Nijō of Japan (d. 1165)"
},
{
"year": 1396,
"event": "Philip III, Duke of Burgundy (d. 1467)"
},
// ...
]
"deaths": [
null,
{
"year": 450,
"event": "Peter Chrysologus, Italian bishop and saint (b. 380)"
},
{
"year": 910,
"event": "Feng Xingxi, Chinese warlord"
},
{
"year": 975,
"event": "Fu Yanqing, Chinese general (b. 898)"
},
// ...
]
}





