From 59759e5864e363c95fbb3f24e29319dc4bff9857 Mon Sep 17 00:00:00 2001 From: gimy Date: Fri, 27 Oct 2023 08:47:25 +0800 Subject: [PATCH] fix: added config validation --- src/Base.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Base.ts b/src/Base.ts index c712c26..71b725e 100644 --- a/src/Base.ts +++ b/src/Base.ts @@ -31,9 +31,23 @@ export class BaseCalculator { this._prayerConfig = config const { date, latitude, longitude, method, ...paramsOptions } = this._prayerConfig + if (date.toString() === 'Invalid Date') { + throw new Error('You must provide a valid date') + } + + if (latitude < -90 || latitude > 90) { + throw new Error('Latitude must be between -90 and 90') + } else if (longitude < -180 || longitude > 180) { + throw new Error('Longitude must be between -180 and 180') + } else if (latitude === undefined && longitude === undefined) { + throw new Error('You must provide a valid latitude and longitude') + } // create a coordinate object const coordinates = new Coordinates(latitude, longitude) + if (method === undefined) { + this._logger.warn('No calculation method provided, using Umm Al Qura as default') + } // create calculation params based on the method name const calculationParams = this._useMethod(method)