Skip to content

Commit 4803bf6

Browse files
committed
feat: add getRubAlHizb and getRubAlHizbByAyahId methods
1 parent 7531007 commit 4803bf6

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/getRubAlHizb.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { HizbId, Juz, RubAlHizb, JuzPart, RubAlHizbId } from "./types"
2+
3+
/**
4+
* Retrieves the basic metadata for a specific quarter (rub' al-hizb) of the Quran.
5+
*
6+
* @param quarterIndex - The index of the quarter (rub' al-hizb) to retrieve metadata for, where 1 is the first quarter.
7+
* @returns An object containing the metadata for the specified quarter, including the juz' (part), hizb (section), and the quarter (rub' al-hizb) index.
8+
*/
9+
export function getRubAlHizb(quarterIndex: RubAlHizbId): RubAlHizb {
10+
// return HizbQuarterList[maqra]
11+
12+
// const quarterIndex = HizbQuarterList.findIndex(x => x > ayahId) - 1
13+
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+
}

src/getRubAlHizbByAyahId.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { findRubAlHizbByAyahId } from "./findRubAlHizbByAyahId"
2+
import { getRubAlHizb } from "./getRubAlHizb"
3+
import { AyahId, RubAlHizb } from "./types"
4+
import { checkValidAyahId } from "./validation"
5+
6+
/**
7+
* Finds the Juz, Hizb, and Rub-el-Hizb id for the given Ayah ID.
8+
*
9+
* @param ayahId - The Ayah ID to find the Juz, Hizb, and Hizb ID for.
10+
* @returns An object containing the Juz, Hizb, and Hizb ID for the given Ayah ID.
11+
*/
12+
export function getRubAlHizbByAyahId(ayahId: AyahId): RubAlHizb {
13+
checkValidAyahId(ayahId)
14+
15+
const quarterIndex = findRubAlHizbByAyahId(ayahId)
16+
return getRubAlHizb(quarterIndex)
17+
}

0 commit comments

Comments
 (0)