"use strict"; exports.id = 41051; exports.ids = [41051]; exports.modules = { /***/ 94007: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "Nl": () => (/* binding */ getMushafLinesNumber), /* harmony export */ "Uh": () => (/* binding */ PAGES_MUSHAF_MAP), /* harmony export */ "p6": () => (/* binding */ getPageIdsByMushaf) /* harmony export */ }); /* unused harmony exports isFirstPage, isLastPage */ /* harmony import */ var _locale__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(24709); /* harmony import */ var types_QuranReader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(50467); const DEFAULT_NUMBER_OF_PAGES = 604; // a map between the mushafId and the number of pages it has const PAGES_MUSHAF_MAP = { [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.Indopak */ .RA.Indopak]: 604, [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.KFGQPCHAFS */ .RA.KFGQPCHAFS]: 604, [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.QCFV1 */ .RA.QCFV1]: 604, [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.QCFV2 */ .RA.QCFV2]: 604, [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.UthmaniHafs */ .RA.UthmaniHafs]: 604, [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.Indopak16Lines */ .RA.Indopak16Lines]: 548, [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.Indopak15Lines */ .RA.Indopak15Lines]: 610, [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.Tajweeed */ .RA.Tajweeed]: 604 }; /** * Whether the current page is the first page. * * @param {number} surahNumber * @returns {boolean} */ const isFirstPage = (surahNumber)=>surahNumber === 1; /** * Whether the current page is the last page. * * @param {number} pageNumber * @param {QuranFont} quranFont * @param {MushafLines} mushafLines * @returns {boolean} */ const isLastPage = (pageNumber, quranFont, mushafLines)=>pageNumber === getMushafTotalPageNumber(quranFont, mushafLines); /** * Get the number of pages of the current mushaf based on the selected font * and the number of line (in the case of IndoPak). * * @param {QuranFont} quranFont * @param {MushafLines} mushafLines * @returns {number} */ const getMushafTotalPageNumber = (quranFont, mushafLines)=>{ let mushafTotalPages = 0; // this is when we are SSR the page because those 2 values won't be there since they come from Redux if (!quranFont || !mushafLines) { mushafTotalPages = DEFAULT_NUMBER_OF_PAGES; } else if (quranFont === types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .QuranFont.IndoPak */ .fr.IndoPak) { mushafTotalPages = mushafLines === types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .MushafLines.SixteenLines */ .AN.SixteenLines ? PAGES_MUSHAF_MAP[types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.Indopak16Lines */ .RA.Indopak16Lines] : PAGES_MUSHAF_MAP[types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.Indopak15Lines */ .RA.Indopak15Lines]; } else { mushafTotalPages = PAGES_MUSHAF_MAP[types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .QuranFontMushaf */ .ru[quranFont]]; } return mushafTotalPages; }; /** * Return array of page id * * @returns {{value: number, label: string}[]} */ const getPageIdsByMushaf = (lang, quranFont, mushafLines)=>[ ...Array(getMushafTotalPageNumber(quranFont, mushafLines)) ].map((n, index)=>{ const page = index + 1; return { value: page, label: (0,_locale__WEBPACK_IMPORTED_MODULE_0__/* .toLocalizedNumber */ .rQ)(page, lang) }; }); /** * Get the number of lines in a Mushaf page based on the Mushaf. * All Mushafs have 15 lines except for Indopak 16-line one. * * @param {QuranFont} quranFont * @param {MushafLines} mushafLines * @returns {number} */ const getMushafLinesNumber = (quranFont, mushafLines)=>{ if (quranFont !== types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .QuranFont.IndoPak */ .fr.IndoPak || quranFont === types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .QuranFont.IndoPak */ .fr.IndoPak && mushafLines === types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .MushafLines.FifteenLines */ .AN.FifteenLines) { return 15; } return 16; }; /***/ }), /***/ 41051: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "CG": () => (/* binding */ isValidVerseKey), /* harmony export */ "GX": () => (/* binding */ isValidRubId), /* harmony export */ "IT": () => (/* binding */ isValidVerseRange), /* harmony export */ "LX": () => (/* binding */ getToAndFromFromRange), /* harmony export */ "eg": () => (/* binding */ isValidJuzId), /* harmony export */ "hP": () => (/* binding */ isValidChapterId), /* harmony export */ "it": () => (/* binding */ isValidVerseNumber), /* harmony export */ "tW": () => (/* binding */ isValidVerseId), /* harmony export */ "vU": () => (/* binding */ isValidPageNumber), /* harmony export */ "xI": () => (/* binding */ isValidHizbId), /* harmony export */ "z5": () => (/* binding */ isRangesStringValid) /* harmony export */ }); /* unused harmony export isValidTafsirId */ /* harmony import */ var _chapter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(95892); /* harmony import */ var _page__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(94007); /* harmony import */ var _verseKeys__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(36495); /** * Validate a chapterId which can be in-valid in 2 cases: * * 1. if it's a string that is not numeric e.g. "test". * 2. if it's a numeric string but lies outside the range 1->114. * * @param {string} chapterId * @returns {boolean} */ const isValidChapterId = (chapterId)=>{ const chapterIdNumber = Number(chapterId); // if it's not a numeric string or it's numeric but out of the range of chapter 1->114 if (Number.isNaN(chapterIdNumber) || chapterIdNumber > 114 || chapterIdNumber < 1) { return false; } return true; }; /** * Check whether the verse number is valid by trying to convert it * into a number. * * @param {string} verseId * @returns {boolean} */ const isValidVerseNumber = (verseId)=>{ const verseIdNumber = Number(verseId); return !Number.isNaN(verseIdNumber); }; /** * Validate a verseId which can be in-valid in 3 cases: * * 1. if it's a string that is not numeric e.g. "test". * 2. if it's a numeric string but below 1. * 3. if it's a numeric string but above the maximum number of verses for the chapter. e.g. verseId 8 for chapterId 1 (Alfatiha) is invalid since it only has 7 verses. * * @param {ChaptersData} chaptersData * @param {string} chapterId the chapter id. We will assume it's valid since we already validated it. * @param {string} verseId the verse id being validated. * @returns {boolean} */ const isValidVerseId = (chaptersData, chapterId, verseId)=>{ const verseIdNumber = Number(verseId); // is not a valid number, below 1 or above the maximum number of verses for the chapter. if (Number.isNaN(verseIdNumber) || verseIdNumber < 1) { return false; } if (!(0,_chapter__WEBPACK_IMPORTED_MODULE_0__/* .getChapterData */ .dy)(chaptersData, chapterId) || verseIdNumber > (0,_chapter__WEBPACK_IMPORTED_MODULE_0__/* .getChapterData */ .dy)(chaptersData, chapterId).versesCount) { return false; } return true; }; /** * Validate a juzId which can be in-valid in 2 cases: * * 1. if it's a string that is not numeric e.g. "test". * 2. if it's a numeric string but lies outside the range 1->30. * * @param {string} juzId * @returns {boolean} */ const isValidJuzId = (juzId)=>{ const juzIdNumber = Number(juzId); // if it's not a numeric string or it's numeric but out of the range of chapter 1->30 if (Number.isNaN(juzIdNumber) || juzIdNumber > 30 || juzIdNumber < 1) { return false; } return true; }; /** * Validate a rubId which can be in-valid in 2 cases: * * 1. if it's a string that is not numeric e.g. "test". * 2. if it's a numeric string but lies outside the range 1->240. * * @param {string} rubId * @returns {boolean} */ const isValidRubId = (rubId)=>{ const rubIdNumber = Number(rubId); // if it's not a numeric string or it's numeric but out of the range of chapter 1->240 if (Number.isNaN(rubIdNumber) || rubIdNumber > 240 || rubIdNumber < 1) { return false; } return true; }; /** * Validate a hizbId which can be in-valid in 2 cases: * * 1. if it's a string that is not numeric e.g. "test". * 2. if it's a numeric string but lies outside the range 1->60. * * @param {string} hizbId * @returns {boolean} */ const isValidHizbId = (hizbId)=>{ const hizbIdNumber = Number(hizbId); // if it's not a numeric string or it's numeric but out of the range of chapter 1->30 if (Number.isNaN(hizbIdNumber) || hizbIdNumber > 60 || hizbIdNumber < 1) { return false; } return true; }; /** * Validate a pageId which can be in-valid in 2 cases: * * 1. if it's a string that is not numeric e.g. "test". * 2. if it's a numeric string but lies outside the range of the selected Mushaf. * * @param {string | number} pageId * @returns {boolean} */ const isValidPageNumber = (pageId, mushafId)=>{ const pageIdNumber = Number(pageId); const MUSHAF_COUNT = _page__WEBPACK_IMPORTED_MODULE_1__/* .PAGES_MUSHAF_MAP */ .Uh[mushafId]; // if it's not a numeric string or it's numeric but out of the range of the selected Mushaf if (Number.isNaN(pageIdNumber) || pageIdNumber > MUSHAF_COUNT || pageIdNumber < 1) { return false; } return true; }; /** * Extract the to and from verse by splitting the range by '-'. * * @param {string} range * @returns {string[]} */ const getToAndFromFromRange = (range)=>range.split("-"); /** * This is to check if the range passed is valid or not. It won't be valid if: * * 1. The format is not a range's format and this is known if after splitting the range string * by '-', we don't have 2 parts for the range representing the from verse and to verse. * e.g. 'one' * 2. If after splitting them, either of the 2 parts are not a valid number e.g. 'one-two' * or '1-two' or 'one-2'. * 3. If the from verse number exceeds the to verse number. e.g. '8-7'. * 4. If either the from verse number of to verse number exceeds the total number of verses * for the current chapter e.g. for chapter 1: '7-8' or '8-8'. * * @param {ChaptersData} chaptersData * @param {string} chapterId * @param {string} range * @returns {boolean} */ const isValidVerseRange = (chaptersData, chapterId, range)=>{ const rangeSplits = getToAndFromFromRange(range); // if the splits are not 2, it means it's not in the right format. if (rangeSplits.length !== 2) { return false; } const [from, to] = rangeSplits; const fromNumber = Number(from); const toNumber = Number(to); // if the range is in the right format but either value is not a number e.g. 'one-two' if (Number.isNaN(fromNumber) || Number.isNaN(toNumber)) { return false; } // 0 is not a valid verse number if (fromNumber === 0 || toNumber === 0) { return false; } // if the from verse number is bigger than the to verse number if (fromNumber > toNumber) { return false; } // if the chapterId is not a valid chapterId e.g. "word" if (!(0,_chapter__WEBPACK_IMPORTED_MODULE_0__/* .getChapterData */ .dy)(chaptersData, chapterId)) { return false; } const chapterVersesCount = (0,_chapter__WEBPACK_IMPORTED_MODULE_0__/* .getChapterData */ .dy)(chaptersData, chapterId).versesCount; // if either the from verse number of to verse number exceeds the chapter's total number. if (fromNumber > chapterVersesCount || toNumber > chapterVersesCount) { return false; } return true; }; /** * Check if a string range is valid or not. * A valid range looks like this: "1:1-1:2" or "1:1-2:3". * * @param {ChaptersData} chaptersData * @param {string} rangesString * @returns {boolean} */ const isRangesStringValid = (chaptersData, rangesString)=>{ const parsedVerseRange = (0,_verseKeys__WEBPACK_IMPORTED_MODULE_2__/* .parseVerseRange */ .p)(rangesString); // 1. if the range is not in the right format if (!parsedVerseRange) { return false; } const [fromRange, toRange] = parsedVerseRange; // if both ranges are in the same chapter if (fromRange.chapter === toRange.chapter) { const verseRange = `${fromRange.verse}-${toRange.verse}`; // 2. if range within same surah is not valid if (!isValidVerseRange(chaptersData, fromRange.chapter, verseRange)) { return false; } } else { // 2. if start of range verse key is not valid if (!isValidVerseKey(chaptersData, fromRange.verseKey)) { return false; } // 3. if end of range verse key is not valid if (!isValidVerseKey(chaptersData, toRange.verseKey)) { return false; } // 4. if the fromRange chapter is bigger than the toRange chapter e.g. 2:1-1:1 if (Number(fromRange.chapter) > Number(toRange.chapter)) { return false; } } return true; }; /** * Check if a verse key is valid. An invalid verse key can be: * * 1. it's in a wrong format e.g. "verseKey" * 2. if the number of parts is bigger than 2 e.g. "1:2:3" * 3. if it's not a valid chapter id {@see isValidChapterId} * 4. if it's not a valid verse ID {@see isValidVerseId} * * @param {ChaptersData} chaptersData * @param {string} verseKey * @returns {boolean} */ const isValidVerseKey = (chaptersData, verseKey)=>{ const splits = verseKey.split(":"); // if the splits are not 2, it means it's not in the right format. if (splits.length !== 2) { return false; } const [chapterId, verseId] = splits; // if either value is not a number e.g. 'one:2' or if the verseNumber is below 0 if (!isValidChapterId(chapterId) || !isValidVerseId(chaptersData, chapterId, verseId)) { return false; } return true; }; /** * Check whether a tafsir id is valid or not. An invalid tafsirId can be: * 1. A non numeric value. * 2. A numeric value that is less than 0. * * @param {string} tafsirId * @returns {boolean} */ const isValidTafsirId = (tafsirId)=>{ const tafsirIdNumber = Number(tafsirId); // if the tafsir Id is not a number of if it's below 1 if (Number.isNaN(tafsirIdNumber) || tafsirIdNumber < 1) { return false; } return true; }; /***/ }) }; ; //# sourceMappingURL=41051.js.map