UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

21 lines (19 loc) 793 B
import { checkValidAyahId } from "./validation.mjs"; import { binarySearch } from "./utils.mjs"; //#region src/findThumunAlHizbByAyahId.ts /** * Finds the Maqra/Rub-al-Hizb of the Quran that contains the given Ayah (verse) ID. * * @param ayahId - The ID of the Ayah (verse) to find the Juz for. * @param data - The Lists object for the riwaya. * @returns The thumun of the Quran that contains the given Ayah ID. */ function findThumunAlHizbByAyahId(ayahId, data) { checkValidAyahId(ayahId, data.meta); const HizbEighthList = data.HizbEighthList; if (!HizbEighthList) throw new Error(`Riwaya ${data.meta.riwayaName} does not have Hizb Eighth List data.`); const jj = binarySearch(HizbEighthList, ayahId); return jj < 0 ? -jj - 2 : jj; } //#endregion export { findThumunAlHizbByAyahId };