UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

56 lines (54 loc) 2.06 kB
import { checkValidSurah } from "./validation.mjs"; import { getAyahMeta } from "./getAyahMeta.mjs"; //#region src/getAyahMetasForSurah.ts /** * Retrieves metadata for all ayahs in a specific surah. * * @param surahNumber - The surah number (1-114) * @param data - The Lists object for the riwaya. * @returns Array of AyahMeta objects for each ayah in the surah * @throws RangeError If the surah number is not between 1 and 114 */ function getAyahMetasForSurah(surahNumber, data) { checkValidSurah(surahNumber, data.meta); const { SurahList, SajdaList, PageList, RukuList, JuzList, HizbQuarterList } = data; const [startAyahId, ayahCount] = SurahList[surahNumber]; const endAyahId = startAyahId + ayahCount - 1; const result = []; let meta = getAyahMeta(startAyahId, data); result.push(meta); for (let ayahId = startAyahId + 1; ayahId <= endAyahId; ayahId++) { meta = structuredClone(meta); meta.ayah += 1; meta.isStartOfSurah = false; meta.isEndOfSurah = endAyahId === ayahId; if (PageList[meta.page + 1] === ayahId) { meta.page += 1; meta.isStartOfPage = true; } else meta.isStartOfPage = false; meta.isEndOfPage = PageList[meta.page + 1] === ayahId + 1; if (RukuList[meta.ruku + 1] === ayahId) { meta.ruku += 1; meta.isStartOfRuku = true; } else meta.isStartOfRuku = false; meta.isEndOfRuku = RukuList[meta.ruku + 1] === ayahId + 1; meta.isEndOfJuz = JuzList[meta.juz + 1] === ayahId + 1; if (JuzList[meta.juz + 1] === ayahId) { meta.juz += 1; meta.hizbId += 1; meta.isStartOfJuz = true; } else meta.isStartOfJuz = false; meta.isEndOfQuarter = HizbQuarterList[meta.rubAlHizbId + 1] === ayahId + 1; if (HizbQuarterList[meta.rubAlHizbId + 1] === ayahId) { meta.rubAlHizbId += 1; meta.juzPart = meta.isStartOfJuz ? 1 : meta.juzPart + 1; meta.isStartOfQuarter = true; if (meta.juzPart === 5) meta.hizbId += 1; } else meta.isStartOfQuarter = false; meta.isSajdahAyah = SajdaList.includes(ayahId); result.push(meta); } return result; } //#endregion export { getAyahMetasForSurah };