UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

23 lines (21 loc) 700 B
import { checkValidSurah } from "./validation.js"; import { findAyahIdBySurah } from "./findAyahIdBySurah.js"; import { binarySearch } from "./utils.js"; import { PageList } from "./lists/pageList.js"; //#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. * @returns The page number for the given Surah and Ayah. */ function findPage(surah, ayah = 1) { checkValidSurah(surah); const ayahId = findAyahIdBySurah(surah, ayah); const jj = binarySearch(PageList, ayahId); const page = jj < 0 ? -jj - 2 : jj; return page; } //#endregion export { findPage };