-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added method recommendation based on location
- Loading branch information
1 parent
65c6f20
commit c8fd1fb
Showing
7 changed files
with
174 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { findCountryByCoordinate } from 'country-locator' | ||
import { CountryMethods } from './data/methods' | ||
import type { LngLatLike } from './types/LangLatLike' | ||
import type { Methods } from './types/Methods' | ||
|
||
const methodsMap = new WeakMap<WeakKey, Methods[]>( | ||
Object.entries(CountryMethods).map(([country, methods]) => [Symbol(country), methods]) | ||
) | ||
|
||
/** | ||
* recommend methods to use from given coordinate | ||
* the methods are ranked by the most used to the least used | ||
* @param point - an array of two numbers - [x, y]. | ||
* PAY ATTENTION: x == longitude, y == latitude! | ||
* @returns Methods[] | undefined - An array of recommended prayer methods for the given location, or undefined if the location is not found. | ||
*/ | ||
export function MethodRecommender(coordinates: LngLatLike): Methods[] | undefined | ||
/** | ||
* recommend methods to use given coordinate | ||
* the methods are ranked by the most used to the least used | ||
* @param latitude - latitude of coordinate | ||
* @param longitude - longitude of coordinate | ||
* @returns Methods[] | undefined - An array of recommended prayer methods for the given location, or undefined if the location is not found. | ||
*/ | ||
export function MethodRecommender(latitude: number, longitude: number): Methods[] | undefined | ||
|
||
export function MethodRecommender(coordinatesOrLat: LngLatLike | number, longitude?: number): Methods[] | undefined { | ||
const countryInfo = findCountryByCoordinate( | ||
longitude ? [coordinatesOrLat as number, longitude] : getLngLat(coordinatesOrLat as LngLatLike) | ||
) | ||
return methodsMap.get(Symbol(countryInfo?.code)) | ||
} | ||
|
||
function getLngLat(coordinates: LngLatLike): [number, number] { | ||
if (Array.isArray(coordinates)) { | ||
return coordinates | ||
} else if ('lng' in coordinates && 'lat' in coordinates) { | ||
return [coordinates.lng, coordinates.lat] | ||
} else if ('lon' in coordinates && 'lat' in coordinates) { | ||
return [coordinates.lon, coordinates.lat] | ||
} else if ('longitude' in coordinates && 'latitude' in coordinates) { | ||
return [coordinates.longitude, coordinates.latitude] | ||
} else { | ||
throw new Error('Invalid coordinates object') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Methods } from '../types/Methods' | ||
|
||
export const CountryMethods = { | ||
SAU: [Methods.UMM_AL_QURA], | ||
AFG: [Methods.KARACHI], | ||
ALB: [Methods.MUSLIM_WORLD_LEAGUE], | ||
ARE: [Methods.DUBAI], | ||
BGD: [Methods.KARACHI], | ||
BHR: [Methods.BAHRAIN], | ||
BRN: [Methods.BRUNEI], | ||
CAN: [Methods.NORTH_AMERICA, Methods.MUSLIM_WORLD_LEAGUE], | ||
DEU: [Methods.GERMANY], | ||
// DNK: ['Europe/Copenhagen'], | ||
DZA: [Methods.ALGERIA], | ||
EGY: [Methods.EGYPTIAN], | ||
FRA: [Methods.FRANCE, Methods.NORTH_AMERICA, Methods.STANDARD], | ||
GBR: [Methods.NORTH_AMERICA, Methods.MUSLIM_WORLD_LEAGUE, Methods.MOONSIGHTING_COMMITTEE], | ||
IDN: [Methods.INDONESIA], | ||
IND: [Methods.KARACHI], | ||
IRN: [Methods.TEHRAN], | ||
IRQ: [Methods.IRAQ], | ||
ISR: [Methods.PALESTINE], | ||
JOR: [Methods.JORDAN], | ||
KWT: [Methods.KUWAIT], | ||
LBN: [Methods.EGYPTIAN], | ||
LBY: [Methods.LIBYA], | ||
MAR: [Methods.MOROCCO], | ||
MYS: [Methods.MALAYSIA], | ||
OMN: [Methods.OMAN], | ||
PAK: [Methods.KARACHI], | ||
PSE: [Methods.PALESTINE], | ||
QAT: [Methods.QATAR], | ||
RUS: [Methods.RUSSIA], | ||
// SDN: ['Africa/Khartoum'], | ||
SGP: [Methods.SINGAPORE], | ||
THA: [Methods.MALAYSIA], | ||
TUN: [Methods.TUNISIA], | ||
TUR: [Methods.TURKEY], | ||
USA: [Methods.NORTH_AMERICA, Methods.MUSLIM_WORLD_LEAGUE, Methods.MOONSIGHTING_COMMITTEE, Methods.EGYPTIAN], | ||
YEM: [Methods.YEMEN], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type CoordinatesObject = | ||
| { lng: number; lat: number } | ||
| { lon: number; lat: number } | ||
| { longitude: number; latitude: number } | ||
export type LngLatLike = [number, number] | CoordinatesObject |