Skip to content

Commit

Permalink
Merge pull request #112 from batoulapps/4.4.x-cleanup
Browse files Browse the repository at this point in the history
Rename bundles and update documentation
  • Loading branch information
sgtsquiggs authored May 11, 2022
2 parents 02e66df + e160a07 commit 575083e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 41 deletions.
96 changes: 61 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,44 @@ Implementations of Adhan in other languages can be found in the parent repo [Adh

## Installation

Adhan was designed to work in the browser and in Node.js
Adhan was designed to work in both the browser and NodeJS applications.

### Browser

```
<script src="Adhan.js"></script>
We provide both ESM and UMD bundles for use in the browser.

Download the latest release and check under `package/lib/bundles`.

```html
<script src="adhan.umd.min.js"></script>
<script>
var prayerTimes = new adhan.PrayerTimes(coordinates, date, params);
var prayerTimes = new adhan.PrayerTimes(coordinates, date, params);
</script>
```

### Node

Both CommonJS and ES Module libraries are provided.

```
npm install adhan
```

CommonJS:

```js
const adhan = require('adhan');
const prayerTimes = new adhan.PrayerTimes(coordinates, date, params);
```
var adhan = require('adhan')
var prayerTimes = new adhan.PrayerTimes(coordinates, date, params);

ES Modules:

```js
import { Coordinates, CalculationMethod, PrayerTimes } from 'adhan';
const coordinates = new Coordinates(35.7897507, -78.6912485);
const params = CalculationMethod.MoonsightingCommittee();
const date = new Date(2022, 3, 20);
const prayerTimes = new PrayerTimes(coordinates, date, params);
```

## Migration
Expand All @@ -42,7 +60,7 @@ To get prayer times initialize a new `PrayerTimes` object passing in coordinates
date, and calculation parameters.

```js
var prayerTimes = new adhan.PrayerTimes(coordinates, date, params);
const prayerTimes = new PrayerTimes(coordinates, date, params);
```

### Initialization parameters
Expand All @@ -53,20 +71,20 @@ Create a `Coordinates` object with the latitude and longitude for the location
you want prayer times for.

```js
var coordinates = new adhan.Coordinates(35.78056, -78.6389);
const coordinates = new Coordinates(35.78056, -78.6389);
```

#### Date

The date parameter passed in should be an instance of the JavaScript `Date`
object. The year, month, and day values need to be populated. All other
values will be ignored. The year, month and day values should be for the date
that you want prayer times for. These date values are expected to be for the
that you want prayer times for. These date values are expected to be for the
Gregorian calendar.

```js
var date = new Date();
var date = new Date(2015, 11, 1);
const date = new Date();
const date = new Date(2015, 11, 1);
```

#### Calculation parameters
Expand All @@ -75,13 +93,12 @@ The rest of the needed information is contained within the `CalculationParameter

[Calculation Parameters & Methods Guide](METHODS.md)


### Prayer Times

Once the `PrayerTimes` object has been initialized it will contain values
for all five prayer times and the time for sunrise. The prayer times will be
Date object instances initialized with UTC values. You will then need to format
the times for the correct timezone. You can do that by using a timezone aware
the times for the correct timezone. You can do that by using a timezone aware
date formatting library like [moment](https://momentjs.com/docs/).

```js
Expand All @@ -90,28 +107,33 @@ moment(prayerTimes.fajr).tz('America/New_York').format('h:mm A');

### Full Example

```js
var date = new Date();
var coordinates = new adhan.Coordinates(35.78056, -78.6389);
var params = adhan.CalculationMethod.MuslimWorldLeague();
params.madhab = adhan.Madhab.Hanafi;
var prayerTimes = new adhan.PrayerTimes(coordinates, date, params);

var fajrTime = moment(prayerTimes.fajr).tz('America/New_York').format('h:mm A');
var sunriseTime = moment(prayerTimes.sunrise).tz('America/New_York').format('h:mm A');
var dhuhrTime = moment(prayerTimes.dhuhr).tz('America/New_York').format('h:mm A');
var asrTime = moment(prayerTimes.asr).tz('America/New_York').format('h:mm A');
var maghribTime = moment(prayerTimes.maghrib).tz('America/New_York').format('h:mm A');
var ishaTime = moment(prayerTimes.isha).tz('America/New_York').format('h:mm A');
```ts
import {
Coordinates,
CalculationMethod,
PrayerTimes,
SunnahTimes,
Prayer,
Qibla,
} from 'adhan';
import moment from 'moment-timezone';

const coordinates = new Coordinates(35.7897507, -78.6912485);
const params = CalculationMethod.MoonsightingCommittee();
const date = new Date();
const prayerTimes = new PrayerTimes(coordinates, date, params);
const sunnahTimes = new SunnahTimes(prayerTimes);
```

[![Edit Adhan Example](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/adhan-example-88v549?fontsize=14&hidenavigation=1&theme=dark)

### Convenience Utilities

The `PrayerTimes` object has functions for getting the current prayer and the next prayer. You can also get the time for a specified prayer, making it
easier to dynamically show countdowns until the next prayer.

```js
var prayerTimes = new adhan.PrayerTimes(coordinates, date, params);
var prayerTimes = new PrayerTimes(coordinates, date, params);

var current = prayerTimes.currentPrayer();
var next = prayerTimes.nextPrayer();
Expand All @@ -123,25 +145,29 @@ var nextPrayerTime = prayerTimes.timeForPrayer(next);
The Adhan library can also calulate Sunnah times. Given an instance of `PrayerTimes`, you can get a `SunnahTimes` object with the times for Qiyam.

```js
var sunnahTimes = new adhan.SunnahTimes(prayerTimes);
var middleOfTheNight = moment(sunnahTimes.middleOfTheNight).tz('America/New_York').format('h:mm A');
var lastThirdOfTheNight = moment(sunnahTimes.lastThirdOfTheNight).tz('America/New_York').format('h:mm A');
var sunnahTimes = new SunnahTimes(prayerTimes);
var middleOfTheNight = moment(sunnahTimes.middleOfTheNight)
.tz('America/New_York')
.format('h:mm A');
var lastThirdOfTheNight = moment(sunnahTimes.lastThirdOfTheNight)
.tz('America/New_York')
.format('h:mm A');
```

### Qibla Direction

Get the direction, in degrees from North, of the Qibla from a given set of coordinates.

```js
var coordinates = new adhan.Coordinates(35.78056, -78.6389);
var qiblaDirection = adhan.Qibla(coordinates);
var coordinates = new Coordinates(35.78056, -78.6389);
var qiblaDirection = Qibla(coordinates);
```

## Contributing

Adhan is made publicly available to provide a well tested and well documented library for Islamic prayer times to all
developers. We accept feature contributions provided that they are properly documented and include the appropriate
unit tests. We are also looking for contributions in the form of unit tests of of prayer times for different
Adhan is made publicly available to provide a well tested and well documented library for Islamic prayer times to all
developers. We accept feature contributions provided that they are properly documented and include the appropriate
unit tests. We are also looking for contributions in the form of unit tests of of prayer times for different
locations, we do ask that the source of the comparison values be properly documented.

**Note:** Commit messages should follow the [commit message convention](./.github/COMMIT_CONVENTIONS.md) so that changelogs can be automatically generated. Commit messages will be automatically validated upon commit. **If you are not familiar with the commit message convention, you should use `npm run commit` instead of `git commit`**, which provides an interactive CLI for generating proper commit messages.
Expand Down
3 changes: 1 addition & 2 deletions example.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<html>
<head>
<script src="lib/bundles/bundle.umd.min.js"></script>
<script src="lib/bundles/adhan.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.28/moment-timezone-with-data-10-year-range.min.js"></script>
</head>

<body>
<pre><script type="text/javascript">


function prayerName(prayer) {
if (prayer == adhan.Prayer.Fajr) {
return "Fajr";
Expand Down
8 changes: 4 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ export default {
input: 'src/Adhan.ts',
output: [
{
file: 'lib/bundles/bundle.esm.js',
file: 'lib/bundles/adhan.esm.js',
format: 'esm',
sourcemap: true,
},
{
file: 'lib/bundles/bundle.esm.min.js',
file: 'lib/bundles/adhan.esm.min.js',
format: 'esm',
plugins: [terser()],
sourcemap: true,
},
{
file: 'lib/bundles/bundle.umd.js',
file: 'lib/bundles/adhan.umd.js',
format: 'umd',
name: 'adhan',
sourcemap: true,
},
{
file: 'lib/bundles/bundle.umd.min.js',
file: 'lib/bundles/adhan.umd.min.js',
format: 'umd',
name: 'adhan',
plugins: [terser()],
Expand Down

0 comments on commit 575083e

Please sign in to comment.