UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

27 lines (25 loc) 837 B
import { checkValidAyahId } from "./validation.mjs"; import { binarySearch } from "./utils.mjs"; //#region src/findRukuByAyahId.ts /** * Finds the Ruku number for a given Ayah ID using binary search. * * @param ayahId - The unique identifier of an Ayah in format: surah:ayah (e.g., "2:255") * @param data - The Lists object for the riwaya. * @returns The Ruku number corresponding to the given Ayah ID * @throws {@link Error} If the provided Ayah ID is invalid * * @example * ```ts * const ruku = findRukuByAyahId("2:255", HafsLists); * // Returns the Ruku number containing Ayah 255 of Surah 2 * ``` */ function findRukuByAyahId(ayahId, data) { checkValidAyahId(ayahId, data.meta); const RukuList = data.RukuList; const jj = binarySearch(RukuList, ayahId); return jj < 0 ? -jj - 2 : jj; } //#endregion export { findRukuByAyahId };