zero-deps-prayer-times
Version:
A lightweight, embeddable Islamic prayer times calculator based on date and coordinates, with zero external dependencies.
66 lines (63 loc) • 2.74 kB
text/typescript
type Prayer = "fajr" | "dhuhr" | "asr" | "maghrib" | "isha";
type Coordinates = {
longitude: number;
latitude: number;
};
type Options = {
convention?: Convention;
hanafiAsr?: boolean;
};
type FormattedTime = {
date: Date;
formatted12H: string;
formatted24H: string;
};
type PrayerTimes = {
fajr: FormattedTime;
dhuhr: FormattedTime;
asr: FormattedTime;
maghrib: FormattedTime;
isha: FormattedTime;
};
type ExtraInfo = {
sunrise: FormattedTime;
midnight: FormattedTime;
dayOfYear: number | string;
dayLength: string;
nextPrayer: {
name: Prayer;
remainingSeconds: number;
};
};
type PrayerTimesResult = {
data: {
prayers: PrayerTimes;
extras: ExtraInfo;
} | null;
error: Error | null;
};
type Convention = "Muslim World League" | "Islamic Society of North America (ISNA)" | "Egyptian General Authority of Survey" | "Umm al-Qura University, Makkah" | "University of Islamic Sciences, Karachi" | "Institute of Geophysics, University of Tehran" | "Shia Ithna Ashari, Leva Research Institute, Qum";
/**
* Calculates the Islamic prayer times for a given date and geographical location.
*
* This function computes the prayer times for Fajr, Dhuhr, Asr, Maghrib, and Isha,
* as well as additional information such as sunrise, midnight, and the day length.
* It also calculates the next prayer time based on the current date.
* The calculation is influenced by the provided coordinates (latitude and longitude),
* and optional settings for conventions (e.g., calculation methods) and Asr prayer calculation
* (using the Hanafi method).
*
* @param date - The date for which the prayer times should be calculated. It must be a valid Date object.
* @param coordinates - The geographical coordinates (longitude and latitude) of the location.
* @param options - Optional settings that may influence the calculation methods, such as:
* - `convention`: Specifies the convention for Fajr and Isha calculation.
* - `hanafiAsr`: If true, the Hanafi method for Asr prayer calculation will be used.
*
* @returns An object containing the prayer times (`prayers`), additional information (`extras`), and any errors encountered:
* - `data`: An object with `prayers` (formatted prayer times) and `extras` (sunrise, midnight, day length, and next prayer).
* - `error`: An error object if calculation fails, or null if no error occurred.
*
* @throws {Error} If the input date is invalid, coordinates are out of range, or the location is in an unsupported polar region.
*/
declare function getPrayerTimes(date: Date, coordinates: Coordinates, options: Options | undefined): PrayerTimesResult;
export { getPrayerTimes };