UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

60 lines (58 loc) 2.67 kB
const require_surahList = require('./lists/surahList.cjs'); const require_validation = require('./validation.cjs'); const require_juzList = require('./lists/juzList.cjs'); const require_utils = require('./utils.cjs'); const require_findSurahAyahByAyahId = require('./findSurahAyahByAyahId.cjs'); const require_pageList = require('./lists/pageList.cjs'); const require_findPagebyAyahId = require('./findPagebyAyahId.cjs'); const require_rukuList = require('./lists/rukuList.cjs'); const require_hizbQuarterList = require('./lists/hizbQuarterList.cjs'); const require_getRubAlHizbByAyahId = require('./getRubAlHizbByAyahId.cjs'); const require_sajdaList = require('./lists/sajdaList.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) * @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) { require_validation.checkValidAyahId(ayahId); const quarterData = require_getRubAlHizbByAyahId.getRubAlHizbByAyahId(ayahId); const [surah, ayah] = require_findSurahAyahByAyahId.findSurahAyahByAyahId(ayahId); const page = require_findPagebyAyahId.findPagebyAyahId(ayahId); const isSajdahAyah = require_utils.binarySearch(require_sajdaList.SajdaList, ayahId, (a, b) => a - b[0]) >= 0; const rk = require_utils.binarySearch(require_rukuList.RukuList, ayahId); const isStartOfRuku = rk > 0; const ruku = isStartOfRuku ? rk : -rk - 2; const isStartOfSurah = require_surahList.SurahList[surah][0] === ayahId; const isStartOfPage = require_pageList.PageList[page] === ayahId; const isStartOfJuz = require_juzList.JuzList[quarterData.juz] === ayahId; const isStartOfQuarter = require_hizbQuarterList.HizbQuarterList[quarterData.rubAlHizbId] === ayahId; const isEndOfSurah = require_surahList.SurahList[surah + 1][0] - 1 === ayahId; const isEndOfPage = require_pageList.PageList[page + 1] - 1 === ayahId; const isEndOfJuz = require_juzList.JuzList[quarterData.juz + 1] - 1 === ayahId; const isEndOfRuku = require_utils.binarySearch(require_rukuList.RukuList, ayahId + 1) > 0; const isEndOfQuarter = require_hizbQuarterList.HizbQuarterList[quarterData.rubAlHizbId + 1] - 1 === ayahId; return { ...quarterData, surah, ayah, page, isStartOfQuarter, isEndOfQuarter, isSajdahAyah, isStartOfPage, isEndOfPage, ruku, isStartOfJuz, isEndOfJuz, isStartOfSurah, isEndOfSurah, isStartOfRuku, isEndOfRuku }; } //#endregion exports.getAyahMeta = getAyahMeta;