JavaScript SDK
SDK chính thức cho JavaScript/TypeScript
Cài đặt
npm install @islamiovn/sdk
# hoặc
yarn add @islamiovn/sdk
# hoặc
pnpm add @islamiovn/sdkSDK đang trong giai đoạn phát triển. API có thể thay đổi trước khi ra v1.0.0.
Khởi tạo
import { IslamClient } from '@islamiovn/sdk';
const client = new IslamClient({
// Không cần API key trong public beta
baseUrl: 'https://api.islam.io.vn/v1', // mặc định
});Prayer Times
// Lấy giờ cầu nguyện hôm nay tại TP.HCM
const timings = await client.prayerTimes.getByProvince('ho-chi-minh');
console.log(timings.fajr); // "04:47"
console.log(timings.dhuhr); // "12:05"
console.log(timings.maghrib); // "18:08"
// Lấy theo tọa độ GPS
const timingsByCoords = await client.prayerTimes.getByCoordinates({
lat: 10.8231,
lng: 106.6297,
date: '2024-03-15',
method: 'MWL',
});
// Lấy cả tháng
const monthlyTimings = await client.prayerTimes.getMonth({
province: 'ha-noi',
year: 2024,
month: 3,
});Mosques
// Tìm thánh đường gần vị trí hiện tại
const mosques = await client.mosques.findNearby({
lat: 10.8231,
lng: 106.6297,
radius: 5, // km
});
// Lấy theo tỉnh thành
const hcmMosques = await client.mosques.getByProvince('ho-chi-minh');
// Lấy chi tiết một thánh đường
const mosque = await client.mosques.getById('masjid-al-rahim-hcm');Islamic Calendar
// Chuyển đổi ngày
const hijriDate = await client.calendar.toHijri('2024-03-15');
console.log(hijriDate.monthName); // "Ramadan"
console.log(hijriDate.year); // 1445
// Lấy sự kiện trong năm
const events = await client.calendar.getEvents(2024);
events.forEach(event => {
console.log(`${event.nameLocal}: ${event.gregorianDate}`);
});TypeScript Support
SDK được viết hoàn toàn bằng TypeScript với đầy đủ type definitions:
import type {
PrayerTimings,
Mosque,
HijriDate,
IslamicEvent,
PrayerMethod,
} from '@islamiovn/sdk';
const method: PrayerMethod = 'MWL'; // type-safeError Handling
import { IslamApiError } from '@islamiovn/sdk';
try {
const timings = await client.prayerTimes.getByProvince('invalid-province');
} catch (error) {
if (error instanceof IslamApiError) {
console.error(error.code); // "PROVINCE_NOT_FOUND"
console.error(error.message); // "Province 'invalid-province' not found..."
}
}Source Code
SDK là open-source: github.com/islamiovn/sdk-js