A minimalist, offline TypeScript SDK for calculating Islamic prayer times without any external dependencies.
Installation β’ Quick Start β’ API Reference β’ Examples β’ Documentation
- β Zero Dependencies: No external libraries required
- β Offline: Works completely offline without internet connection
- β Fast: Calculations complete in <10ms
- β Lightweight: <50KB package size
- β Accurate: Β±1 minute accuracy compared to official sources
- β Flexible: Support for multiple calculation methods and custom angles
- β TypeScript: Full TypeScript support with type definitions
- β Universal: Works in Node.js and all modern browsers
- β Well-tested: Comprehensive test suite with 19+ test cases
npm install @muslims-community/prayer-times-calculationyarn add @muslims-community/prayer-times-calculationpnpm add @muslims-community/prayer-times-calculationimport { PrayerTimesSDK } from '@muslims-community/prayer-times-calculation';
// Riyadh coordinates
const latitude = 24.7136;
const longitude = 46.6753;
const timezone = 3; // UTC+3
const date = new Date(); // Current date
const prayerTimes = new PrayerTimesSDK(latitude, longitude, date, timezone, {
method: 'MWL',
asrJurisdiction: 'Standard'
});
const times = prayerTimes.getTimes();
console.log(times);
// {
// fajr: "04:32",
// sunrise: "05:52",
// dhuhr: "12:15",
// asr: "15:42",
// maghrib: "18:38",
// isha: "20:08"
// }new PrayerTimesSDK(
latitude: number,
longitude: number,
date: Date = new Date(),
timezone: number,
options: CalculationOptions
)latitude: Geographic latitude (-90 to 90)longitude: Geographic longitude (-180 to 180)date: Date for calculation (optional, defaults to current date)timezone: UTC offset in hours (e.g., 3 for UTC+3, -5 for UTC-5)options: Calculation configuration object
interface CalculationOptions {
method: 'MWL' | 'ISNA' | 'Egypt' | 'Makkah' | 'Karachi' | 'Custom';
fajrAngle?: number; // Required when method is 'Custom'
ishaAngle?: number; // Required when method is 'Custom'
asrJurisdiction: 'Standard' | 'Hanafi';
}Returns prayer times as formatted strings (HH:mm).
interface PrayerTimes {
fajr: string; // Dawn prayer
sunrise: string; // Sunrise time
dhuhr: string; // Noon prayer
asr: string; // Afternoon prayer
maghrib: string; // Sunset prayer
isha: string; // Night prayer
}| Method | Fajr Angle | Isha Angle | Description |
|---|---|---|---|
| MWL | 18Β° | 17Β° | Muslim World League |
| ISNA | 15Β° | 15Β° | Islamic Society of North America |
| Egypt | 19.5Β° | 17.5Β° | Egyptian General Authority |
| Makkah | 18.5Β° | 18.5Β° | Umm Al-Qura University |
| Karachi | 18Β° | 18Β° | University of Islamic Sciences, Karachi |
| Custom | Custom | Custom | User-defined angles |
- Standard (Shafi/Maliki/Hanbali): Shadow length = object height
- Hanafi: Shadow length = 2 Γ object height
// Muslim World League method (Most common)
const mwl = new PrayerTimesSDK(24.7136, 46.6753, new Date(), 3, {
method: 'MWL',
asrJurisdiction: 'Standard'
});
// Islamic Society of North America method
const isna = new PrayerTimesSDK(40.7128, -74.0060, new Date(), -5, {
method: 'ISNA',
asrJurisdiction: 'Standard'
});
// Custom angles for specific requirements
const custom = new PrayerTimesSDK(51.5074, -0.1278, new Date(), 0, {
method: 'Custom',
fajrAngle: 18,
ishaAngle: 16,
asrJurisdiction: 'Hanafi'
});// New York, USA
const nyTimes = new PrayerTimesSDK(40.7128, -74.0060, new Date(), -5, {
method: 'ISNA',
asrJurisdiction: 'Standard'
});
// London, UK
const londonTimes = new PrayerTimesSDK(51.5074, -0.1278, new Date(), 0, {
method: 'MWL',
asrJurisdiction: 'Standard'
});
// Tokyo, Japan
const tokyoTimes = new PrayerTimesSDK(35.6762, 139.6503, new Date(), 9, {
method: 'MWL',
asrJurisdiction: 'Standard'
});
// Cairo, Egypt
const cairoTimes = new PrayerTimesSDK(30.0444, 31.2357, new Date(), 2, {
method: 'Egypt',
asrJurisdiction: 'Standard'
});// Calculate for Ramadan 2024
const ramadanStart = new Date('2024-03-11');
const ramadanTimes = new PrayerTimesSDK(24.7136, 46.6753, ramadanStart, 3, {
method: 'MWL',
asrJurisdiction: 'Standard'
});
// Calculate for next Friday
const nextFriday = new Date();
nextFriday.setDate(nextFriday.getDate() + (5 - nextFriday.getDay() + 7) % 7);
const fridayTimes = new PrayerTimesSDK(40.7128, -74.0060, nextFriday, -5, {
method: 'ISNA',
asrJurisdiction: 'Standard'
});import React, { useState, useEffect } from 'react';
import { PrayerTimesSDK } from '@muslims-community/prayer-times-calculation';
const PrayerTimesWidget: React.FC = () => {
const [times, setTimes] = useState<any>(null);
useEffect(() => {
// Get user's location
navigator.geolocation.getCurrentPosition((position) => {
const { latitude, longitude } = position.coords;
const timezone = -new Date().getTimezoneOffset() / 60;
const prayerTimes = new PrayerTimesSDK(latitude, longitude, new Date(), timezone, {
method: 'MWL',
asrJurisdiction: 'Standard'
});
setTimes(prayerTimes.getTimes());
});
}, []);
if (!times) return <div>Loading prayer times...</div>;
return (
<div>
<h2>Today's Prayer Times</h2>
<ul>
<li>Fajr: {times.fajr}</li>
<li>Sunrise: {times.sunrise}</li>
<li>Dhuhr: {times.dhuhr}</li>
<li>Asr: {times.asr}</li>
<li>Maghrib: {times.maghrib}</li>
<li>Isha: {times.isha}</li>
</ul>
</div>
);
};The SDK is designed for high performance:
| Metric | Value |
|---|---|
| Execution Time | <10ms on average hardware |
| Memory Usage | <100KB |
| Package Size | <50KB (uncompressed) |
| Bundle Size | <15KB (minified + gzipped) |
Prayer times are calculated with Β±1 minute accuracy compared to official Islamic authorities. The calculations use:
- β Standard astronomical formulas
- β Proper solar declination and equation of time
- β Geographic coordinate corrections
- β Timezone adjustments
- β Atmospheric refraction corrections
Works in all modern browsers and Node.js environments:
| Environment | Minimum Version |
|---|---|
| Chrome/Edge | 88+ |
| Firefox | 78+ |
| Safari | 14+ |
| Node.js | 14+ |
| React Native | 0.60+ |
The package includes comprehensive tests:
npm test # Run all tests
npm run test:watch # Watch mode
npm run test:coverage # Coverage report- English (This file)
- Ψ§ΩΨΉΨ±Ψ¨ΩΨ© (Arabic)
- Ψ§Ψ±Ψ―Ω (Urdu)
We welcome contributions! Please see our Contributing Guide for details.
git clone https://github.com/Muslims-Community/prayer-times-calculation-ts.git
cd prayer-times-calculation-ts
npm install
npm run devThis project is licensed under the MIT License - see the LICENSE file for details.
If you find this package helpful, please consider:
- β Starring the repository
- π Reporting bugs via GitHub Issues
- π‘ Suggesting features
- π Contributing code
- Author: Mahmoud Alsamman
- Email: memoibraheem1@gmail.com
- GitHub: @mahmoudalsaman
- NPM: @muslims-community/prayer-times-calculation