mirror of
https://github.com/holidayapi/holidayapi-node.git
synced 2025-06-21 04:26:33 +00:00
feat: add search capability to all calls
* chore: Updated dependencies. * test: Fixed a linter issue in the test suite. * feat: Updated all requests to contain the `search` property. * chore: Cleaned up some of the type properties order (alphabetized). * test: Added tests to cover the search capabilities. * docs: Added examples to the readme to cover all endpoints as well as search. * docs: Updated the readme to cover migrating from v1 to v2. * docs: Fixed repository links where applicable. * chore: Bumped the minor version number.
This commit is contained in:
parent
80d96a68ef
commit
e36a998229
7 changed files with 238 additions and 76 deletions
|
@ -24,6 +24,10 @@
|
|||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"import/no-extraneous-dependencies": [
|
||||
"error",
|
||||
{ "devDependencies": ["**/*.test.ts"] }
|
||||
],
|
||||
"import/prefer-default-export": "off",
|
||||
"lines-between-class-members": "off",
|
||||
"no-unused-vars": "off"
|
||||
|
|
76
README.md
76
README.md
|
@ -1,18 +1,28 @@
|
|||
# Holiday API Node.js Library
|
||||
|
||||
[](https://github.com/holidayapi/node-holidayapi/blob/master/LICENSE)
|
||||
[](https://github.com/holidayapi/holidayapi-node/blob/master/LICENSE)
|
||||

|
||||

|
||||
[](https://coveralls.io/github/holidayapi/node-holidayapi?branch=master)
|
||||

|
||||
[](https://coveralls.io/github/holidayapi/holidayapi-node?branch=master)
|
||||
|
||||
Official Node.js library for [Holiday API](https://holidayapi.com) providing
|
||||
quick and easy access to holiday information from applications written in
|
||||
server-side JavaScript.
|
||||
|
||||
## 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
|
||||
|
||||
|
@ -70,7 +80,41 @@ holidayApi.holidays({ country: 'US', year: 2019 });
|
|||
|
||||
## Examples
|
||||
|
||||
### 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({
|
||||
|
@ -79,7 +123,7 @@ holidayApi.holidays({
|
|||
});
|
||||
```
|
||||
|
||||
### Fetch holidays for a specific month
|
||||
#### Fetch holidays for a specific month
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
|
@ -89,7 +133,7 @@ holidayApi.holidays({
|
|||
});
|
||||
```
|
||||
|
||||
### Fetch holidays for a specific day
|
||||
#### Fetch holidays for a specific day
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
|
@ -100,7 +144,7 @@ holidayApi.holidays({
|
|||
});
|
||||
```
|
||||
|
||||
### Fetch upcoming holidays based on a specific date
|
||||
#### Fetch upcoming holidays based on a specific date
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
|
@ -112,7 +156,7 @@ holidayApi.holidays({
|
|||
});
|
||||
```
|
||||
|
||||
### Fetch previous holidays based on a specific date
|
||||
#### Fetch previous holidays based on a specific date
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
|
@ -124,7 +168,7 @@ holidayApi.holidays({
|
|||
});
|
||||
```
|
||||
|
||||
### Fetch only public holidays
|
||||
#### Fetch only public holidays
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
|
@ -134,7 +178,7 @@ holidayApi.holidays({
|
|||
});
|
||||
```
|
||||
|
||||
### Fetch holidays for a specific subdivision
|
||||
#### Fetch holidays for a specific subdivision
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
|
@ -143,7 +187,7 @@ holidayApi.holidays({
|
|||
});
|
||||
```
|
||||
|
||||
### Include subdivision holidays with countrywide holidays
|
||||
#### Include subdivision holidays with countrywide holidays
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
|
@ -153,7 +197,7 @@ holidayApi.holidays({
|
|||
});
|
||||
```
|
||||
|
||||
### Search for a holiday by name
|
||||
#### Search for a holiday by name
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
|
@ -163,7 +207,7 @@ holidayApi.holidays({
|
|||
});
|
||||
```
|
||||
|
||||
### Translate holidays to another language
|
||||
#### Translate holidays to another language
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
|
@ -173,7 +217,7 @@ holidayApi.holidays({
|
|||
});
|
||||
```
|
||||
|
||||
### Fetch holidays for multiple countries
|
||||
#### Fetch holidays for multiple countries
|
||||
|
||||
```javascript
|
||||
holidayApi.holidays({
|
||||
|
|
8
dist/types.d.ts
vendored
8
dist/types.d.ts
vendored
|
@ -1,21 +1,21 @@
|
|||
export declare type Endpoint = 'countries' | 'holidays' | 'languages';
|
||||
export declare type Request = {
|
||||
key?: string;
|
||||
format?: 'csv' | 'json' | 'php' | 'tsv' | 'yaml' | 'xml';
|
||||
key?: string;
|
||||
pretty?: boolean;
|
||||
search?: string;
|
||||
};
|
||||
export declare type Requests = Request | HolidaysRequest;
|
||||
export declare type HolidaysRequest = Request & {
|
||||
country?: string;
|
||||
year?: number;
|
||||
day?: number;
|
||||
month?: number;
|
||||
language?: string;
|
||||
month?: number;
|
||||
previous?: boolean;
|
||||
public?: boolean;
|
||||
search?: string;
|
||||
subdivisions?: boolean;
|
||||
upcoming?: boolean;
|
||||
year?: number;
|
||||
};
|
||||
export declare type Response = {
|
||||
requests: {
|
||||
|
|
95
package-lock.json
generated
95
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "holidayapi",
|
||||
"version": "2.0.0",
|
||||
"version": "2.1.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -470,15 +470,15 @@
|
|||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "12.7.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.4.tgz",
|
||||
"integrity": "sha512-W0+n1Y+gK/8G2P/piTkBBN38Qc5Q1ZSO6B5H3QmPCUewaiXOo2GCAWZ4ElZCcNhjJuBSUSLGFUJnmlCn5+nxOQ==",
|
||||
"version": "12.7.11",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.7.11.tgz",
|
||||
"integrity": "sha512-Otxmr2rrZLKRYIybtdG/sgeO+tHY20GxeDjcGmUnmmlCWyEnv2a2x1ZXBo3BTec4OiTXMQCiazB8NMBf0iRlFw==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/node-fetch": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.0.tgz",
|
||||
"integrity": "sha512-TLFRywthBgL68auWj+ziWu+vnmmcHCDFC/sqCOQf1xTz4hRq8cu79z8CtHU9lncExGBsB8fXA4TiLDLt6xvMzw==",
|
||||
"version": "2.5.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.2.tgz",
|
||||
"integrity": "sha512-djYYKmdNRSBtL1x4CiE9UJb9yZhwtI1VC+UxZD0psNznrUj80ywsxKlEGAE+QL1qvLjPbfb24VosjkYM6W4RSQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
|
@ -506,12 +506,12 @@
|
|||
"dev": true
|
||||
},
|
||||
"@typescript-eslint/eslint-plugin": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.2.0.tgz",
|
||||
"integrity": "sha512-rOodtI+IvaO8USa6ValYOrdWm9eQBgqwsY+B0PPiB+aSiK6p6Z4l9jLn/jI3z3WM4mkABAhKIqvGIBl0AFRaLQ==",
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.3.2.tgz",
|
||||
"integrity": "sha512-tcnpksq1bXzcIRbYLeXkgp6l+ggEMXXUcl1wsSvL807fRtmvVQKygElwEUf4hBA76dNag3VAK1q2m3vd7qJaZA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/experimental-utils": "2.2.0",
|
||||
"@typescript-eslint/experimental-utils": "2.3.2",
|
||||
"eslint-utils": "^1.4.2",
|
||||
"functional-red-black-tree": "^1.0.1",
|
||||
"regexpp": "^2.0.1",
|
||||
|
@ -519,13 +519,13 @@
|
|||
}
|
||||
},
|
||||
"@typescript-eslint/experimental-utils": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.2.0.tgz",
|
||||
"integrity": "sha512-IMhbewFs27Frd/ICHBRfIcsUCK213B8MsEUqvKFK14SDPjPR5JF6jgOGPlroybFTrGWpMvN5tMZdXAf+xcmxsA==",
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.3.2.tgz",
|
||||
"integrity": "sha512-t+JGdTT6dRbmvKDlhlVkEueoZa0fhJNfG6z2cpnRPLwm3VwYr2BjR//acJGC1Yza0I9ZNcDfRY7ubQEvvfG6Jg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/json-schema": "^7.0.3",
|
||||
"@typescript-eslint/typescript-estree": "2.2.0",
|
||||
"@typescript-eslint/typescript-estree": "2.3.2",
|
||||
"eslint-scope": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -542,21 +542,21 @@
|
|||
}
|
||||
},
|
||||
"@typescript-eslint/parser": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.2.0.tgz",
|
||||
"integrity": "sha512-0mf893kj9L65O5sA7wP6EoYvTybefuRFavUNhT7w9kjhkdZodoViwVS+k3D+ZxKhvtL7xGtP/y/cNMJX9S8W4A==",
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.3.2.tgz",
|
||||
"integrity": "sha512-nq1UQeNGdKdqdgF6Ww+Ov2OidWgiL96+JYdXXZ2rkP/OWyc6KMNSbs6MpRCpI8q+PmDa7hBnHNQIo7w/drYccA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/eslint-visitor-keys": "^1.0.0",
|
||||
"@typescript-eslint/experimental-utils": "2.2.0",
|
||||
"@typescript-eslint/typescript-estree": "2.2.0",
|
||||
"@typescript-eslint/experimental-utils": "2.3.2",
|
||||
"@typescript-eslint/typescript-estree": "2.3.2",
|
||||
"eslint-visitor-keys": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/typescript-estree": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.2.0.tgz",
|
||||
"integrity": "sha512-9/6x23A3HwWWRjEQbuR24on5XIfVmV96cDpGR9671eJv1ebFKHj2sGVVAwkAVXR2UNuhY1NeKS2QMv5P8kQb2Q==",
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.3.2.tgz",
|
||||
"integrity": "sha512-eZNEAai16nwyhIVIEaWQlaUgAU3S9CkQ58qvK0+3IuSdLJD3W1PNuehQFMIhW/mTP1oFR9GNoTcLg7gtXz6lzA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"glob": "^7.1.4",
|
||||
|
@ -572,9 +572,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"acorn": {
|
||||
"version": "7.0.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.0.0.tgz",
|
||||
"integrity": "sha512-PaF/MduxijYYt7unVGRuds1vBC9bFxbNf+VWqhOClfdgy7RlVkQqt610ig1/yxTgsDIfW1cWDel5EBbOy3jdtQ==",
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz",
|
||||
"integrity": "sha512-kL5CuoXA/dgxlBbVrflsflzQ3PAas7RYZB52NOm/6839iVYJgKMJ3cQJD+t2i5+qFa8h3MDpEOJiS64E8JLnSQ==",
|
||||
"dev": true
|
||||
},
|
||||
"acorn-globals": {
|
||||
|
@ -1199,9 +1199,9 @@
|
|||
}
|
||||
},
|
||||
"commander": {
|
||||
"version": "2.20.0",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz",
|
||||
"integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==",
|
||||
"version": "2.20.1",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.1.tgz",
|
||||
"integrity": "sha512-cCuLsMhJeWQ/ZpsFTbE765kvVfoeSddc4nU3up4fV+fDBcfUXnbITJ+JzhkdjzOqhURjZgujxaioam4RM9yGUg==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
|
@ -1564,9 +1564,9 @@
|
|||
}
|
||||
},
|
||||
"eslint": {
|
||||
"version": "6.3.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-6.3.0.tgz",
|
||||
"integrity": "sha512-ZvZTKaqDue+N8Y9g0kp6UPZtS4FSY3qARxBs7p4f0H0iof381XHduqVerFWtK8DPtKmemqbqCFENWSQgPR/Gow==",
|
||||
"version": "6.5.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-6.5.1.tgz",
|
||||
"integrity": "sha512-32h99BoLYStT1iq1v2P9uwpyznQ4M2jRiFB6acitKz52Gqn+vPaMDUTB1bYi1WN4Nquj2w+t+bimYUG83DC55A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "^7.0.0",
|
||||
|
@ -2784,9 +2784,9 @@
|
|||
}
|
||||
},
|
||||
"glob-parent": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.0.0.tgz",
|
||||
"integrity": "sha512-Z2RwiujPRGluePM6j699ktJYxmPpJKCfpGA13jz2hmFZC7gKetzrWvg5KN3+OsIFmydGyZ1AVwERCq1w/ZZwRg==",
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.0.tgz",
|
||||
"integrity": "sha512-qjtRgnIVmOfnKUE3NJAQEdk+lKrxfw8t5ke7SXtfMTHcjsBfOfWXCQfdb30zfDoZQ2IRSIiidmjtbHZPZ++Ihw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-glob": "^4.0.1"
|
||||
|
@ -2817,9 +2817,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"handlebars": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.2.tgz",
|
||||
"integrity": "sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==",
|
||||
"version": "4.4.2",
|
||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.2.tgz",
|
||||
"integrity": "sha512-cIv17+GhL8pHHnRJzGu2wwcthL5sb8uDKBHvZ2Dtu5s1YNt0ljbzKbamnc+gr69y7bzwQiBdr5+hOpRd5pnOdg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"neo-async": "^2.6.0",
|
||||
|
@ -3976,6 +3976,12 @@
|
|||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.memoize": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz",
|
||||
"integrity": "sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=",
|
||||
"dev": true
|
||||
},
|
||||
"lodash.sortby": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
|
||||
|
@ -5694,15 +5700,16 @@
|
|||
"dev": true
|
||||
},
|
||||
"ts-jest": {
|
||||
"version": "24.0.2",
|
||||
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-24.0.2.tgz",
|
||||
"integrity": "sha512-h6ZCZiA1EQgjczxq+uGLXQlNgeg02WWJBbeT8j6nyIBRQdglqbvzDoHahTEIiS6Eor6x8mK6PfZ7brQ9Q6tzHw==",
|
||||
"version": "24.1.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-24.1.0.tgz",
|
||||
"integrity": "sha512-HEGfrIEAZKfu1pkaxB9au17b1d9b56YZSqz5eCVE8mX68+5reOvlM93xGOzzCREIov9mdH7JBG+s0UyNAqr0tQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"bs-logger": "0.x",
|
||||
"buffer-from": "1.x",
|
||||
"fast-json-stable-stringify": "2.x",
|
||||
"json5": "2.x",
|
||||
"lodash.memoize": "4.x",
|
||||
"make-error": "1.x",
|
||||
"mkdirp": "0.x",
|
||||
"resolve": "1.x",
|
||||
|
@ -5779,9 +5786,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.6.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.2.tgz",
|
||||
"integrity": "sha512-lmQ4L+J6mnu3xweP8+rOrUwzmN+MRAj7TgtJtDaXE5PMyX2kCrklhg3rvOsOIfNeAWMQWO2F1GPc1kMD2vLAfw==",
|
||||
"version": "3.6.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.6.3.tgz",
|
||||
"integrity": "sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw==",
|
||||
"dev": true
|
||||
},
|
||||
"uglify-js": {
|
||||
|
|
16
package.json
16
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "holidayapi",
|
||||
"version": "2.0.1",
|
||||
"version": "2.1.0",
|
||||
"description": "Official Node.js library for Holiday API",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
@ -26,19 +26,19 @@
|
|||
"devDependencies": {
|
||||
"@types/jest": "^24.0.18",
|
||||
"@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",
|
||||
"eslint-plugin-import": "^2.18.2",
|
||||
"eslint-plugin-jest": "^22.17.0",
|
||||
"jest": "^24.9.0",
|
||||
"nock": "^10.0.6",
|
||||
"ts-jest": "^24.0.2",
|
||||
"typescript": "^3.6.2"
|
||||
"ts-jest": "^24.1.0",
|
||||
"typescript": "^3.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-fetch": "^2.6.0"
|
||||
|
|
|
@ -8,24 +8,24 @@
|
|||
export type Endpoint = 'countries' | 'holidays' | 'languages';
|
||||
|
||||
export type Request = {
|
||||
key?: string,
|
||||
format?: 'csv' | 'json' | 'php' | 'tsv' | 'yaml' | 'xml',
|
||||
key?: string,
|
||||
pretty?: boolean,
|
||||
search?: string,
|
||||
};
|
||||
|
||||
export type Requests = Request | HolidaysRequest;
|
||||
|
||||
export type HolidaysRequest = Request & {
|
||||
country?: string,
|
||||
year?: number,
|
||||
day?: number,
|
||||
month?: number,
|
||||
language?: string,
|
||||
month?: number,
|
||||
previous?: boolean,
|
||||
public?: boolean,
|
||||
search?: string,
|
||||
subdivisions?: boolean,
|
||||
upcoming?: boolean,
|
||||
year?: number,
|
||||
};
|
||||
|
||||
export type Response = {
|
||||
|
|
|
@ -93,6 +93,47 @@ describe('holidayapi', () => {
|
|||
expect(await holidayapi.countries()).toStrictEqual(expectedResponse);
|
||||
});
|
||||
|
||||
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 () => {
|
||||
const expectedResponse = {
|
||||
status: 429,
|
||||
|
@ -165,6 +206,46 @@ describe('holidayapi', () => {
|
|||
})).toStrictEqual(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 () => {
|
||||
expect.assertions(1);
|
||||
|
||||
|
@ -268,6 +349,32 @@ describe('holidayapi', () => {
|
|||
expect(await holidayapi.languages()).toStrictEqual(expectedResponse);
|
||||
});
|
||||
|
||||
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 () => {
|
||||
const expectedResponse = {
|
||||
status: 429,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue