quran-meta
Version:
Library with meta data and functionality related to Holy Quran
33 lines (32 loc) • 1.21 kB
JavaScript
import { meta } from "./const.mjs";
import { getAyahCountInSurah } from "./getAyahCountInSurah.mjs";
export function checkValidSurah(surah, checkOnly = false) {
if (typeof surah !== "number" || !Number.isInteger(surah)) {
if (checkOnly) return false;
throw new TypeError("Ayah ID must be an integer");
}
if (surah < 1 || surah > meta.numSurahs) {
if (checkOnly) return false;
throw new RangeError("Surah must be between 1 and " + meta.numSurahs);
}
return true;
}
export function checkValidSurahAyah(surah, ayah, checkOnly = false) {
if (!checkValidSurah(surah, checkOnly)) return false;
if (ayah < 1 || ayah > getAyahCountInSurah(surah)) {
if (checkOnly) return false;
throw new RangeError("Ayah must be between 1 and " + getAyahCountInSurah(surah));
}
return true;
}
export function checkValidAyahId(ayahId, checkOnly = false) {
if (typeof ayahId !== "number" || !Number.isInteger(ayahId)) {
if (checkOnly) return false;
throw new TypeError("Ayah ID must be an integer");
}
if (ayahId < 1 || ayahId > meta.numAyahs) {
if (checkOnly) return false;
throw new RangeError("Ayah ID must be between 1 and " + meta.numAyahs);
}
return true;
}