Skip to main content

Overview

Ramadan CLI is written in TypeScript and exports all type definitions. All API responses are validated at runtime using Zod schemas.

Prayer Data Types

PrayerTimings

Contains all prayer times for a day.
interface PrayerTimings {
  readonly Fajr: string;
  readonly Sunrise: string;
  readonly Dhuhr: string;
  readonly Asr: string;
  readonly Sunset: string;
  readonly Maghrib: string;
  readonly Isha: string;
  readonly Imsak: string;
  readonly Midnight: string;
  readonly Firstthird: string;
  readonly Lastthird: string;
}
Fajr
string
Fajr prayer time (e.g., “05:30”)
Sunrise
string
Sunrise time (not a prayer)
Dhuhr
string
Dhuhr (midday) prayer time
Asr
string
Asr (afternoon) prayer time
Sunset
string
Sunset time (not a prayer)
Maghrib
string
Maghrib prayer time (immediately after sunset)
Isha
string
Isha (night) prayer time
Imsak
string
Imsak time (10 minutes before Fajr, used in Ramadan)
Midnight
string
Islamic midnight (midpoint between sunset and sunrise)
Firstthird
string
End of first third of the night
Lastthird
string
Start of last third of the night

PrayerData

Complete prayer data response from the API.
interface PrayerData {
  readonly timings: PrayerTimings;
  readonly date: {
    readonly readable: string;
    readonly timestamp: string;
    readonly hijri: HijriDate;
    readonly gregorian: GregorianDate;
  };
  readonly meta: PrayerMeta;
}
timings
PrayerTimings
All prayer times for the day
date
object
Date information
meta
PrayerMeta
Calculation metadata (method, school, coordinates, timezone)

NextPrayerData

Extends PrayerData with next prayer information.
interface NextPrayerData {
  readonly timings: PrayerTimings;
  readonly date: PrayerData['date'];
  readonly meta: PrayerMeta;
  readonly nextPrayer: string;
  readonly nextPrayerTime: string;
}
nextPrayer
string
Name of next prayer (e.g., “Asr”, “Maghrib”)
nextPrayerTime
string
Time of next prayer (e.g., “16:30”)

PrayerMeta

Metadata about prayer time calculation.
interface PrayerMeta {
  readonly latitude: number;
  readonly longitude: number;
  readonly timezone: string;
  readonly method: {
    readonly id: number;
    readonly name: string;
  };
  readonly school:
    | {
        readonly id: number;
        readonly name: string;
      }
    | string;
}
latitude
number
Latitude used for calculation
longitude
number
Longitude used for calculation
timezone
string
IANA timezone string
method
object
Calculation method information
school
object | string
Asr school information (may be string or object)

Date Types

HijriDate

Hijri (Islamic) calendar date.
interface HijriDate {
  readonly date: string;
  readonly day: string;
  readonly month: {
    readonly number: number;
    readonly en: string;
    readonly ar: string;
  };
  readonly year: string;
  readonly weekday: {
    readonly en: string;
    readonly ar: string;
  };
}
date
string
Full date string (e.g., “15-09-1445”)
day
string
Day of month (e.g., “15”)
month
object
year
string
Hijri year (e.g., “1445”)
weekday
object

GregorianDate

Gregorian calendar date.
interface GregorianDate {
  readonly date: string;
  readonly day: string;
  readonly month: {
    readonly number: number;
    readonly en: string;
  };
  readonly year: string;
  readonly weekday: {
    readonly en: string;
  };
}
date
string
Full date string (e.g., “15-03-2024”)
day
string
Day of month (e.g., “15”)
month
object
year
string
Gregorian year (e.g., “2024”)
weekday
object

Geolocation Types

GeoLocation

Complete location data with coordinates and timezone.
interface GeoLocation {
  readonly city: string;
  readonly country: string;
  readonly latitude: number;
  readonly longitude: number;
  readonly timezone: string;
}
city
string
City name
country
string
Country name
latitude
number
Latitude coordinate
longitude
number
Longitude coordinate
timezone
string
IANA timezone string

CityCountryGuess

City resolution result (timezone may be missing).
interface CityCountryGuess {
  readonly city: string;
  readonly country: string;
  readonly latitude: number;
  readonly longitude: number;
  readonly timezone?: string;
}
timezone
string | undefined
IANA timezone string (may be undefined)

Calculation Method Types

CalculationMethod

Prayer time calculation method details.
interface CalculationMethod {
  readonly id: number;
  readonly name: string;
  readonly params: {
    readonly Fajr: number;
    readonly Isha: number | string;
  };
}
id
number
Method ID (0-23)
name
string
Full method name (e.g., “Islamic Society of North America (ISNA)”)
params
object
Calculation parameters

