@apiverve/worldholidays 1.1.9 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +237 -185
- package/examples/basic.js +39 -0
- package/index.d.ts +42 -0
- package/index.js +48 -14
- package/package.json +10 -7
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025 APIVerve, and EvlarSoft LLC
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
World Holidays API
|
|
2
|
-
============
|
|
1
|
+
# World Holidays API
|
|
3
2
|
|
|
4
3
|
World Holidays is a simple tool for getting the holidays of the world. It returns the holidays of the world for each day of the year.
|
|
5
4
|
|
|
@@ -7,55 +6,63 @@ World Holidays is a simple tool for getting the holidays of the world. It return
|
|
|
7
6
|

|
|
8
7
|

|
|
9
8
|
|
|
10
|
-
This is a Javascript Wrapper for the [World Holidays API](https://apiverve.com/marketplace/
|
|
9
|
+
This is a Javascript Wrapper for the [World Holidays API](https://apiverve.com/marketplace/worldholidays)
|
|
11
10
|
|
|
12
11
|
---
|
|
13
12
|
|
|
14
13
|
## Installation
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
Using npm:
|
|
16
|
+
```shell
|
|
17
|
+
npm install @apiverve/worldholidays
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Using yarn:
|
|
21
|
+
```shell
|
|
22
|
+
yarn add @apiverve/worldholidays
|
|
23
|
+
```
|
|
16
24
|
|
|
17
25
|
---
|
|
18
26
|
|
|
19
27
|
## Configuration
|
|
20
28
|
|
|
21
|
-
Before using the
|
|
29
|
+
Before using the World Holidays API client, you have to setup your account and obtain your API Key.
|
|
22
30
|
You can get it by signing up at [https://apiverve.com](https://apiverve.com)
|
|
23
31
|
|
|
24
32
|
---
|
|
25
33
|
|
|
26
|
-
##
|
|
34
|
+
## Quick Start
|
|
27
35
|
|
|
28
|
-
|
|
36
|
+
[Get started with the Quick Start Guide](https://docs.apiverve.com/quickstart)
|
|
37
|
+
|
|
38
|
+
The World Holidays API documentation is found here: [https://docs.apiverve.com/ref/worldholidays](https://docs.apiverve.com/ref/worldholidays).
|
|
29
39
|
You can find parameters, example responses, and status codes documented here.
|
|
30
40
|
|
|
31
41
|
### Setup
|
|
32
42
|
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
api_key: [YOUR_API_KEY]
|
|
37
|
-
secure: true //(Optional, defaults to true)
|
|
43
|
+
```javascript
|
|
44
|
+
const worldholidaysAPI = require('@apiverve/worldholidays');
|
|
45
|
+
const api = new worldholidaysAPI({
|
|
46
|
+
api_key: '[YOUR_API_KEY]'
|
|
38
47
|
});
|
|
39
48
|
```
|
|
40
49
|
|
|
41
50
|
---
|
|
42
51
|
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
---
|
|
43
55
|
|
|
44
56
|
### Perform Request
|
|
45
|
-
Using the API client, you can perform requests to the API.
|
|
46
57
|
|
|
47
|
-
|
|
58
|
+
Using the API is simple. All you have to do is make a request. The API will return a response with the data you requested.
|
|
48
59
|
|
|
49
|
-
```
|
|
60
|
+
```javascript
|
|
50
61
|
var query = {
|
|
51
62
|
country: "US",
|
|
52
63
|
year: 2025
|
|
53
64
|
};
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
###### Simple Request (using Callback)
|
|
57
65
|
|
|
58
|
-
```
|
|
59
66
|
api.execute(query, function (error, data) {
|
|
60
67
|
if (error) {
|
|
61
68
|
return console.error(error);
|
|
@@ -65,173 +72,217 @@ api.execute(query, function (error, data) {
|
|
|
65
72
|
});
|
|
66
73
|
```
|
|
67
74
|
|
|
68
|
-
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
### Using Promises
|
|
78
|
+
|
|
79
|
+
You can also use promises to make requests. The API returns a promise that you can use to handle the response.
|
|
80
|
+
|
|
81
|
+
```javascript
|
|
82
|
+
var query = {
|
|
83
|
+
country: "US",
|
|
84
|
+
year: 2025
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
api.execute(query)
|
|
88
|
+
.then(data => {
|
|
89
|
+
console.log(data);
|
|
90
|
+
})
|
|
91
|
+
.catch(error => {
|
|
92
|
+
console.error(error);
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
### Using Async/Await
|
|
99
|
+
|
|
100
|
+
You can also use async/await to make requests. The API returns a promise that you can use to handle the response.
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
async function makeRequest() {
|
|
104
|
+
var query = {
|
|
105
|
+
country: "US",
|
|
106
|
+
year: 2025
|
|
107
|
+
};
|
|
69
108
|
|
|
109
|
+
try {
|
|
110
|
+
const data = await api.execute(query);
|
|
111
|
+
console.log(data);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error(error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
70
116
|
```
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
"
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
"
|
|
129
|
-
"
|
|
130
|
-
"
|
|
131
|
-
"
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
"
|
|
136
|
-
"
|
|
137
|
-
"
|
|
138
|
-
"
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
"
|
|
143
|
-
"
|
|
144
|
-
"
|
|
145
|
-
"
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
"
|
|
150
|
-
"
|
|
151
|
-
"
|
|
152
|
-
"
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
"
|
|
157
|
-
"
|
|
158
|
-
"
|
|
159
|
-
"
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
"
|
|
164
|
-
"
|
|
165
|
-
"
|
|
166
|
-
"
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
"
|
|
171
|
-
"
|
|
172
|
-
"
|
|
173
|
-
"
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
"
|
|
178
|
-
"
|
|
179
|
-
"
|
|
180
|
-
"
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
"
|
|
185
|
-
"
|
|
186
|
-
"
|
|
187
|
-
"
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
"
|
|
192
|
-
"
|
|
193
|
-
"
|
|
194
|
-
"
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
"
|
|
199
|
-
"
|
|
200
|
-
"
|
|
201
|
-
"
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
"
|
|
206
|
-
"
|
|
207
|
-
"
|
|
208
|
-
"
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
"
|
|
213
|
-
"
|
|
214
|
-
"
|
|
215
|
-
"
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
"
|
|
220
|
-
"
|
|
221
|
-
"
|
|
222
|
-
"
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
"
|
|
227
|
-
"
|
|
228
|
-
"
|
|
229
|
-
"
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Example Response
|
|
121
|
+
|
|
122
|
+
```json
|
|
123
|
+
{
|
|
124
|
+
"status": "ok",
|
|
125
|
+
"error": null,
|
|
126
|
+
"data": {
|
|
127
|
+
"country": "US",
|
|
128
|
+
"year": "2025",
|
|
129
|
+
"holidays": [
|
|
130
|
+
{
|
|
131
|
+
"date": "2025-01-01 00:00:00",
|
|
132
|
+
"start": "2025-01-01T05:00:00Z",
|
|
133
|
+
"end": "2025-01-02T05:00:00Z",
|
|
134
|
+
"name": "New Year's Day",
|
|
135
|
+
"type": "public"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"date": "2025-01-20 00:00:00",
|
|
139
|
+
"start": "2025-01-20T05:00:00Z",
|
|
140
|
+
"end": "2025-01-21T05:00:00Z",
|
|
141
|
+
"name": "Martin Luther King Jr. Day",
|
|
142
|
+
"type": "public"
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"date": "2025-02-14 00:00:00",
|
|
146
|
+
"start": "2025-02-14T05:00:00Z",
|
|
147
|
+
"end": "2025-02-15T05:00:00Z",
|
|
148
|
+
"name": "Valentine's Day",
|
|
149
|
+
"type": "observance"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
"date": "2025-02-17 00:00:00",
|
|
153
|
+
"start": "2025-02-17T05:00:00Z",
|
|
154
|
+
"end": "2025-02-18T05:00:00Z",
|
|
155
|
+
"name": "Washington's Birthday",
|
|
156
|
+
"type": "public"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"date": "2025-03-17 00:00:00",
|
|
160
|
+
"start": "2025-03-17T04:00:00Z",
|
|
161
|
+
"end": "2025-03-18T04:00:00Z",
|
|
162
|
+
"name": "St. Patrick's Day",
|
|
163
|
+
"type": "observance"
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
"date": "2025-04-15 00:00:00",
|
|
167
|
+
"start": "2025-04-15T04:00:00Z",
|
|
168
|
+
"end": "2025-04-16T04:00:00Z",
|
|
169
|
+
"name": "Tax Day",
|
|
170
|
+
"type": "observance"
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"date": "2025-04-20 00:00:00",
|
|
174
|
+
"start": "2025-04-20T04:00:00Z",
|
|
175
|
+
"end": "2025-04-21T04:00:00Z",
|
|
176
|
+
"name": "Easter Sunday",
|
|
177
|
+
"type": "observance"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"date": "2025-04-23 00:00:00",
|
|
181
|
+
"start": "2025-04-23T04:00:00Z",
|
|
182
|
+
"end": "2025-04-24T04:00:00Z",
|
|
183
|
+
"name": "Administrative Professionals Day",
|
|
184
|
+
"type": "observance"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"date": "2025-05-11 00:00:00",
|
|
188
|
+
"start": "2025-05-11T04:00:00Z",
|
|
189
|
+
"end": "2025-05-12T04:00:00Z",
|
|
190
|
+
"name": "Mother's Day",
|
|
191
|
+
"type": "observance"
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
"date": "2025-05-26 00:00:00",
|
|
195
|
+
"start": "2025-05-26T04:00:00Z",
|
|
196
|
+
"end": "2025-05-27T04:00:00Z",
|
|
197
|
+
"name": "Memorial Day",
|
|
198
|
+
"type": "public"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"date": "2025-06-15 00:00:00",
|
|
202
|
+
"start": "2025-06-15T04:00:00Z",
|
|
203
|
+
"end": "2025-06-16T04:00:00Z",
|
|
204
|
+
"name": "Father's Day",
|
|
205
|
+
"type": "observance"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"date": "2025-06-19 00:00:00",
|
|
209
|
+
"start": "2025-06-19T04:00:00Z",
|
|
210
|
+
"end": "2025-06-20T04:00:00Z",
|
|
211
|
+
"name": "Juneteenth",
|
|
212
|
+
"type": "public"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"date": "2025-07-04 00:00:00",
|
|
216
|
+
"start": "2025-07-04T04:00:00Z",
|
|
217
|
+
"end": "2025-07-05T04:00:00Z",
|
|
218
|
+
"name": "Independence Day",
|
|
219
|
+
"type": "public"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"date": "2025-09-01 00:00:00",
|
|
223
|
+
"start": "2025-09-01T04:00:00Z",
|
|
224
|
+
"end": "2025-09-02T04:00:00Z",
|
|
225
|
+
"name": "Labor Day",
|
|
226
|
+
"type": "public"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"date": "2025-10-13 00:00:00",
|
|
230
|
+
"start": "2025-10-13T04:00:00Z",
|
|
231
|
+
"end": "2025-10-14T04:00:00Z",
|
|
232
|
+
"name": "Columbus Day",
|
|
233
|
+
"type": "public"
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"date": "2025-10-31 18:00:00",
|
|
237
|
+
"start": "2025-10-31T22:00:00Z",
|
|
238
|
+
"end": "2025-11-01T04:00:00Z",
|
|
239
|
+
"name": "Halloween",
|
|
240
|
+
"type": "observance"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"date": "2025-11-11 00:00:00",
|
|
244
|
+
"start": "2025-11-11T05:00:00Z",
|
|
245
|
+
"end": "2025-11-12T05:00:00Z",
|
|
246
|
+
"name": "Veterans Day",
|
|
247
|
+
"type": "public"
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"date": "2025-11-27 00:00:00",
|
|
251
|
+
"start": "2025-11-27T05:00:00Z",
|
|
252
|
+
"end": "2025-11-28T05:00:00Z",
|
|
253
|
+
"name": "Thanksgiving Day",
|
|
254
|
+
"type": "public"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"date": "2025-11-28 00:00:00",
|
|
258
|
+
"start": "2025-11-28T05:00:00Z",
|
|
259
|
+
"end": "2025-11-29T05:00:00Z",
|
|
260
|
+
"name": "Day after Thanksgiving Day",
|
|
261
|
+
"type": "observance"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
"date": "2025-12-24 00:00:00",
|
|
265
|
+
"start": "2025-12-24T05:00:00Z",
|
|
266
|
+
"end": "2025-12-25T05:00:00Z",
|
|
267
|
+
"name": "Christmas Eve",
|
|
268
|
+
"type": "optional"
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
"date": "2025-12-25 00:00:00",
|
|
272
|
+
"start": "2025-12-25T05:00:00Z",
|
|
273
|
+
"end": "2025-12-26T05:00:00Z",
|
|
274
|
+
"name": "Christmas Day",
|
|
275
|
+
"type": "public"
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
"date": "2025-12-31 00:00:00",
|
|
279
|
+
"start": "2025-12-31T05:00:00Z",
|
|
280
|
+
"end": "2026-01-01T05:00:00Z",
|
|
281
|
+
"name": "New Year's Eve",
|
|
282
|
+
"type": "observance"
|
|
283
|
+
}
|
|
284
|
+
]
|
|
285
|
+
}
|
|
235
286
|
}
|
|
236
287
|
```
|
|
237
288
|
|
|
@@ -244,6 +295,7 @@ Need any assistance? [Get in touch with Customer Support](https://apiverve.com/c
|
|
|
244
295
|
---
|
|
245
296
|
|
|
246
297
|
## Updates
|
|
298
|
+
|
|
247
299
|
Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
|
|
248
300
|
|
|
249
301
|
---
|
|
@@ -263,4 +315,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
263
315
|
|
|
264
316
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
265
317
|
|
|
266
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
318
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Basic Example - World Holidays API
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to use the World Holidays API.
|
|
5
|
+
* Make sure to set your API key in the .env file or replace '[YOUR_API_KEY]' below.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
require('dotenv').config();
|
|
9
|
+
const worldholidaysAPI = require('../index.js');
|
|
10
|
+
|
|
11
|
+
// Initialize the API client
|
|
12
|
+
const api = new worldholidaysAPI({
|
|
13
|
+
api_key: process.env.API_KEY || '[YOUR_API_KEY]'
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// Example query
|
|
17
|
+
var query = {
|
|
18
|
+
country: "US",
|
|
19
|
+
year: 2025
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Make the API request using callback
|
|
23
|
+
console.log('Making request to World Holidays API...\n');
|
|
24
|
+
|
|
25
|
+
api.execute(query, function (error, data) {
|
|
26
|
+
if (error) {
|
|
27
|
+
console.error('Error occurred:');
|
|
28
|
+
if (error.error) {
|
|
29
|
+
console.error('Message:', error.error);
|
|
30
|
+
console.error('Status:', error.status);
|
|
31
|
+
} else {
|
|
32
|
+
console.error(JSON.stringify(error, null, 2));
|
|
33
|
+
}
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log('Response:');
|
|
38
|
+
console.log(JSON.stringify(data, null, 2));
|
|
39
|
+
});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module '@apiverve/worldholidays' {
|
|
2
|
+
export interface worldholidaysOptions {
|
|
3
|
+
api_key: string;
|
|
4
|
+
secure?: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface worldholidaysResponse {
|
|
8
|
+
status: string;
|
|
9
|
+
error: string | null;
|
|
10
|
+
data: WorldHolidaysData;
|
|
11
|
+
code?: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
interface WorldHolidaysData {
|
|
16
|
+
country: string;
|
|
17
|
+
year: string;
|
|
18
|
+
holidays: Holiday[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Holiday {
|
|
22
|
+
date: Date;
|
|
23
|
+
start: Date;
|
|
24
|
+
end: Date;
|
|
25
|
+
name: string;
|
|
26
|
+
type: Type;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
enum Type {
|
|
30
|
+
Observance = "observance",
|
|
31
|
+
Optional = "optional",
|
|
32
|
+
Public = "public",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default class worldholidaysWrapper {
|
|
36
|
+
constructor(options: worldholidaysOptions);
|
|
37
|
+
|
|
38
|
+
execute(callback: (error: any, data: worldholidaysResponse | null) => void): Promise<worldholidaysResponse>;
|
|
39
|
+
execute(query: Record<string, any>, callback: (error: any, data: worldholidaysResponse | null) => void): Promise<worldholidaysResponse>;
|
|
40
|
+
execute(query?: Record<string, any>): Promise<worldholidaysResponse>;
|
|
41
|
+
}
|
|
42
|
+
}
|
package/index.js
CHANGED
|
@@ -4,14 +4,27 @@ class worldholidaysWrapper {
|
|
|
4
4
|
|
|
5
5
|
constructor(options) {
|
|
6
6
|
if (!options || typeof options !== 'object') {
|
|
7
|
-
throw new Error('Options object must be provided.');
|
|
7
|
+
throw new Error('Options object must be provided. See documentation: https://docs.apiverve.com/ref/worldholidays');
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
const { api_key, secure = true } = options;
|
|
11
11
|
|
|
12
12
|
if (!api_key || typeof api_key !== 'string') {
|
|
13
|
-
throw new Error('API key must be provided as a non-empty string.');
|
|
13
|
+
throw new Error('API key must be provided as a non-empty string. Get your API key at: https://apiverve.com');
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
// Validate API key format (GUID or alphanumeric with hyphens)
|
|
17
|
+
const apiKeyPattern = /^[a-zA-Z0-9-]+$/;
|
|
18
|
+
if (!apiKeyPattern.test(api_key)) {
|
|
19
|
+
throw new Error('Invalid API key format. API key must be alphanumeric and may contain hyphens. Get your API key at: https://apiverve.com');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Check minimum length (GUIDs are typically 36 chars with hyphens, or 32 without)
|
|
23
|
+
const trimmedKey = api_key.replace(/-/g, '');
|
|
24
|
+
if (trimmedKey.length < 32) {
|
|
25
|
+
throw new Error('Invalid API key. API key appears to be too short. Get your API key at: https://apiverve.com');
|
|
26
|
+
}
|
|
27
|
+
|
|
15
28
|
if (typeof secure !== 'boolean') {
|
|
16
29
|
throw new Error('Secure parameter must be a boolean value.');
|
|
17
30
|
}
|
|
@@ -24,20 +37,32 @@ class worldholidaysWrapper {
|
|
|
24
37
|
}
|
|
25
38
|
|
|
26
39
|
async execute(query, callback) {
|
|
27
|
-
|
|
40
|
+
// Handle different argument patterns
|
|
41
|
+
if(arguments.length === 0) {
|
|
42
|
+
// execute() - no args
|
|
43
|
+
query = {};
|
|
44
|
+
callback = null;
|
|
45
|
+
} else if(arguments.length === 1) {
|
|
46
|
+
if (typeof query === 'function') {
|
|
47
|
+
// execute(callback)
|
|
48
|
+
callback = query;
|
|
49
|
+
query = {};
|
|
50
|
+
} else {
|
|
51
|
+
// execute(query)
|
|
52
|
+
callback = null;
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
// execute(query, callback)
|
|
28
56
|
if (!query || typeof query !== 'object') {
|
|
29
57
|
throw new Error('Query parameters must be provided as an object.');
|
|
30
58
|
}
|
|
31
|
-
} else {
|
|
32
|
-
callback = query;
|
|
33
|
-
query = {};
|
|
34
59
|
}
|
|
35
60
|
|
|
36
61
|
var requiredParams = ["country"];
|
|
37
62
|
if (requiredParams.length > 0) {
|
|
38
63
|
for (var i = 0; i < requiredParams.length; i++) {
|
|
39
64
|
if (!query[requiredParams[i]]) {
|
|
40
|
-
throw new Error(`Required parameter [${requiredParams[i]}] is missing
|
|
65
|
+
throw new Error(`Required parameter [${requiredParams[i]}] is missing. See documentation: https://docs.apiverve.com/ref/worldholidays`);
|
|
41
66
|
}
|
|
42
67
|
}
|
|
43
68
|
}
|
|
@@ -58,16 +83,25 @@ class worldholidaysWrapper {
|
|
|
58
83
|
});
|
|
59
84
|
|
|
60
85
|
const data = response.data;
|
|
61
|
-
callback(null, data);
|
|
86
|
+
if (callback) callback(null, data);
|
|
62
87
|
return data;
|
|
63
88
|
} catch (error) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
89
|
+
let apiError;
|
|
90
|
+
|
|
91
|
+
if (error.response && error.response.data) {
|
|
92
|
+
apiError = error.response.data;
|
|
93
|
+
} else if (error.message) {
|
|
94
|
+
apiError = { error: error.message, status: 'error' };
|
|
67
95
|
} else {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
96
|
+
apiError = { error: 'An unknown error occurred', status: 'error' };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (callback) {
|
|
100
|
+
callback(apiError, null);
|
|
101
|
+
return; // Don't throw if callback is provided
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
throw apiError;
|
|
71
105
|
}
|
|
72
106
|
}
|
|
73
107
|
|
package/package.json
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apiverve/worldholidays",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.12",
|
|
4
4
|
"description": "World Holidays is a simple tool for getting the holidays of the world. It returns the holidays of the world for each day of the year.",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"test": "mocha"
|
|
8
|
+
"test": "mocha",
|
|
9
|
+
"example": "node examples/basic.js"
|
|
8
10
|
},
|
|
9
11
|
"repository": {
|
|
10
12
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/apiverve/worldholidays-
|
|
13
|
+
"url": "git+https://github.com/apiverve/worldholidays-api.git",
|
|
14
|
+
"directory": "npm"
|
|
12
15
|
},
|
|
13
16
|
"keywords": [
|
|
14
|
-
"world holidays","world holidays api","world holidays tool","world holidays software","world holidays service"
|
|
17
|
+
"world holidays", "world holidays api", "world holidays tool", "world holidays software", "world holidays service"
|
|
15
18
|
],
|
|
16
19
|
"author": "APIVerve <hello@apiverve.com> (http://apiverve.com/)",
|
|
17
20
|
"license": "MIT",
|
|
18
21
|
"bugs": {
|
|
19
|
-
"url": "https://github.com/apiverve/worldholidays-
|
|
22
|
+
"url": "https://github.com/apiverve/worldholidays-api/issues"
|
|
20
23
|
},
|
|
21
|
-
"homepage": "https://apiverve.com/marketplace/
|
|
24
|
+
"homepage": "https://apiverve.com/marketplace/worldholidays?utm_source=npm",
|
|
22
25
|
"devDependencies": {
|
|
23
26
|
"mocha": "^11.0.1",
|
|
24
27
|
"chai": "^5.1.2",
|
|
@@ -27,6 +30,6 @@
|
|
|
27
30
|
"dependencies": {
|
|
28
31
|
"node-fetch": "^3.3.2",
|
|
29
32
|
"promise": "^8.3.0",
|
|
30
|
-
"axios": "1.
|
|
33
|
+
"axios": "1.13.2"
|
|
31
34
|
}
|
|
32
35
|
}
|