|
1 |
| -import { HizbId, Juz, JuzHizb, JuzPart, RubAlHizbId } from "./types" |
| 1 | +import { findSurahAyahByAyahId } from "./findSurahAyahByAyahId" |
| 2 | +import { getRubAlHizb } from "./getRubAlHizb" |
| 3 | +import { HizbQuarterList } from "./lists/hizbQuarterList" |
| 4 | +import { RubAlHizbMeta, RubAlHizbId, AyahId } from "./types" |
2 | 5 |
|
3 | 6 | /**
|
4 | 7 | * Retrieves the metadata for a specific quarter (rub' al-hizb) of the Quran.
|
5 | 8 | *
|
6 | 9 | * @param quarterIndex - The index of the quarter (rub' al-hizb) to retrieve metadata for, where 1 is the first quarter.
|
7 | 10 | * @returns An object containing the metadata for the specified quarter, including the juz' (part), hizb (section), and the quarter (rub' al-hizb) index.
|
8 | 11 | */
|
9 |
| -export function getRubAlHizbMeta(quarterIndex: RubAlHizbId): JuzHizb { |
10 |
| - // return HizbQuarterList[maqra] |
| 12 | +export function getRubAlHizbMeta(quarterIndex: RubAlHizbId): RubAlHizbMeta { |
| 13 | + const res = getRubAlHizb(quarterIndex) |
11 | 14 |
|
12 |
| - // const quarterIndex = HizbQuarterList.findIndex(x => x > ayahId) - 1 |
| 15 | + const [firstAyahId, nextJuzAyahId]: [AyahId, AyahId] = [ |
| 16 | + HizbQuarterList[quarterIndex], |
| 17 | + HizbQuarterList[quarterIndex + 1] |
| 18 | + ] |
| 19 | + const lastAyahId = nextJuzAyahId - 1 |
13 | 20 |
|
14 |
| - // const juz = findJuzByAyahId(ayahId) |
15 |
| - const juz = Math.floor((quarterIndex - 1) / 8) + 1 as Juz |
16 |
| - // isValidJuz(juz) |
17 |
| - |
18 |
| - const hizbIndex = Math.floor((quarterIndex - 1) / 4) + 1 as HizbId |
19 |
| - const juzPart = (quarterIndex % 8 || 8) as JuzPart |
20 |
| - return { juz, hizbId: hizbIndex, juzPart, rubAlHizbId: quarterIndex } |
| 21 | + return { firstAyahId, |
| 22 | + lastAyahId, |
| 23 | + first: findSurahAyahByAyahId(firstAyahId), |
| 24 | + last: findSurahAyahByAyahId(lastAyahId), ...res } |
21 | 25 | }
|
0 commit comments