Official Node.js library for Holiday API https://holidayapi.com
Find a file
Josh Sherman d27c12a05c
feat: add workdays endpoint
Added support for our new workdays endpoint that allows you to pull the
number of working days that occur between two dates.

In addition to the new endpoint:
* chore: upgraded dependencies.
* ci: dropped Node.js 10 because it past EOL.
* ci: swapped Node.js 15 for 16 now that it's out.
* docs: added example of new endpoint.
2021-06-10 22:56:16 -05:00
.github/workflows feat: add workdays endpoint 2021-06-10 22:56:16 -05:00
dist chore(deps): bump typescript to 4 2020-12-29 16:43:47 -06:00
src feat: add workdays endpoint 2021-06-10 22:56:16 -05:00
tests feat: add workdays endpoint 2021-06-10 22:56:16 -05:00
.eslintrc.json feat: add workday endpoint 2020-06-20 11:12:10 -05:00
.gitignore test: drop end of life Node.js version 2020-06-08 18:30:21 -05:00
.npmignore Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00
codecov.yml test: drop end of life Node.js version 2020-06-08 18:30:21 -05:00
jest.config.js test: drop end of life Node.js version 2020-06-08 18:30:21 -05:00
LICENSE feat: pull country or language by code. 2020-02-11 19:06:09 -06:00
package-lock.json feat: add workdays endpoint 2021-06-10 22:56:16 -05:00
package.json feat: add workdays endpoint 2021-06-10 22:56:16 -05:00
README.md feat: add workdays endpoint 2021-06-10 22:56:16 -05:00
tsconfig.json Merge pull request #6 from holidayapi/development-v2 2019-09-09 22:30:30 -05:00

Holiday API Node.js Library

License Node Version Test Status Code Coverage

Official Node.js library for Holiday API providing quick and easy access to holiday information from applications written in server-side JavaScript.

Documentation

Full documentation of the Holiday API endpoints is available here.

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

Countries

Fetch all supported countries

holidayApi.countries();

Fetch only countries with public holidays

holidayApi.countries({
  public: true,
});

Fetch a supported country by code

holidayApi.countries({
  country: 'NO',
});

Search for countries by code or name

holidayApi.countries({
  search: 'united',
});

Languages

Fetch all supported languages

holidayApi.languages();

Fetch a supported language by code

holidayApi.language({
  language: 'es',
});

Search for languages by code or name

holidayApi.language({
  search: 'Chinese',
});

Holidays

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,
});

Workday

Fetch workday 7 business days after a date

holidayApi.workday({
  country: 'US',
  start: '2019-07-01',
  days: 7,
});

Workdays

Fetch number of workdays between two dates

holidayApi.workday({
  country: 'US',
  start: '2019-07-01',
  end: '2019-07-10',
});