UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

64 lines (62 loc) 2.52 kB
const require_validation = require('./validation.cjs'); const require_utils = require('./utils.cjs'); const require_findSurahAyahByAyahId = require('./findSurahAyahByAyahId.cjs'); const require_findPagebyAyahId = require('./findPagebyAyahId.cjs'); const require_getRubAlHizbByAyahId = require('./getRubAlHizbByAyahId.cjs'); //#region src/getAyahMeta.ts /** * Retrieves metadata for a specific ayah of the Quran. * * @param ayahId - The ayahId number to retrieve metadata for (1-6236) * @param data - The Lists object for the riwaya. * @returns An object containing the ayah related meta, including information about the surah, juz, and quarter the ayah is in. * @throws RangeError If the ayahId number is not between 1 and 6236 */ function getAyahMeta(ayahId, data) { require_validation.checkValidAyahId(ayahId, data.meta); const { SurahList, SajdaList, PageList, RukuList, JuzList, HizbQuarterList } = data; const getThumunData = () => { if ("HizbEighthList" in data && data.HizbEighthList) { const jj = require_utils.binarySearch(data.HizbEighthList, ayahId); return { thumunAlHizbId: jj < 0 ? -jj - 2 : jj }; } return {}; }; const quarterData = require_getRubAlHizbByAyahId.getRubAlHizbByAyahId(ayahId, data); const [surah, ayah] = require_findSurahAyahByAyahId.findSurahAyahByAyahId(ayahId, data); const page = require_findPagebyAyahId.findPagebyAyahId(ayahId, data); const isSajdahAyah = require_utils.binarySearch(SajdaList, ayahId, (a, b) => a - b) >= 0; const rk = require_utils.binarySearch(RukuList, ayahId); const isStartOfRuku = rk > 0; const ruku = isStartOfRuku ? rk : -rk - 2; const isStartOfSurah = SurahList[surah][0] === ayahId; const isStartOfPage = PageList[page] === ayahId; const isStartOfJuz = JuzList[quarterData.juz] === ayahId; const isStartOfQuarter = HizbQuarterList[quarterData.rubAlHizbId] === ayahId; const isEndOfSurah = SurahList[surah + 1][0] - 1 === ayahId; const isEndOfPage = PageList[page + 1] - 1 === ayahId; const isEndOfJuz = JuzList[quarterData.juz + 1] - 1 === ayahId; const isEndOfRuku = require_utils.binarySearch(RukuList, ayahId + 1) > 0; const isEndOfQuarter = HizbQuarterList[quarterData.rubAlHizbId + 1] - 1 === ayahId; return { ...quarterData, ...getThumunData(), surah, ayah, page, isStartOfQuarter, isEndOfQuarter, isSajdahAyah, isStartOfPage, isEndOfPage, ruku, isStartOfJuz, isEndOfJuz, isStartOfSurah, isEndOfSurah, isStartOfRuku, isEndOfRuku }; } //#endregion exports.getAyahMeta = getAyahMeta;