UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

49 lines (47 loc) 1.82 kB
import { findJuzByAyahId } from "./findJuzByAyahId.mjs"; import { findSurahByAyahId } from "./findSurahByAyahId.mjs"; import { findPagebyAyahId } from "./findPagebyAyahId.mjs"; import { findRukuByAyahId } from "./findRukuByAyahId.mjs"; //#region src/findRangeAroundAyah.ts /** * Finds the range of ayahs surrounding a given ayah based on specified mode * @param ayahId - The unique identifier of the ayah * @param mode - The scope for finding the range: * - "juz": Returns range of ayahs in the same juz * - "surah": Returns range of ayahs in the same surah * - "ayah": Returns the single ayah as both start and end of range * - "page": Returns range of ayahs on the same page * - "ruku": Returns range of ayahs on the same ruku * - "all": Returns range covering all ayahs (1 to total number of ayahs) * @param data - The Lists object for the riwaya. * @returns An array of two numbers representing the start and end ayah IDs of the range [startAyahId, endAyahId] */ function findRangeAroundAyah(ayahId, mode, data) { const JuzList = data.JuzList; const SurahList = data.SurahList; const PageList = data.PageList; const RukuList = data.RukuList; switch (mode) { case "juz": { const juz = findJuzByAyahId(ayahId, data); return [JuzList[juz], JuzList[juz + 1] - 1]; } case "surah": { const surah = findSurahByAyahId(ayahId, data); return [SurahList[surah][0], SurahList[surah + 1][0] - 1]; } case "ayah": return [ayahId, ayahId]; case "page": { const page = findPagebyAyahId(ayahId, data); return [PageList[page], PageList[page + 1] - 1]; } case "ruku": { const ruku = findRukuByAyahId(ayahId, data); return [RukuList[ruku], RukuList[ruku + 1] - 1]; } case "all": default: return [1, data.meta.numAyahs]; } } //#endregion export { findRangeAroundAyah };