Skip to content

Latest commit

 

History

39 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OnThisDay.js

Repo Banner for OnThisDay.js - JavaScript Library

Show your support!

OnThisDay.js is a zero-dependency JavaScript library for fetching historical events, births, deaths, and holidays from the Wikimedia REST API. It works in Node.js 18+ and modern browsers.

Example and usage

How to use OnThisDay.js:

import { OnThisDay } from 'https://esm.sh/gh/MarketingPipeline/OnThisDay.js';

// Fetch events, births, and deaths for a specific date
try {
    const result = await OnThisDay(7, 4);
    
    console.log(result.getEvents());   // historical events
    console.log(result.getBirths());   // famous births
    console.log(result.getDeaths());   // notable deaths
    console.log(result.getHolidays()); // holidays & observances
    console.log(result.getSelected()); // editor's picks
    console.log(result.getAll());      // everything at once
    console.log(result.getRaw());      // full Wikimedia response
} catch (error) {
    console.log(error.message)
}

// Fetch events, births, and deaths that happened on the current date.
try {
    const onToday = await OnThisDay()
    console.log('All Data:', onToday.getAll());
    console.log('Births:', onToday.getBirths());
    console.log('Deaths:', onToday.getDeaths());
    console.log('Events:', onToday.getEvents());
    console.log('Holidays:', onToday.getHolidays());
    console.log('Editor Picks:', onToday.getSelected());
    console.log('Wikimedia:', onToday.getRaw());
} catch (error) {
    console.log(error.message)
}

// With options
try {
    const withOptions = await OnThisDay(7, 4, {
      lang: 'de',       // see supported languages below
      timeout: 5000     // milliseconds
    });
} catch (error) {
    console.log(error.message)
}

// Invalid date
try {
    await OnThisDay(2, 30);
} catch (error) {
    console.log(error.message)
}

// Unsupported language
try {
    await OnThisDay(7, 4, { lang: 'ja' });
} catch (error) {
    console.log(error.message)
}

Options

Option Default Description
lang 'en' en, es, de, fr, zh, ru, ar, pt, sv, tr, cs, uk
timeout 10000 Request timeout in milliseconds

Contributing GitHub

Want to improve this? Create a pull request with detailed changes.

See the list of contributors who participate in this project.

License GitHub

This library is open-source and available under the MIT License. See the LICENSE file for more details.

Releases

Used by

Contributors

Languages