salah-calculator
v1.0.0
Published
Pure TypeScript Islamic prayer times calculation library. Part of Adwatak (https://adwatak.cloud).
Maintainers
Readme
islamic-prayer-times
Pure TypeScript library for calculating Islamic prayer times. Part of Adwatak.
🌐 Live Demo
Try the interactive version at adwatak.cloud/tools/prayer-times
Installation
npm install islamic-prayer-timesQuick Start
import { calcPrayerTimes, getNextPrayer, METHODS, CITIES, CITIES_BY_COUNTRY } from 'islamic-prayer-times';
// Calculate for a specific city
const riyadh = CITIES.find(c => c.name === 'Riyadh')!;
const today = new Date();
const times = calcPrayerTimes(
riyadh.lat, // 24.7136
riyadh.lng, // 46.6753
riyadh.tz, // 3 (UTC+3)
'1', // Umm al-Qra (Saudi)
today
);
console.log(times);
// { fajr: '04:12', sunrise: '05:36', dhuhr: '12:04', asr: '15:28', maghrib: '18:32', isha: '20:02' }
// Find the next upcoming prayer
const next = getNextPrayer(times, new Date());
console.log(next);
// { name: 'Dhuhr', nameAr: 'الظهر', time: '12:04', diff: 45 }API
calcPrayerTimes(lat, lng, tz, methodId, date)
Calculates the six daily prayer times for a given location and date.
| Param | Type | Description |
|------------|----------|--------------------------------------|
| lat | number | Latitude in degrees |
| lng | number | Longitude in degrees |
| tz | number | UTC offset in hours (e.g. 3 for +3) |
| methodId | string | Calculation method key (see METHODS) |
| date | Date | The target date |
Returns PrayerTimes:
{
fajr: string; // "HH:MM"
sunrise: string;
dhuhr: string;
asr: string;
maghrib: string;
isha: string;
}getNextPrayer(times, now)
Finds the next prayer that hasn't started yet.
| Param | Type | Description |
|--------|--------------|---------------------------|
| times | PrayerTimes | The day's prayer times |
| now | Date | Current date/time |
Returns NextPrayer | null:
{
name: string; // "Fajr"
nameAr: string; // "الفجر"
time: string; // "HH:MM"
diff: number; // minutes until prayer
}METHODS
A record of 8 calculation methods:
| Key | Name | Fajr Angle | Isha Angle | Isha Offset |
|-----|--------------------------|------------|------------|-------------|
| 1 | Umm al-Qura (Saudi) | 18.5° | — | 90 min |
| 2 | Egyptian Authority | 19.5° | 17.5° | — |
| 3 | Muslim World League | 18° | 17° | — |
| 4 | Karachi University | 18° | 18° | — |
| 5 | ISNA (North America) | 15° | 15° | — |
| 6 | Kuwait | 18° | 17.5° | — |
| 7 | Qatar | 18° | — | 90 min |
| 8 | Singapore | 20° | 18° | — |
Each entry includes ar, en, and tr (Arabic, English, Turkish) display names, plus fajrAngle, ishaAngle, and optional ishaOffset.
CITIES
An array of 80+ cities, each with:
{
name: string; // "Makkah"
nameAr: string; // "مكة المكرمة"
lat: number; // 21.3891
lng: number; // 39.8579
tz: number; // 3
}CITIES_BY_COUNTRY
Cities grouped by ISO 3166-1 alpha-2 country code:
{
SA: {
country: 'Saudi Arabia',
countryAr: 'السعودية',
cities: [ /* City, ... */ ]
},
EG: { ... },
// ... 50+ countries
}Types
interface CalculationMethod {
ar: string;
en: string;
tr: string;
fajrAngle: number;
ishaAngle: number;
ishaOffset?: number;
}
interface PrayerTimes {
fajr: string;
sunrise: string;
dhuhr: string;
asr: string;
maghrib: string;
isha: string;
}
interface NextPrayer {
name: string;
nameAr: string;
time: string;
diff: number;
}
interface City {
name: string;
nameAr: string;
lat: number;
lng: number;
tz: number;
}License
MIT
