@mosqueicu/islamic_prayer_times
v0.0.4
Published
npm package for islamic texts
Downloads
22
Maintainers
Readme
# islamic_prayer_times NPM
The islamic prayer times NPM package
simplifies access to Islamic prayer
times data for developers. This package
extends the functionality of the Prayer
Times API repository to provide an
easy-to-use interface for retrieving
prayer times information.
## Installation
You can install the Sacred Texts NPM
package via npm:
```bash
npm i @mosqueicu/islamic_prayer_times
```
importing the package
Import the package in your code:
const islamic_prayer_times = require('@mosqueicu/islamic_prayer_times');
Functions
getPrayerTimes
Function
Description
The getPrayerTimes
function is a
JavaScript function for fetching daily
prayer times based on various parameters
such as date, location coordinates,
calculation method, and other optional
settings. It utilizes the Aladhan API to
retrieve accurate prayer times.
Usage
To use this function, you need to import it into your JavaScript/TypeScript project. Here's how you can import it:
import { getPrayerTimes } from '@mosqueicu/islamic_prayer_times';
Function Signature
async function getPrayerTimes(options): Promise<any>
Parameters
options
(required): An object of typePrayerTimeOptions
containing the following properties:date
(string, required): The date for which you want to fetch prayer times in the format 'DD-MM-YYYY'.latitude
(number, required): The latitude of the location for which you want to fetch prayer times.longitude
(number, required): The longitude of the location for which you want to fetch prayer times.method
(number, optional): The calculation method for prayer times. Defaults tonull
.shafaq
(number, optional): The shafaq method for prayer times. Defaults tonull
.tune
(number, optional): The tune method for prayer times. Defaults tonull
.school
(number, optional): The school of jurisprudence for prayer times. Defaults tonull
.midnightMode
(number, optional): The midnight mode for prayer times. Defaults tonull
.timezonestring
(string, optional): The time zone string for the location. Defaults tonull
.latitudeAdjustmentMethod
(string, optional): The latitude adjustment method for prayer times. Defaults tonull
.adjustment
(number, optional): The adjustment for prayer times. Defaults tonull
.iso8601
(boolean, optional): Whether to return prayer times in ISO8601 format. Defaults tonull
.
Returns
- A Promise that resolves to an object containing the prayer times data or rejects with an error if the request fails.
Example
Here's an example of how to use the
getPrayerTimes
function:
const options: PrayerTimeOptions = {
date: '17-07-2007',
latitude: 51.508515,
longitude: -0.1254872,
method: 2, // Calculation method (optional)
};
getPrayerTimes(options)
.then((data) => {
console.log(data); // Print the retrieved prayer times data
})
.catch((error) => {
console.error(error); // Handle any errors that occur during the request
});
In this example, you specify the date
and location coordinates in the
options
object and, if needed,
additional parameters for calculation
methods. The function then makes an API
request to fetch the daily prayer times
and returns the data.
Error Handling
The function handles errors by rejecting the Promise if there is a failure in fetching the data. You can catch these errors and handle them as needed.
Error Object
The error object thrown by the function will include an error message indicating the reason for the failure.
Error: Failed to fetch prayer times: [error message]
API Endpoint
The function uses the Aladhan API to retrieve prayer times data. The API endpoint is constructed based on the provided date.
- API Endpoint:
http://api.aladhan.com/v1/timings/[date]
Please note that you need an internet connection to access the API.
License
This function is provided under [your project's license].
Credits
This function was developed by MosqueICU. If you have any questions or need support, please contact us on https://discord.gg/WtKVyeeDrZ or visit our website at https://mosque.icu.
License
This package is released under the MIT license.