Skip to content

Commit

Permalink
fix: added config validation
Browse files Browse the repository at this point in the history
  • Loading branch information
khawarizmus committed Oct 27, 2023
1 parent 6f4ba11 commit 59759e5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 59759e5

Please sign in to comment.