From 36a2eb2006634d8048d3a91e5ba42421dd29dfbf Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Tue, 13 Dec 2022 22:47:40 -0600 Subject: [PATCH] Version bump and cleanup. --- README.md | 12 +++-- example/index.ts | 10 ++-- example/package.json | 2 +- package-lock.json | 28 +++++------ package.json | 2 +- src/{holidayapi.ts => holidays.ts} | 8 +-- src/index.ts | 2 +- src/types.ts | 2 +- test/{holidayapi.test.ts => holidays.test.ts} | 50 +++++++++---------- 9 files changed, 61 insertions(+), 55 deletions(-) rename src/{holidayapi.ts => holidays.ts} (96%) rename test/{holidayapi.test.ts => holidays.test.ts} (85%) diff --git a/README.md b/README.md index 0720e7e..5a6b6c2 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,21 @@ Industry-leading Holiday and Event API for JavaScript/TypeScript. Over 5,000 hol # Authentication Access to the Holiday and Event API requires an API Key. You can get for one for FREE [here](https://apilayer.com/marketplace/checkiday-api#pricing), no credit card required! Note that free plans are limited. To access more data and have more requests, a paid plan is required. +# Installation + +```terminal +$ npm install --save holiday-event-api +``` + # Example Usage ## Authentication -Simply construct an instance of `HolidayApi` and pass your API Key like this: +Simply construct an instance of `Holidays` and pass your API Key like this: ```ts -import { HolidayApi } from 'holiday-event-api'; +import { Holidays } from 'holiday-event-api'; // Get a FREE API key from https://apilayer.com/marketplace/checkiday-api#pricing -const api = new HolidayApi({ apiKey: '' }); +const api = new Holidays({ apiKey: '' }); ``` ## Example Project diff --git a/example/index.ts b/example/index.ts index 850b34e..2b21aa6 100644 --- a/example/index.ts +++ b/example/index.ts @@ -1,12 +1,12 @@ -import { HolidayApi } from 'holiday-event-api'; +import { Holidays } from 'holiday-event-api'; // Get a FREE API key from https://apilayer.com/marketplace/checkiday-api#pricing -const holidayApi = new HolidayApi({ apiKey: '' }); +const holidays = new Holidays({ apiKey: '' }); (async () => { try { // Get Events for a given Date - const result = await holidayApi.getEvents({ + const result = await holidays.getEvents({ // These parameters are the defaults but can be specified: // date: 'today', // timezone: 'America/Chicago', @@ -17,7 +17,7 @@ const holidayApi = new HolidayApi({ apiKey: '' }); console.log(`Rate limits remaining: ${result.rateLimit.remainingMonth}/${result.rateLimit.limitMonth} (month).`); // Get Event Information - const eventInfo = await holidayApi.getEventInfo({ + const eventInfo = await holidays.getEventInfo({ id: event.id, // These parameters can be specified to calculate the range of eventInfo.Event.Occurrences //start: 2020, @@ -28,7 +28,7 @@ const holidayApi = new HolidayApi({ apiKey: '' }); // Search for Events const query = 'pizza day'; - const search = await holidayApi.search({ + const search = await holidays.search({ query: query, // These parameters are the defaults but can be specified: // adult: false, diff --git a/example/package.json b/example/package.json index 8c132a9..a32f018 100644 --- a/example/package.json +++ b/example/package.json @@ -8,7 +8,7 @@ "build": "tsc" }, "dependencies": { - "holiday-event-api": "^0.0.3" + "holiday-event-api": "^1.0.0" }, "devDependencies": { "typescript": "^4.7.4" diff --git a/package-lock.json b/package-lock.json index 4b3eb09..7a57d4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "holiday-event-api", - "version": "0.0.3", + "version": "1.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "holiday-event-api", - "version": "0.0.3", + "version": "1.0.0", "license": "MIT", "dependencies": { "node-fetch": "^2.6.7" @@ -1068,9 +1068,9 @@ } }, "node_modules/@types/node": { - "version": "18.11.13", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.13.tgz", - "integrity": "sha512-IASpMGVcWpUsx5xBOrxMj7Bl8lqfuTY7FKAnPmu5cHkfQVWF8GulWS1jbRqA934qZL35xh5xN/+Xe/i26Bod4w==", + "version": "18.11.15", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.15.tgz", + "integrity": "sha512-VkhBbVo2+2oozlkdHXLrb3zjsRkpdnaU2bXmX8Wgle3PUi569eLRaHGlgETQHR7lLL1w7GiG3h9SnePhxNDecw==", "dev": true }, "node_modules/@types/node-fetch": { @@ -2877,9 +2877,9 @@ "dev": true }, "node_modules/node-releases": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.6.tgz", - "integrity": "sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==", + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.7.tgz", + "integrity": "sha512-EJ3rzxL9pTWPjk5arA0s0dgXpnyiAbJDE6wHT62g7VsgrgQgmmZ+Ru++M1BFofncWja+Pnn3rEr3fieRySAdKQ==", "dev": true }, "node_modules/normalize-path": { @@ -4516,9 +4516,9 @@ } }, "@types/node": { - "version": "18.11.13", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.13.tgz", - "integrity": "sha512-IASpMGVcWpUsx5xBOrxMj7Bl8lqfuTY7FKAnPmu5cHkfQVWF8GulWS1jbRqA934qZL35xh5xN/+Xe/i26Bod4w==", + "version": "18.11.15", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.15.tgz", + "integrity": "sha512-VkhBbVo2+2oozlkdHXLrb3zjsRkpdnaU2bXmX8Wgle3PUi569eLRaHGlgETQHR7lLL1w7GiG3h9SnePhxNDecw==", "dev": true }, "@types/node-fetch": { @@ -5880,9 +5880,9 @@ "dev": true }, "node-releases": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.6.tgz", - "integrity": "sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==", + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.7.tgz", + "integrity": "sha512-EJ3rzxL9pTWPjk5arA0s0dgXpnyiAbJDE6wHT62g7VsgrgQgmmZ+Ru++M1BFofncWja+Pnn3rEr3fieRySAdKQ==", "dev": true }, "normalize-path": { diff --git a/package.json b/package.json index 1dd63bb..4a68517 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "holiday-event-api", - "version": "0.0.3", + "version": "1.0.0", "description": "Industry-leading holiday and event API for Node.js.", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/src/holidayapi.ts b/src/holidays.ts similarity index 96% rename from src/holidayapi.ts rename to src/holidays.ts index 2b515a6..2014084 100644 --- a/src/holidayapi.ts +++ b/src/holidays.ts @@ -6,18 +6,18 @@ import { GetEventInfoResponse, GetEventsRequest, GetEventsResponse, - HolidayApiConfig, + HolidaysConfig, SearchRequest, SearchResponse, } from './types'; -export class HolidayApi { +export class Holidays { private apiKey: string; - private version: string = '0.0.3'; + private version: string = '1.0.0'; private baseUrl: string = 'https://api.apilayer.com/checkiday/'; private userAgent: string = 'HolidayApiJs/' + this.version; - constructor(config: HolidayApiConfig) { + constructor(config: HolidaysConfig) { if (!config?.apiKey || config.apiKey.length == 0) { throw new Error('Please provide a valid API key. Get one at https://apilayer.com/marketplace/checkiday-api#pricing.'); } diff --git a/src/index.ts b/src/index.ts index cdc94cc..7807760 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,2 @@ -export * from './holidayapi'; +export * from './holidays'; export * from './types'; diff --git a/src/types.ts b/src/types.ts index cae9f68..b1e394a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,7 +1,7 @@ /** * Data needed to create a new API client. */ -export type HolidayApiConfig = { +export type HolidaysConfig = { /** * Your API Key. * Get a FREE API key from https://apilayer.com/marketplace/checkiday-api#pricing diff --git a/test/holidayapi.test.ts b/test/holidays.test.ts similarity index 85% rename from test/holidayapi.test.ts rename to test/holidays.test.ts index ae5deb0..a14b2c1 100644 --- a/test/holidayapi.test.ts +++ b/test/holidays.test.ts @@ -1,5 +1,5 @@ import * as nock from 'nock'; -import { HolidayApi } from '../src/holidayapi'; +import { Holidays } from '../src/holidays'; import { RateLimit } from '../src/types'; const PACKAGE_VERSION = require('../package.json').version; @@ -11,16 +11,16 @@ afterEach(() => { describe('constructor tests', () => { test('works with a proper-looking configuration', () => { - expect(new HolidayApi({ apiKey: 'abc123' })).toBeInstanceOf(HolidayApi); + expect(new Holidays({ apiKey: 'abc123' })).toBeInstanceOf(Holidays); }); test('requires a configuration', () => { - expect(() => new HolidayApi(null as any)).toThrowError('Please provide a valid API key.'); + expect(() => new Holidays(null as any)).toThrowError('Please provide a valid API key.'); }); test('requires a proper-looking API key', () => { - expect(() => new HolidayApi({} as any)).toThrowError('Please provide a valid API key.'); - expect(() => new HolidayApi({apiKey: ''})).toThrowError('Please provide a valid API key.'); + expect(() => new Holidays({} as any)).toThrowError('Please provide a valid API key.'); + expect(() => new Holidays({apiKey: ''})).toThrowError('Please provide a valid API key.'); }); }); @@ -33,7 +33,7 @@ describe('common functionality tests', () => { }).get('/events') .reply(200, {}); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); await api.getEvents(); }); @@ -45,7 +45,7 @@ describe('common functionality tests', () => { }).get('/events') .reply(200, {}); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); await api.getEvents(); }); @@ -54,7 +54,7 @@ describe('common functionality tests', () => { .get('/events') .reply(401, { error: 'MyError!' }); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); expect(api.getEvents()).rejects.toThrowError('MyError!'); }); @@ -63,7 +63,7 @@ describe('common functionality tests', () => { .get('/events') .reply(500); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); expect(api.getEvents()).rejects.toThrowError('Internal Server Error'); }); @@ -72,7 +72,7 @@ describe('common functionality tests', () => { .get('/events') .reply(599); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); expect(api.getEvents()).rejects.toThrowError('599'); }); @@ -81,7 +81,7 @@ describe('common functionality tests', () => { .get('/events') .reply(200, ''); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); expect(api.getEvents()).rejects.toThrowError('Unable to parse response.'); }); @@ -94,7 +94,7 @@ describe('common functionality tests', () => { .get('/redirected') .reply(200, {}); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); await api.getEvents(); }); @@ -106,7 +106,7 @@ describe('common functionality tests', () => { 'x-ratelimit-remaining-month': '88', }); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); const response = await api.getEvents(); expect(response.rateLimit).toEqual({ limitMonth: 100, @@ -121,7 +121,7 @@ describe('getEvents', () => { .get('/events') .replyWithFile(200, 'test/responses/getEvents-default.json'); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); const response = await api.getEvents(); expect(response.adult).toBe(false); expect(response.timezone).toBe('America/Chicago'); @@ -145,7 +145,7 @@ describe('getEvents', () => { }) .replyWithFile(200, 'test/responses/getEvents-parameters.json'); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); const response = await api.getEvents({ adult: true, timezone: 'America/New_York', @@ -173,7 +173,7 @@ describe('getEventInfo', () => { }) .replyWithFile(200, 'test/responses/getEventInfo.json'); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); const response = await api.getEventInfo({ id: 'f90b893ea04939d7456f30c54f68d7b4', }); @@ -191,7 +191,7 @@ describe('getEventInfo', () => { }) .replyWithFile(200, 'test/responses/getEventInfo-parameters.json'); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); const response = await api.getEventInfo({ id: 'f90b893ea04939d7456f30c54f68d7b4', start: 2002, @@ -212,17 +212,17 @@ describe('getEventInfo', () => { }) .reply(404, { error: 'Event not found.' }); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); expect(api.getEventInfo({ id: 'hi' })).rejects.toThrowError('Event not found.'); }); test('missing id', async () => { - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); expect(api.getEventInfo({} as any)).rejects.toThrowError('Event id is required.'); }); test('missing parameters', async () => { - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); expect(api.getEventInfo(undefined as any)).rejects.toThrowError('Event id is required.'); }); }); @@ -236,7 +236,7 @@ describe('search', () => { }) .replyWithFile(200, 'test/responses/search-default.json'); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); const response = await api.search({ query: 'zucchini', }); @@ -259,7 +259,7 @@ describe('search', () => { }) .replyWithFile(200, 'test/responses/search-parameters.json'); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); const response = await api.search({ adult: true, query: 'porch day', @@ -282,7 +282,7 @@ describe('search', () => { }) .reply(400, { error: 'Please enter a longer search term.' }); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); expect(api.search({ query: 'a' })).rejects.toThrowError('Please enter a longer search term.'); }); @@ -294,12 +294,12 @@ describe('search', () => { }) .reply(400, { error: 'Too many results returned. Please refine your query.' }); - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); expect(api.search({ query: 'day' })).rejects.toThrowError('Too many results returned. Please refine your query.'); }); test('missing parameters', async () => { - const api = new HolidayApi({ apiKey: 'abc123' }); + const api = new Holidays({ apiKey: 'abc123' }); expect(api.search(undefined as any)).rejects.toThrowError('Search query is required.'); }); });