MethodsResponse

Record of all available calculation methods.
type MethodsResponse = Readonly<Record<string, CalculationMethod>>;
Example:
{
  "0": { id: 0, name: "Jafari (Shia Ithna-Ashari)", params: { ... } },
  "1": { id: 1, name: "University of Islamic Sciences, Karachi", params: { ... } },
  "2": { id: 2, name: "Islamic Society of North America (ISNA)", params: { ... } },
  // ...
}

MethodId

Branded type for type-safe method IDs.
type MethodId = number & { readonly __brand: 'MethodId' };

Qibla Types

QiblaData

Qibla direction information.
interface QiblaData {
  readonly latitude: number;
  readonly longitude: number;
  readonly direction: number;
}
latitude
number
Input latitude
longitude
number
Input longitude
direction
number
Qibla bearing in degrees from North (0-360)

Configuration Types

StoredLocation

Stored location data (all fields optional).
interface StoredLocation {
  readonly city?: string | undefined;
  readonly country?: string | undefined;
  readonly latitude?: number | undefined;
  readonly longitude?: number | undefined;
}

StoredPrayerSettings

Stored prayer calculation settings.
interface StoredPrayerSettings {
  readonly method: number;
  readonly school: number;
  readonly timezone?: string | undefined;
}
method
number
Calculation method ID (defaults to 2)
school
number
Asr school: 0 (Shafi) or 1 (Hanafi) (defaults to 0)
timezone
string | undefined
Timezone override

Function Option Types

FetchByCityOptions

interface FetchByCityOptions {
  readonly city: string;
  readonly country: string;
  readonly method?: number;
  readonly school?: number;
  readonly date?: Date;
}

FetchByAddressOptions

interface FetchByAddressOptions {
  readonly address: string;
  readonly method?: number;
  readonly school?: number;
  readonly date?: Date;
}

FetchByCoordsOptions

interface FetchByCoordsOptions {
  readonly latitude: number;
  readonly longitude: number;
  readonly method?: number;
  readonly school?: number;
  readonly timezone?: string;
  readonly date?: Date;
}

FetchNextPrayerOptions

interface FetchNextPrayerOptions {
  readonly latitude: number;
  readonly longitude: number;
  readonly method?: number;
  readonly school?: number;
  readonly timezone?: string;
}

FetchCalendarByCityOptions

interface FetchCalendarByCityOptions {
  readonly city: string;
  readonly country: string;
  readonly year: number;
  readonly month?: number;
  readonly method?: number;
  readonly school?: number;
}

FetchCalendarByAddressOptions

interface FetchCalendarByAddressOptions {
  readonly address: string;
  readonly year: number;
  readonly month?: number;
  readonly method?: number;
  readonly school?: number;
}

FetchHijriCalendarByCityOptions

interface FetchHijriCalendarByCityOptions {
  readonly city: string;
  readonly country: string;
  readonly year: number;
  readonly month: number;  // Required for Hijri calendar
  readonly method?: number;
  readonly school?: number;
}

FetchHijriCalendarByAddressOptions

interface FetchHijriCalendarByAddressOptions {
  readonly address: string;
  readonly year: number;
  readonly month: number;  // Required for Hijri calendar
  readonly method?: number;
  readonly school?: number;
}

Usage with TypeScript

Import Types

import type {
  PrayerData,
  PrayerTimings,
  HijriDate,
  GregorianDate,
  PrayerMeta,
  GeoLocation,
  QiblaData,
  CalculationMethod,
  MethodsResponse,
} from 'ramadan-cli';

Type Guards

All API responses are validated at runtime:
import { fetchTimingsByCity } from 'ramadan-cli';

// Response is guaranteed to match PrayerData interface
const data = await fetchTimingsByCity({
  city: 'Lahore',
  country: 'Pakistan',
});

// TypeScript knows the exact shape
const fajr: string = data.timings.Fajr;
const hijriMonth: string = data.date.hijri.month.en;

Readonly Types

All types use readonly modifiers to prevent accidental mutations:
const data = await fetchTimingsByCity({ city: 'Lahore', country: 'Pakistan' });

// TypeScript error: Cannot assign to 'Fajr' because it is a read-only property
data.timings.Fajr = '06:00';

Runtime Validation

All API responses are validated using Zod schemas. If the API returns unexpected data, an error is thrown:
try {
  const data = await fetchTimingsByCity({
    city: 'Invalid',
    country: 'Invalid',
  });
} catch (error) {
  // Error: Invalid API response: ...
}