UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

49 lines (48 loc) 1.88 kB
import { findPagebyAyahId } from "./findPagebyAyahId.mjs"; import { findSurahAyahByAyahId } from "./findSurahAyahByAyahId.mjs"; import { getRubAlHizbByAyahId } from "./getRubAlHizbByAyahId.mjs"; import { HizbQuarterList } from "./lists/hizbQuarterList.mjs"; import { JuzList } from "./lists/juzList.mjs"; import { PageList } from "./lists/pageList.mjs"; import { RukuList } from "./lists/rukuList.mjs"; import { SajdaList } from "./lists/sajdaList.mjs"; import { SurahList } from "./lists/surahList.mjs"; import { binarySearch } from "./utils.mjs"; import { checkValidAyahId } from "./validation.mjs"; export 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 }; }