UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

60 lines (58 loc) 2.21 kB
import { SurahList } from "./lists/surahList.js"; import { checkValidAyahId } from "./validation.js"; import { JuzList } from "./lists/juzList.js"; import { binarySearch } from "./utils.js"; import { findSurahAyahByAyahId } from "./findSurahAyahByAyahId.js"; import { PageList } from "./lists/pageList.js"; import { findPagebyAyahId } from "./findPagebyAyahId.js"; import { RukuList } from "./lists/rukuList.js"; import { HizbQuarterList } from "./lists/hizbQuarterList.js"; import { getRubAlHizbByAyahId } from "./getRubAlHizbByAyahId.js"; import { SajdaList } from "./lists/sajdaList.js"; //#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) { checkValidAyahId(ayahId); const quarterData = getRubAlHizbByAyahId(ayahId); const [surah, ayah] = findSurahAyahByAyahId(ayahId); const page = findPagebyAyahId(ayahId); const isSajdahAyah = binarySearch(SajdaList, ayahId, (a, b) => a - b[0]) >= 0; const rk = 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 = binarySearch(RukuList, ayahId + 1) > 0; const isEndOfQuarter = HizbQuarterList[quarterData.rubAlHizbId + 1] - 1 === ayahId; return { ...quarterData, surah, ayah, page, isStartOfQuarter, isEndOfQuarter, isSajdahAyah, isStartOfPage, isEndOfPage, ruku, isStartOfJuz, isEndOfJuz, isStartOfSurah, isEndOfSurah, isStartOfRuku, isEndOfRuku }; } //#endregion export { getAyahMeta };