quran-meta
Version:
Library with meta data and functionality related to Holy Quran
40 lines (39 loc) • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.checkValidAyahId = checkValidAyahId;
exports.checkValidSurah = checkValidSurah;
exports.checkValidSurahAyah = checkValidSurahAyah;
var _const = require("./const.cjs");
var _getAyahCountInSurah = require("./getAyahCountInSurah.cjs");
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 > _const.meta.numSurahs) {
if (checkOnly) return false;
throw new RangeError("Surah must be between 1 and " + _const.meta.numSurahs);
}
return true;
}
function checkValidSurahAyah(surah, ayah, checkOnly = false) {
if (!checkValidSurah(surah, checkOnly)) return false;
if (ayah < 1 || ayah > (0, _getAyahCountInSurah.getAyahCountInSurah)(surah)) {
if (checkOnly) return false;
throw new RangeError("Ayah must be between 1 and " + (0, _getAyahCountInSurah.getAyahCountInSurah)(surah));
}
return true;
}
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 > _const.meta.numAyahs) {
if (checkOnly) return false;
throw new RangeError("Ayah ID must be between 1 and " + _const.meta.numAyahs);
}
return true;
}