mirror of
https://github.com/holidayapi/holidayapi-node.git
synced 2025-06-21 12:36:33 +00:00
Merge pull request #6 from holidayapi/development-v2
feat: port to typescript
This commit is contained in:
parent
b6ad36a075
commit
4886f14bc3
21 changed files with 7096 additions and 111 deletions
175
README.md
175
README.md
|
@ -1,33 +1,176 @@
|
|||
# node-holidayapi
|
||||
|
||||
Official Node.js library for [Holiday API](https://holidayapi.com)
|
||||
|
||||
[](https://github.com/holidayapi/node-holidayapi/blob/master/LICENSE)
|
||||

|
||||

|
||||
[](https://coveralls.io/github/holidayapi/node-holidayapi?branch=master)
|
||||
|
||||
## Installation
|
||||
|
||||
```shell
|
||||
# NPM
|
||||
npm install --save node-holidayapi
|
||||
|
||||
# Yarn
|
||||
yarn add node-holidayapi
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var HolidayAPI = require('node-holidayapi');
|
||||
var hapi = new HolidayAPI('_YOUR_API_KEY_').v1;
|
||||
import { HolidayAPI } from 'node-holidayapi';
|
||||
|
||||
var parameters = {
|
||||
// Required
|
||||
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
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
country: 'US',
|
||||
year: 2016,
|
||||
// Optional
|
||||
// month: 7,
|
||||
// day: 4,
|
||||
// previous: true,
|
||||
// upcoming: true,
|
||||
// public: true,
|
||||
// pretty: true,
|
||||
};
|
||||
|
||||
hapi.holidays(parameters, function (err, data) {
|
||||
// Insert awesome code here...
|
||||
year: 2019,
|
||||
});
|
||||
```
|
||||
|
||||
### Fetch holidays for a specific month
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
country: 'US',
|
||||
year: 2019,
|
||||
month: 7,
|
||||
});
|
||||
```
|
||||
|
||||
### Fetch holidays for a specific day
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
country: 'US',
|
||||
year: 2019,
|
||||
month: 7,
|
||||
day: 4,
|
||||
});
|
||||
```
|
||||
|
||||
### Fetch upcoming holidays based on a specific date
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
country: 'US',
|
||||
year: 2019,
|
||||
month: 7,
|
||||
day: 4,
|
||||
upcoming: true,
|
||||
});
|
||||
```
|
||||
|
||||
### Fetch previous holidays based on a specific date
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
country: 'US',
|
||||
year: 2019,
|
||||
month: 7,
|
||||
day: 4,
|
||||
previous: true,
|
||||
});
|
||||
```
|
||||
|
||||
### Fetch only public holidays
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
country: 'US',
|
||||
year: 2019,
|
||||
public: true,
|
||||
});
|
||||
```
|
||||
|
||||
### Fetch holidays for a specific subdivision
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
country: 'GB-ENG',
|
||||
year: 2019,
|
||||
});
|
||||
```
|
||||
|
||||
### Include subdivision holidays with countrywide holidays
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
country: 'US',
|
||||
year: 2019,
|
||||
subdivisions: true,
|
||||
});
|
||||
```
|
||||
|
||||
### Search for a holiday by name
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
country: 'US',
|
||||
year: 2019,
|
||||
search: 'New Year',
|
||||
});
|
||||
```
|
||||
|
||||
### Translate holidays to another language
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
country: 'US',
|
||||
year: 2019,
|
||||
language: 'zh', // Chinese (Simplified)
|
||||
});
|
||||
```
|
||||
|
||||
### Fetch holidays for multiple countries
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
country: 'US,GB,NZ',
|
||||
year: 2019,
|
||||
});
|
||||
|
||||
holidayApi.holidays({
|
||||
country: ['US', 'GB', 'NZ'],
|
||||
year: 2019,
|
||||
});
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue