UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

67 lines (59 loc) 2.58 kB
const require_surahList = require('./lists/surahList.cjs'); const require_validation = require('./validation.cjs'); const require_juzList = require('./lists/juzList.cjs'); const require_pageList = require('./lists/pageList.cjs'); const require_rukuList = require('./lists/rukuList.cjs'); const require_hizbQuarterList = require('./lists/hizbQuarterList.cjs'); const require_sajdaList = require('./lists/sajdaList.cjs'); const require_getAyahMeta = require('./getAyahMeta.cjs'); //#region src/getAyahMetasForSurah.ts /** * Retrieves metadata for all ayahs in a specific surah. * * @param surahNumber - The surah number (1-114) * @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) { require_validation.checkValidSurah(surahNumber); const [startAyahId, ayahCount] = require_surahList.SurahList[surahNumber]; const endAyahId = startAyahId + ayahCount - 1; const result = []; let meta = require_getAyahMeta.getAyahMeta(startAyahId); for (let ayahId = startAyahId; ayahId <= endAyahId; ayahId++) { if (ayahId > startAyahId) { meta = structuredClone(meta); meta.ayah += 1; meta.isStartOfSurah = false; meta.isEndOfSurah = endAyahId === ayahId; if (require_pageList.PageList[meta.page + 1] === ayahId) { meta.page += 1; meta.isStartOfPage = true; } else meta.isStartOfPage = false; meta.isEndOfPage = require_pageList.PageList[meta.page + 1] === ayahId + 1; if (require_rukuList.RukuList[meta.ruku + 1] === ayahId) { meta.ruku += 1; meta.isStartOfRuku = true; } else meta.isStartOfRuku = false; meta.isEndOfRuku = require_rukuList.RukuList[meta.ruku + 1] === ayahId + 1; meta.isEndOfJuz = require_juzList.JuzList[meta.juz + 1] === ayahId + 1; if (require_juzList.JuzList[meta.juz + 1] === ayahId) { meta.juz += 1; meta.hizbId += 1; meta.isStartOfJuz = true; } else meta.isStartOfJuz = false; meta.isEndOfQuarter = require_hizbQuarterList.HizbQuarterList[meta.rubAlHizbId + 1] === ayahId + 1; if (require_hizbQuarterList.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 = require_sajdaList.SajdaList.some((x) => x[0] === ayahId); } result.push(meta); } return result; } //#endregion exports.getAyahMetasForSurah = getAyahMetasForSurah;