UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

28 lines (26 loc) 919 B
import { checkValidPage } from "./validation.mjs"; import { findSurahAyahByAyahId } from "./findSurahAyahByAyahId.mjs"; //#region src/getPageMeta.ts /** * Retrieves metadata for a specific page of the Quran. * * @param pageNum - The page number to retrieve metadata for (1-604) * @param data - The Lists object for the riwaya. * @returns {@link PageMeta} An object containing the page number, first ayah, and last ayah on the page * @throws {@link RangeError} If the page number is not between 1 and 604 */ function getPageMeta(pageNum, data) { checkValidPage(pageNum, data.meta); const PageList = data.PageList; const [firstAyahId, nextPage] = [PageList[pageNum], PageList[pageNum + 1]]; const lastAyahId = nextPage - 1; return { pageNum, firstAyahId, lastAyahId, first: findSurahAyahByAyahId(firstAyahId, data), last: findSurahAyahByAyahId(lastAyahId, data) }; } //#endregion export { getPageMeta };