holidayapi
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -27,2 +27,6 @@ { | ||
"@typescript-eslint/no-unused-vars": "error", | ||
"import/no-extraneous-dependencies": [ | ||
"error", | ||
{ "devDependencies": ["**/*.test.ts"] } | ||
], | ||
"import/prefer-default-export": "off", | ||
@@ -29,0 +33,0 @@ "lines-between-class-members": "off", |
export declare type Endpoint = 'countries' | 'holidays' | 'languages'; | ||
export declare type Request = { | ||
format?: 'csv' | 'json' | 'php' | 'tsv' | 'yaml' | 'xml'; | ||
key?: string; | ||
format?: 'csv' | 'json' | 'php' | 'tsv' | 'yaml' | 'xml'; | ||
pretty?: boolean; | ||
search?: string; | ||
}; | ||
@@ -10,11 +11,10 @@ export declare type Requests = Request | HolidaysRequest; | ||
country?: string; | ||
year?: number; | ||
day?: number; | ||
language?: string; | ||
month?: number; | ||
language?: string; | ||
previous?: boolean; | ||
public?: boolean; | ||
search?: string; | ||
subdivisions?: boolean; | ||
upcoming?: boolean; | ||
year?: number; | ||
}; | ||
@@ -21,0 +21,0 @@ export declare type Response = { |
{ | ||
"name": "holidayapi", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Official Node.js library for Holiday API", | ||
@@ -29,8 +29,8 @@ "main": "dist/index.js", | ||
"@types/nock": "^10.0.3", | ||
"@types/node": "^12.7.4", | ||
"@types/node-fetch": "^2.5.0", | ||
"@typescript-eslint/eslint-plugin": "^2.2.0", | ||
"@typescript-eslint/parser": "^2.2.0", | ||
"@types/node": "^12.7.11", | ||
"@types/node-fetch": "^2.5.2", | ||
"@typescript-eslint/eslint-plugin": "^2.3.2", | ||
"@typescript-eslint/parser": "^2.3.2", | ||
"coveralls": "^3.0.6", | ||
"eslint": "^6.3.0", | ||
"eslint": "^6.5.1", | ||
"eslint-config-airbnb-base": "^14.0.0", | ||
@@ -41,4 +41,4 @@ "eslint-plugin-import": "^2.18.2", | ||
"nock": "^10.0.6", | ||
"ts-jest": "^24.0.2", | ||
"typescript": "^3.6.2" | ||
"ts-jest": "^24.1.0", | ||
"typescript": "^3.6.3" | ||
}, | ||
@@ -45,0 +45,0 @@ "dependencies": { |
# Holiday API Node.js Library | ||
[![License](https://img.shields.io/npm/l/node-holidayapi?style=for-the-badge)](https://github.com/holidayapi/node-holidayapi/blob/master/LICENSE) | ||
[![License](https://img.shields.io/npm/l/holidayapi-node?style=for-the-badge)](https://github.com/holidayapi/holidayapi-node/blob/master/LICENSE) | ||
![Node Version](https://img.shields.io/node/v/holidayapi?style=for-the-badge) | ||
![Build Status](https://img.shields.io/travis/holidayapi/node-holidayapi/master?style=for-the-badge) | ||
[![Coverage Status](https://img.shields.io/coveralls/github/holidayapi/node-holidayapi/master?style=for-the-badge)](https://coveralls.io/github/holidayapi/node-holidayapi?branch=master) | ||
![Build Status](https://img.shields.io/travis/holidayapi/holidayapi-node/master?style=for-the-badge) | ||
[![Coverage Status](https://img.shields.io/coveralls/github/holidayapi/holidayapi-node/master?style=for-the-badge)](https://coveralls.io/github/holidayapi/holidayapi-node?branch=master) | ||
@@ -12,7 +12,17 @@ Official Node.js library for [Holiday API](https://holidayapi.com) providing | ||
## Migrating from 1.x | ||
Please note, version 2.x of this library is a full rewrite of the 1.x series in | ||
TypeScript. The interfacing to the library has been simplified and existing | ||
applications upgrading to 2.x will need some massaging. Sorry for any | ||
inconvenience. | ||
applications upgrading to 2.x will need to be updated. | ||
| Version 1.x Syntax (Old) | Version 2.x Syntax (New) | | ||
|---------------------------------------------------|---------------------------------------------------| | ||
| `const HolidayAPI = require('node-holidayapi');` | `import { HolidayAPI } from 'holidayapi';` | | ||
| `const holidayApi = new HolidayAPI(key).v1;` | `const holidayApi = new HolidayAPI({ key });` | | ||
| `holidayApi.holidays(params, (err, data) => {});` | `holidayApi.holidays(params).then((data) => {});` | | ||
Version 1.x of the library can still be found | ||
[here](https://github.com/joshtronic/node-holidayapi). | ||
## Documentation | ||
@@ -74,5 +84,39 @@ | ||
### Fetch holidays for a specific year | ||
### Countries | ||
#### Fetch all supported countries | ||
```javascript | ||
holidayApi.countries(); | ||
``` | ||
#### Search for a country by code or name | ||
```javascript | ||
holidayApi.countries({ | ||
search: 'united', | ||
}); | ||
``` | ||
### Languages | ||
#### Fetch all supported languages | ||
```javascript | ||
holidayApi.languages(); | ||
``` | ||
#### Search for a language by code or name | ||
```javascript | ||
holidayApi.language({ | ||
search: 'Chinese', | ||
}); | ||
``` | ||
### Holidays | ||
#### Fetch holidays for a specific year | ||
```javascript | ||
holidayApi.holidays({ | ||
@@ -84,3 +128,3 @@ country: 'US', | ||
### Fetch holidays for a specific month | ||
#### Fetch holidays for a specific month | ||
@@ -95,3 +139,3 @@ ```javascript | ||
### Fetch holidays for a specific day | ||
#### Fetch holidays for a specific day | ||
@@ -107,3 +151,3 @@ ```javascript | ||
### Fetch upcoming holidays based on a specific date | ||
#### Fetch upcoming holidays based on a specific date | ||
@@ -120,3 +164,3 @@ ```javascript | ||
### Fetch previous holidays based on a specific date | ||
#### Fetch previous holidays based on a specific date | ||
@@ -133,3 +177,3 @@ ```javascript | ||
### Fetch only public holidays | ||
#### Fetch only public holidays | ||
@@ -144,3 +188,3 @@ ```javascript | ||
### Fetch holidays for a specific subdivision | ||
#### Fetch holidays for a specific subdivision | ||
@@ -154,3 +198,3 @@ ```javascript | ||
### Include subdivision holidays with countrywide holidays | ||
#### Include subdivision holidays with countrywide holidays | ||
@@ -165,3 +209,3 @@ ```javascript | ||
### Search for a holiday by name | ||
#### Search for a holiday by name | ||
@@ -176,3 +220,3 @@ ```javascript | ||
### Translate holidays to another language | ||
#### Translate holidays to another language | ||
@@ -187,3 +231,3 @@ ```javascript | ||
### Fetch holidays for multiple countries | ||
#### Fetch holidays for multiple countries | ||
@@ -190,0 +234,0 @@ ```javascript |
@@ -96,2 +96,43 @@ import * as nock from 'nock'; | ||
it('should search countries', async () => { | ||
const expectedResponse = { | ||
status: 200, | ||
requests: { | ||
used: 1000, | ||
available: 9000, | ||
resets: '2019-10-01 00:00:00', | ||
}, | ||
countries: [ | ||
{ | ||
code: 'ST', | ||
name: 'Sao Tome and Principe', | ||
languages: ['pt'], | ||
codes: { | ||
'alpha-2': 'ST', | ||
'alpha-3': 'STP', | ||
numeric: 678, | ||
}, | ||
flag: 'https://www.countryflags.io/ST/flat/64.png', | ||
subdivisions: [ | ||
{ | ||
code: 'ST-P', | ||
name: 'Príncipe', | ||
languages: ['pt'], | ||
}, | ||
{ | ||
code: 'ST-S', | ||
name: 'São Tomé', | ||
languages: ['pt'], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
mockRequest.get(`${basePath}&search=Sao`).reply(200, expectedResponse); | ||
expect(await holidayapi.countries({ | ||
search: 'Sao', | ||
})).toStrictEqual(expectedResponse); | ||
}); | ||
it('should raise 4xx errors', async () => { | ||
@@ -169,2 +210,42 @@ const expectedResponse = { | ||
it('should search holidays', async () => { | ||
const expectedResponse = { | ||
status: 200, | ||
requests: { | ||
used: 1000, | ||
available: 9000, | ||
resets: '2019-10-01 00:00:00', | ||
}, | ||
holidays: [ | ||
{ | ||
name: 'Independence Day', | ||
date: '2015-07-04', | ||
observed: '2015-07-03', | ||
public: true, | ||
country: 'US', | ||
uuid: '88268759-9b90-468c-804f-b729b8418e7c', | ||
weekday: { | ||
date: { | ||
name: 'Saturday', | ||
numeric: '6', | ||
}, | ||
observed: { | ||
name: 'Friday', | ||
numeric: '5', | ||
}, | ||
}, | ||
}, | ||
], | ||
}; | ||
mockRequest.get(`${basePath}&country=US&year=2019&search=Independence`) | ||
.reply(200, expectedResponse); | ||
expect(await holidayapi.holidays({ | ||
country: 'US', | ||
year: 2019, | ||
search: 'Independence', | ||
})).toStrictEqual(expectedResponse); | ||
}); | ||
it('should error when country is missing', async () => { | ||
@@ -273,2 +354,28 @@ expect.assertions(1); | ||
it('should search languages', async () => { | ||
const expectedResponse = { | ||
status: 200, | ||
requests: { | ||
used: 1000, | ||
available: 9000, | ||
resets: '2019-10-01 00:00:00', | ||
}, | ||
languages: [ | ||
{ | ||
code: 'hi', | ||
name: 'Hindi', | ||
}, | ||
{ | ||
code: 'zh', | ||
name: 'Chinese (Simplified)', | ||
}, | ||
], | ||
}; | ||
mockRequest.get(`${basePath}&search=in`).reply(200, expectedResponse); | ||
expect(await holidayapi.languages({ | ||
search: 'in', | ||
})).toStrictEqual(expectedResponse); | ||
}); | ||
it('should raise 4xx errors', async () => { | ||
@@ -275,0 +382,0 @@ const expectedResponse = { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28280
623
233