Skip to content

Commit 793df2c

Browse files
committed
feat: updated getRubAlHizbMeta and getRubAlHizbMetabyAyahId
1 parent 4803bf6 commit 793df2c

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/getRubAlHizbMeta.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
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"
25

36
/**
47
* Retrieves the metadata for a specific quarter (rub' al-hizb) of the Quran.
58
*
69
* @param quarterIndex - The index of the quarter (rub' al-hizb) to retrieve metadata for, where 1 is the first quarter.
710
* @returns An object containing the metadata for the specified quarter, including the juz' (part), hizb (section), and the quarter (rub' al-hizb) index.
811
*/
9-
export function getRubAlHizbMeta(quarterIndex: RubAlHizbId): JuzHizb {
10-
// return HizbQuarterList[maqra]
12+
export function getRubAlHizbMeta(quarterIndex: RubAlHizbId): RubAlHizbMeta {
13+
const res = getRubAlHizb(quarterIndex)
1114

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
1320

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 }
2125
}

src/getRubAlHizbMetaByAyahId.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { findRubAlHizbByAyahId } from "./findRubAlHizbByAyahId"
22
import { getRubAlHizbMeta } from "./getRubAlHizbMeta"
3-
import { AyahId, JuzHizb } from "./types"
3+
import { AyahId, RubAlHizbMeta } from "./types"
44
import { checkValidAyahId } from "./validation"
55

66
/**
@@ -9,7 +9,7 @@ import { checkValidAyahId } from "./validation"
99
* @param ayahId - The Ayah ID to find the Juz, Hizb, and Hizb ID for.
1010
* @returns An object containing the Juz, Hizb, and Hizb ID for the given Ayah ID.
1111
*/
12-
export function getRubAlHizbMetaByAyahId(ayahId: AyahId): JuzHizb {
12+
export function getRubAlHizbMetaByAyahId(ayahId: AyahId): RubAlHizbMeta {
1313
checkValidAyahId(ayahId)
1414

1515
const quarterIndex = findRubAlHizbByAyahId(ayahId)

0 commit comments

Comments
 (0)