UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

404 lines (402 loc) 11.4 kB
import { getSurahInfo } from "./getSurahInfo.mjs"; import { getAyahCountInSurah } from "./getAyahCountInSurah.mjs"; import { isValidAyahId, isValidAyahNo, isValidJuz, isValidPage, isValidRuku, isValidSurah, isValidSurahAyah } from "./typeGuards.mjs"; import { ayahStringSplitter, string2NumberSplitter } from "./ayahStringSplitter.mjs"; import { findAyahIdBySurah } from "./findAyahIdBySurah.mjs"; import { findJuzByAyahId } from "./findJuzByAyahId.mjs"; import { findJuz } from "./findJuz.mjs"; import { findSurahAyahByAyahId } from "./findSurahAyahByAyahId.mjs"; import { findSurahByAyahId } from "./findSurahByAyahId.mjs"; import { findJuzAndShift, findJuzAndShiftByAyahId } from "./findJuzAndShift.mjs"; import { findJuzMetaBySurah } from "./findJuzMetaBySurah.mjs"; import { findManzilByAyahId } from "./findManzilByAyahId.mjs"; import { findManzil } from "./findManzil.mjs"; import { findPage } from "./findPage.mjs"; import { findPagebyAyahId } from "./findPagebyAyahId.mjs"; import { findRukuByAyahId } from "./findRukuByAyahId.mjs"; import { findRangeAroundAyah } from "./findRangeAroundAyah.mjs"; import { findRangeAroundSurahAyah } from "./findRangeAroundSurahAyah.mjs"; import { findRubAlHizbByAyahId } from "./findRubAlHizbByAyahId.mjs"; import { findRubAlHizb } from "./findRubAlHizb.mjs"; import { findThumunAlHizbByAyahId } from "./findThumunAlHizbByAyahId.mjs"; import { findThumunAlHizb } from "./findThumunAlHizb.mjs"; import { generatePartBlocks, getList, getListNormalised } from "./lists/getList.mjs"; import { getRubAlHizb } from "./getRubAlHizb.mjs"; import { getRubAlHizbByAyahId } from "./getRubAlHizbByAyahId.mjs"; import { getAyahMeta } from "./getAyahMeta.mjs"; import { getAyahMetasForSurah } from "./getAyahMetasForSurah.mjs"; import { getJuzMeta } from "./getJuzMeta.mjs"; import { getManzilMeta } from "./getManzilMeta.mjs"; import { getPageMeta } from "./getPageMeta.mjs"; import { getRubAlHizbMeta } from "./getRubAlHizbMeta.mjs"; import { getRubAlHizbMetaByAyahId } from "./getRubAlHizbMetaByAyahId.mjs"; import { getRukuMeta } from "./getRukuMeta.mjs"; import { getSurahMeta } from "./getSurahMeta.mjs"; import { getThumunAlHizb } from "./getThumunAlHizb.mjs"; import { getThumunAlHizbByAyahId } from "./getThumunAlHizbByAyahId.mjs"; import { getThumunAlHizbMeta } from "./getThumunAlHizbMeta.mjs"; import { prevAyah } from "./prevAyah.mjs"; import { nextAyah } from "./nextAyah.mjs"; import { isAyahJuzFirst } from "./isAyahJuzFirst.mjs"; import { isAyahPageFirst } from "./isAyahPageFirst.mjs"; import { isSurahAyahJuzFirst } from "./isSurahAyahJuzFirst.mjs"; import { isSurahAyahPageFirst } from "./isSurahAyahPageFirst.mjs"; import { getThumunAlHizbMetaByAyahId } from "./getThumunAlHizbMetaByAyahId.mjs"; import { surahStringParser } from "./surahStringParser.mjs"; //#region src/QuranRiwaya.ts /** * QuranRiwaya class provides a clean API for Quran metadata operations * with a specific riwaya (recitation tradition) context. * * Currently provides basic Surah and Ayah operations. For advanced features * like Juz, Page, Manzil, RubAlHizb, etc., use the functional API directly. * * @example * **Basic Usage with Hafs** * ```typescript * import { quran } from 'quran-meta/hafs' * * const surahMeta = quran.getSurahMeta(2) // Get Al-Baqarah metadata * const ayahCount = quran.getAyahCountInSurah(2) // 286 ayahs * const [surah, ayah] = quran.findSurahAyahByAyahId(100) // [2, 93] * ``` * * @example * **Working with Qalun** * ```typescript * import { quran } from 'quran-meta/qalun' * * const meta = quran.meta * console.log(meta.numAyahs) // 6214 (Qalun has fewer ayahs than Hafs) * ``` * * @example * **Creating a custom instance** * ```typescript * import { QuranRiwaya } from 'quran-meta' * import { WarshMeta, WarshLists } from 'quran-meta/lists/WarshLists' * * const warsh = QuranRiwaya.create(WarshLists) * ``` */ var QuranRiwaya = class QuranRiwaya { #riwaya; #meta; #data; constructor(rData) { this.#riwaya = rData.meta.riwayaName; this.#meta = rData.meta; this.#data = rData; } /** * Create a QuranRiwaya instance with the specified riwaya, metadata, and lists * @param riwaya - The riwaya name ("Hafs", "Qalun", or "Warsh") * @param meta - The metadata for this riwaya * @param rData - The Lists object for this riwaya */ static create(rData) { return new QuranRiwaya(rData); } /** * Gets the metadata for the specified Surah */ getSurahMeta(surahNum) { return getSurahMeta(surahNum, this.#data); } ayahStringSplitter(str, isStrict = true) { return ayahStringSplitter(str, isStrict, this.#data); } /** * Gets the surah info array [firstAyahId, ayahCount, surahOrder, rukuCount, name, isMeccan] */ getSurahInfo(surah) { return getSurahInfo(surah, this.#data); } /** * Gets the count of ayahs in a surah */ getAyahCountInSurah(surah) { return getAyahCountInSurah(surah, this.#data); } /** * Finds the surah number for a given ayah ID */ findSurahByAyahId(ayahId) { return findSurahByAyahId(ayahId, this.#data); } /** * Finds the [surah, ayah] tuple for a given ayah ID */ findSurahAyahByAyahId(ayahId) { return findSurahAyahByAyahId(ayahId, this.#data); } /** * Finds the ayah ID for a given surah and ayah number */ findAyahIdBySurah(surah, ayah) { return findAyahIdBySurah(surah, ayah, this.#data); } generatePartBlocks(type) { return generatePartBlocks(type, this.#data); } getList(type) { return getList(type, this.#data); } getListNormalised(type) { return getListNormalised(type, this.#data); } /** * Gets the next ayah after the given surah and ayah */ nextAyah(surah, ayah) { return nextAyah(surah, ayah, this.#data); } /** * Gets the previous ayah before the given surah and ayah */ prevAyah(surah, ayah) { return prevAyah(surah, ayah, this.#data); } /** * Finds the juz number for a given surah and ayah */ findJuz(surah, ayah = 1) { return findJuz(surah, ayah, this.#data); } /** * Finds the juz number for a given ayah ID */ findJuzByAyahId(ayahId) { return findJuzByAyahId(ayahId, this.#data); } /** * Finds the page number for a given surah and ayah */ findPage(surah, ayah = 1) { return findPage(surah, ayah, this.#data); } /** * Finds the page number for a given ayah ID */ findPagebyAyahId(ayahId) { return findPagebyAyahId(ayahId, this.#data); } /** * Gets metadata for a specific page */ getPageMeta(pageNum) { return getPageMeta(pageNum, this.#data); } /** * Finds the manzil number for a given surah and ayah */ findManzil(surah, ayah = 1) { return findManzil(surah, ayah, this.#data); } /** * Finds the manzil number for a given ayah ID */ findManzilByAyahId(ayahId) { return findManzilByAyahId(ayahId, this.#data); } /** * Gets metadata for a specific manzil */ getManzilMeta(manzilNum) { return getManzilMeta(manzilNum, this.#data); } /** * Finds the ruku number for a given ayah ID */ findRukuByAyahId(ayahId) { return findRukuByAyahId(ayahId, this.#data); } /** * Gets metadata for a specific ruku */ getRukuMeta(rukuNum) { return getRukuMeta(rukuNum, this.#data); } /** * Gets metadata for a specific juz */ getJuzMeta(juzNum) { return getJuzMeta(juzNum, this.#data); } /** * Finds juz metadata for a given surah and ayah */ findJuzMetaBySurah(surah, ayah = 1) { return findJuzMetaBySurah(surah, ayah, this.#data); } /** * Finds juz and calculates shift between juz start and surah start */ findJuzAndShift(surah, ayah) { return findJuzAndShift(surah, ayah, this.#data); } /** * Finds juz and shift for a given ayah ID */ findJuzAndShiftByAyahId(ayahId) { return findJuzAndShiftByAyahId(ayahId, this.#data); } /** * Finds the RubAlHizb for a given surah and ayah */ findRubAlHizb(surah, ayah = 1) { return findRubAlHizb(surah, ayah, this.#data); } /** * Finds the RubAlHizb ID for a given ayah ID */ findRubAlHizbByAyahId(ayahId) { return findRubAlHizbByAyahId(ayahId, this.#data); } /** * Gets RubAlHizb data (juz, hizb, etc.) for a given ayah ID */ getRubAlHizbByAyahId(ayahId) { return getRubAlHizbByAyahId(ayahId, this.#data); } /** * Gets RubAlHizb data (juz, hizb, etc.) for a given ayah ID */ getRubAlHizb(quarterIndex) { return getRubAlHizb(quarterIndex); } /** * Gets complete RubAlHizb metadata for a given ayah ID */ getRubAlHizbMetaByAyahId(ayahId) { return getRubAlHizbMetaByAyahId(ayahId, this.#data); } /** * Gets metadata for a specific RubAlHizb */ getRubAlHizbMeta(quarterIndex) { return getRubAlHizbMeta(quarterIndex, this.#data); } /** * Finds the ThumunAlHizb ID for a given ayah ID (Qalun/Warsh only) */ findThumunAlHizbByAyahId(ayahId) { return findThumunAlHizbByAyahId(ayahId, this.#data); } /** * Finds the ThumunAlHizb ID for a given ayah ID (Qalun/Warsh only) */ findThumunAlHizb(surah, ayah = 1) { return findThumunAlHizb(surah, ayah, this.#data); } /** * Gets metadata for a specific ThumunAlHizb (Qalun/Warsh only) */ getThumunAlHizbMeta(eighthIndex) { return getThumunAlHizbMeta(eighthIndex, this.#data); } getThumunAlHizbByAyahId(ayahId) { return getThumunAlHizbByAyahId(ayahId, this.#data); } getThumunAlHizbMetaByAyahId(ayahId) { return getThumunAlHizbMetaByAyahId(ayahId, this.#data); } getThumunAlHizb(eighthIndex) { return getThumunAlHizb(eighthIndex); } /** * Gets comprehensive metadata for a specific ayah */ getAyahMeta(ayahId) { return getAyahMeta(ayahId, this.#data); } /** * Gets metadata for all ayahs in a surah */ getAyahMetasForSurah(surahNumber) { return getAyahMetasForSurah(surahNumber, this.#data); } /** * Finds the range of ayahs around a given ayah */ findRangeAroundAyah(ayahId, mode) { return findRangeAroundAyah(ayahId, mode, this.#data); } /** * Finds the range of ayahs around a given surah and ayah */ findRangeAroundSurahAyah(surah, ayah, mode) { return findRangeAroundSurahAyah(surah, ayah, mode, this.#data); } /** * Checks if an ayah is the first ayah of a juz */ isAyahJuzFirst(ayahId) { return isAyahJuzFirst(ayahId, this.#data); } /** * Checks if an ayah is the first ayah of a page */ isAyahPageFirst(ayahId) { return isAyahPageFirst(ayahId, this.#data); } /** * Checks if a surah-ayah combination is the first ayah of a juz */ isSurahAyahJuzFirst(surah, ayah) { return isSurahAyahJuzFirst(surah, ayah, this.#data); } /** * Checks if a surah-ayah combination is the first ayah of a page */ isSurahAyahPageFirst(surah, ayah) { return isSurahAyahPageFirst(surah, ayah, this.#data); } isValidAyahId(x) { return isValidAyahId(x, this.#meta); } isValidPage(x) { return isValidPage(x, this.#meta); } isValidSurah(x) { return isValidSurah(x, this.#meta); } isValidJuz(x) { return isValidJuz(x, this.#meta); } isValidRuku(x) { return isValidRuku(x, this.#meta); } isValidSurahAyah(x) { return isValidSurahAyah(x, this.#data); } static isValidAyahNo(x) { return isValidAyahNo(x); } surahStringParser(str, isStrict = false) { return surahStringParser(str, isStrict, this.#meta); } static string2NumberSplitter(str) { return string2NumberSplitter(str); } /** * Gets the riwaya name */ get riwayaName() { return this.#riwaya; } /** * Gets the metadata for this riwaya */ get meta() { return this.#meta; } /** * Gets the metadata for this riwaya */ get lists() { return this.#data; } }; //#endregion export { QuranRiwaya };