quran-meta
Version:
Library with meta data and functionality related to Holy Quran
35 lines (34 loc) • 998 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ayahStringSplitter = ayahStringSplitter;
var _validation = require("./validation.cjs");
function ayahStringSplitter(str) {
const [surahStr, ayahsStr] = str.trim().split(":");
const surah = parseInt(surahStr, 10);
if (isNaN(surah)) {
throw new Error("Error in surah format " + str);
}
if (!ayahsStr) {
throw new Error("Error in data " + str);
}
let ayahs;
if (ayahsStr.includes("-")) {
ayahs = ayahsStr.split("-").map(a => {
const ayah = parseInt(a, 10);
if (isNaN(ayah) || ayah === 0) {
throw new Error("Error in ayah " + a);
}
return ayah;
});
if (ayahs[0] > ayahs[1]) throw new Error("Error in ayah range " + str);
} else {
ayahs = parseInt(ayahsStr, 10);
if (isNaN(ayahs) || ayahs === 0) {
throw new Error("Error in data " + str);
}
(0, _validation.checkValidSurahAyah)(surah, ayahs);
}
return [surah, ayahs];
}