UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

27 lines (25 loc) 944 B
const require_validation = require('./validation.cjs'); const require_utils = require('./utils.cjs'); //#region src/findManzilByAyahId.ts /** * Finds the Manzil number for a given Ayah ID using binary search. * A Manzil is one of seven approximately equal divisions of the Quran. * * @param ayahId - The ID of the Ayah to find the Manzil for * @param data - The Lists object for the riwaya. * @returns The Manzil number (1-7) containing the specified Ayah * @throws {@link Error} If the provided Ayah ID is invalid * * @example * ```typescript * const manzil = findManzilByAyahId(2345, HafsLists); // Returns the Manzil containing Ayah 2345 * ``` */ function findManzilByAyahId(ayahId, data) { require_validation.checkValidAyahId(ayahId, data.meta); const ManzilList = data.ManzilList; const jj = require_utils.binarySearch(ManzilList, ayahId); return jj < 0 ? -jj - 2 : jj; } //#endregion exports.findManzilByAyahId = findManzilByAyahId;