UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

48 lines (46 loc) 1.94 kB
const require_findJuzByAyahId = require('./findJuzByAyahId.cjs'); const require_findSurahByAyahId = require('./findSurahByAyahId.cjs'); const require_findPagebyAyahId = require('./findPagebyAyahId.cjs'); const require_findRukuByAyahId = require('./findRukuByAyahId.cjs'); //#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; const { SurahList } = data; const { PageList } = data; const { RukuList } = data; switch (mode) { case "juz": { const juz = require_findJuzByAyahId.findJuzByAyahId(ayahId, data); return [JuzList[juz], JuzList[juz + 1] - 1]; } case "surah": { const surah = require_findSurahByAyahId.findSurahByAyahId(ayahId, data); return [SurahList[surah][0], SurahList[surah + 1][0] - 1]; } case "ayah": return [ayahId, ayahId]; case "page": { const page = require_findPagebyAyahId.findPagebyAyahId(ayahId, data); return [PageList[page], PageList[page + 1] - 1]; } case "ruku": { const ruku = require_findRukuByAyahId.findRukuByAyahId(ayahId, data); return [RukuList[ruku], RukuList[ruku + 1] - 1]; } default: return [1, data.meta.numAyahs]; } } //#endregion exports.findRangeAroundAyah = findRangeAroundAyah;