quran-meta
Version:
Library with meta data and functionality related to Holy Quran
23 lines (21 loc) • 740 B
JavaScript
import { checkValidSurah } from "./validation.mjs";
import { findAyahIdBySurah } from "./findAyahIdBySurah.mjs";
import { binarySearch } from "./utils.mjs";
//#region src/findPage.ts
/**
* Finds the page number for the given Surah and Ayah number.
*
* @param surah - The Surah to find the page for.
* @param ayah - The Ayah number to find the page for.
* @param data - The Lists object for the riwaya.
* @returns The page number for the given Surah and Ayah.
*/
function findPage(surah, ayah = 1, data) {
checkValidSurah(surah, data.meta);
const ayahId = findAyahIdBySurah(surah, ayah, data);
const PageList = data.PageList;
const jj = binarySearch(PageList, ayahId);
return jj < 0 ? -jj - 2 : jj;
}
//#endregion
export { findPage };