quran-meta
Version:
Library with meta data and functionality related to Holy Quran
57 lines (55 loc) • 2.48 kB
JavaScript
const require_surahList = require('./lists/surahList.cjs');
const require_validation = require('./validation.cjs');
const require_findAyahIdBySurah = require('./findAyahIdBySurah.cjs');
const require_juzList = require('./lists/juzList.cjs');
const require_findJuzByAyahId = require('./findJuzByAyahId.cjs');
const require_findSurahByAyahId = require('./findSurahByAyahId.cjs');
//#region src/findJuzAndShift.ts
/**
* Finds the juz (section) that contains the specified ayah (verse) and calculates the number of ayahs between the start of the juz and the start of the surah (chapter) that contains the ayah.
*
* @param surah - The surah (chapter) that contains the ayah.
* @param ayah - The ayah (verse) number.
* @returns An object containing the following properties:
* - `juz`: The juz (section) that contains the ayah.
* - `leftAyahId`: The ayah ID of the first ayah in the juz.
* - `ayahsBetweenJuzSurah`: The number of ayahs between the start of the juz and the start of the surah (positive if the surah starts is in the juz, negative if the surah starts before the juz).
*/
function findJuzAndShift(surah, ayah) {
const ayahId = require_findAyahIdBySurah.findAyahIdBySurah(surah, ayah);
const juz = require_findJuzByAyahId.findJuzByAyahId(ayahId);
const juzLeftAyahId = require_juzList.JuzList[juz];
const [surahStartAyahId] = require_surahList.SurahList[surah];
return {
juz,
ayahsBetweenJuzSurah: surahStartAyahId - juzLeftAyahId,
leftAyahId: juzLeftAyahId
};
}
/**
* Finds the Juz number and calculates the shift between Juz start and Surah start for a given Ayah ID
*
* @param ayahId - The unique identifier of an Ayah (verse) in the Quran
*
* @returns An object containing:
* - juz: The Juz number where the Ayah is located
* - leftAyahId: The starting Ayah ID of the Juz
* - ayahsBetweenJuzSurah: The number of Ayahs between the Juz start and the Surah start
*
* @throws Error If the provided Ayah ID is invalid
*/
function findJuzAndShiftByAyahId(ayahId) {
require_validation.checkValidAyahId(ayahId);
const juz = require_findJuzByAyahId.findJuzByAyahId(ayahId);
const leftAyahId = require_juzList.JuzList[juz];
const surah = require_findSurahByAyahId.findSurahByAyahId(ayahId);
const [surahStartAyahId] = require_surahList.SurahList[surah];
return {
juz,
ayahsBetweenJuzSurah: surahStartAyahId - leftAyahId,
leftAyahId
};
}
//#endregion
exports.findJuzAndShift = findJuzAndShift;
exports.findJuzAndShiftByAyahId = findJuzAndShiftByAyahId;