salat-first
Version:
Islamic prayer times calculation with special support for Moroccan methods and Maliki madhab
46 lines (45 loc) • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateInRange = validateInRange;
exports.validateLatitude = validateLatitude;
exports.validateLongitude = validateLongitude;
exports.validateDate = validateDate;
/**
* Validates that a number is within a specified range
* @param value The number to validate
* @param min The minimum allowed value
* @param max The maximum allowed value
* @param name The name of the parameter (for the error message)
* @throws Error if the value is outside the range
*/
function validateInRange(value, min, max, name) {
if (value < min || value > max) {
throw new Error(`${name} must be between ${min} and ${max}`);
}
}
/**
* Validates that a latitude value is valid
* @param latitude The latitude to validate
* @throws Error if the latitude is invalid
*/
function validateLatitude(latitude) {
validateInRange(latitude, -90, 90, "Latitude");
}
/**
* Validates that a longitude value is valid
* @param longitude The longitude to validate
* @throws Error if the longitude is invalid
*/
function validateLongitude(longitude) {
validateInRange(longitude, -180, 180, "Longitude");
}
/**
* Validates that a date is valid
* @param date The date to validate
* @throws Error if the date is invalid
*/
function validateDate(date) {
if (!(date instanceof Date) || isNaN(date.getTime())) {
throw new Error("Invalid date");
}
}