Official Node.js library for Holiday API https://holidayapi.com
Find a file
Josh Sherman 23dfd7933b
chore: rename package
* No reason to have the `node-` in the published package's name.
2019-09-09 22:47:36 -05:00
dist Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00
src Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00
tests Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00
.eslintrc.json Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00
.gitignore Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00
.npmignore Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00
.travis.yml Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00
jest.config.js Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00
LICENSE Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00
package-lock.json Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00
package.json chore: rename package 2019-09-09 22:47:36 -05:00
README.md chore: rename package 2019-09-09 22:47:36 -05:00
tsconfig.json Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00

node-holidayapi

Official Node.js library for Holiday API

License Node Version Build Status Coverage Status

Installation

# NPM
npm install --save holidayapi

# Yarn
yarn add holidayapi

Usage

import { HolidayAPI } from 'holidayapi';

const key = 'Insert your API key here';
const holidayApi = new HolidayAPI({ key });

// Fetch supported countries and subdivisions
holidayApi.countries()
  .then((countries) => { console.log(countries); })
  .catch((err) => { console.error(err); });

// Fetch supported languages
holidayApi.languages();
  .then((languages) => { console.log(languages); })
  .catch((err) => { console.error(err); });

// Fetch holidays with minimum parameters
holidayApi.holidays({ country: 'US', year: 2019 });
  .then((holidays) => { console.log(holidays); })
  .catch((err) => { console.error(err); });

// Async? Await? No problem!
(async () => {
  // Fetch supported countries and subdivisions
  const countries = await holidayApi.countries();

  // Fetch supported languages
  const languages = await holidayApi.languages();

  // Fetch holidays with minimum parameters
  const holidays = await holidayApi.holidays({
    country: 'US',
    year: 2019,
  });
})();

Examples

Fetch holidays for a specific year

holidayApi.holidays({
  country: 'US',
  year: 2019,
});

Fetch holidays for a specific month

holidayApi.holidays({
  country: 'US',
  year: 2019,
  month: 7,
});

Fetch holidays for a specific day

holidayApi.holidays({
  country: 'US',
  year: 2019,
  month: 7,
  day: 4,
});

Fetch upcoming holidays based on a specific date

holidayApi.holidays({
  country: 'US',
  year: 2019,
  month: 7,
  day: 4,
  upcoming: true,
});

Fetch previous holidays based on a specific date

holidayApi.holidays({
  country: 'US',
  year: 2019,
  month: 7,
  day: 4,
  previous: true,
});

Fetch only public holidays

holidayApi.holidays({
  country: 'US',
  year: 2019,
  public: true,
});

Fetch holidays for a specific subdivision

holidayApi.holidays({
  country: 'GB-ENG',
  year: 2019,
});

Include subdivision holidays with countrywide holidays

holidayApi.holidays({
  country: 'US',
  year: 2019,
  subdivisions: true,
});

Search for a holiday by name

holidayApi.holidays({
  country: 'US',
  year: 2019,
  search: 'New Year',
});

Translate holidays to another language

holidayApi.holidays({
  country: 'US',
  year: 2019,
  language: 'zh', // Chinese (Simplified)
});

Fetch holidays for multiple countries

holidayApi.holidays({
  country: 'US,GB,NZ',
  year: 2019,
});

holidayApi.holidays({
  country: ['US', 'GB', 'NZ'],
  year: 2019,
});