41051.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. "use strict";
  2. exports.id = 41051;
  3. exports.ids = [41051];
  4. exports.modules = {
  5. /***/ 94007:
  6. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  7. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  8. /* harmony export */ "Nl": () => (/* binding */ getMushafLinesNumber),
  9. /* harmony export */ "Uh": () => (/* binding */ PAGES_MUSHAF_MAP),
  10. /* harmony export */ "p6": () => (/* binding */ getPageIdsByMushaf)
  11. /* harmony export */ });
  12. /* unused harmony exports isFirstPage, isLastPage */
  13. /* harmony import */ var _locale__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(24709);
  14. /* harmony import */ var types_QuranReader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(50467);
  15. const DEFAULT_NUMBER_OF_PAGES = 604;
  16. // a map between the mushafId and the number of pages it has
  17. const PAGES_MUSHAF_MAP = {
  18. [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.Indopak */ .RA.Indopak]: 604,
  19. [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.KFGQPCHAFS */ .RA.KFGQPCHAFS]: 604,
  20. [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.QCFV1 */ .RA.QCFV1]: 604,
  21. [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.QCFV2 */ .RA.QCFV2]: 604,
  22. [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.UthmaniHafs */ .RA.UthmaniHafs]: 604,
  23. [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.Indopak16Lines */ .RA.Indopak16Lines]: 548,
  24. [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.Indopak15Lines */ .RA.Indopak15Lines]: 610,
  25. [types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .Mushaf.Tajweeed */ .RA.Tajweeed]: 604
  26. };
  27. /**
  28. * Whether the current page is the first page.
  29. *
  30. * @param {number} surahNumber
  31. * @returns {boolean}
  32. */ const isFirstPage = (surahNumber)=>surahNumber === 1;
  33. /**
  34. * Whether the current page is the last page.
  35. *
  36. * @param {number} pageNumber
  37. * @param {QuranFont} quranFont
  38. * @param {MushafLines} mushafLines
  39. * @returns {boolean}
  40. */ const isLastPage = (pageNumber, quranFont, mushafLines)=>pageNumber === getMushafTotalPageNumber(quranFont, mushafLines);
  41. /**
  42. * Get the number of pages of the current mushaf based on the selected font
  43. * and the number of line (in the case of IndoPak).
  44. *
  45. * @param {QuranFont} quranFont
  46. * @param {MushafLines} mushafLines
  47. * @returns {number}
  48. */ const getMushafTotalPageNumber = (quranFont, mushafLines)=>{
  49. let mushafTotalPages = 0;
  50. // this is when we are SSR the page because those 2 values won't be there since they come from Redux
  51. if (!quranFont || !mushafLines) {
  52. mushafTotalPages = DEFAULT_NUMBER_OF_PAGES;
  53. } else if (quranFont === types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .QuranFont.IndoPak */ .fr.IndoPak) {
  54. 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];
  55. } else {
  56. mushafTotalPages = PAGES_MUSHAF_MAP[types_QuranReader__WEBPACK_IMPORTED_MODULE_1__/* .QuranFontMushaf */ .ru[quranFont]];
  57. }
  58. return mushafTotalPages;
  59. };
  60. /**
  61. * Return array of page id
  62. *
  63. * @returns {{value: number, label: string}[]}
  64. */ const getPageIdsByMushaf = (lang, quranFont, mushafLines)=>[
  65. ...Array(getMushafTotalPageNumber(quranFont, mushafLines))
  66. ].map((n, index)=>{
  67. const page = index + 1;
  68. return {
  69. value: page,
  70. label: (0,_locale__WEBPACK_IMPORTED_MODULE_0__/* .toLocalizedNumber */ .rQ)(page, lang)
  71. };
  72. });
  73. /**
  74. * Get the number of lines in a Mushaf page based on the Mushaf.
  75. * All Mushafs have 15 lines except for Indopak 16-line one.
  76. *
  77. * @param {QuranFont} quranFont
  78. * @param {MushafLines} mushafLines
  79. * @returns {number}
  80. */ const getMushafLinesNumber = (quranFont, mushafLines)=>{
  81. 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) {
  82. return 15;
  83. }
  84. return 16;
  85. };
  86. /***/ }),
  87. /***/ 41051:
  88. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  89. /* harmony export */ __webpack_require__.d(__webpack_exports__, {
  90. /* harmony export */ "CG": () => (/* binding */ isValidVerseKey),
  91. /* harmony export */ "GX": () => (/* binding */ isValidRubId),
  92. /* harmony export */ "IT": () => (/* binding */ isValidVerseRange),
  93. /* harmony export */ "LX": () => (/* binding */ getToAndFromFromRange),
  94. /* harmony export */ "eg": () => (/* binding */ isValidJuzId),
  95. /* harmony export */ "hP": () => (/* binding */ isValidChapterId),
  96. /* harmony export */ "it": () => (/* binding */ isValidVerseNumber),
  97. /* harmony export */ "tW": () => (/* binding */ isValidVerseId),
  98. /* harmony export */ "vU": () => (/* binding */ isValidPageNumber),
  99. /* harmony export */ "xI": () => (/* binding */ isValidHizbId),
  100. /* harmony export */ "z5": () => (/* binding */ isRangesStringValid)
  101. /* harmony export */ });
  102. /* unused harmony export isValidTafsirId */
  103. /* harmony import */ var _chapter__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(95892);
  104. /* harmony import */ var _page__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(94007);
  105. /* harmony import */ var _verseKeys__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(36495);
  106. /**
  107. * Validate a chapterId which can be in-valid in 2 cases:
  108. *
  109. * 1. if it's a string that is not numeric e.g. "test".
  110. * 2. if it's a numeric string but lies outside the range 1->114.
  111. *
  112. * @param {string} chapterId
  113. * @returns {boolean}
  114. */ const isValidChapterId = (chapterId)=>{
  115. const chapterIdNumber = Number(chapterId);
  116. // if it's not a numeric string or it's numeric but out of the range of chapter 1->114
  117. if (Number.isNaN(chapterIdNumber) || chapterIdNumber > 114 || chapterIdNumber < 1) {
  118. return false;
  119. }
  120. return true;
  121. };
  122. /**
  123. * Check whether the verse number is valid by trying to convert it
  124. * into a number.
  125. *
  126. * @param {string} verseId
  127. * @returns {boolean}
  128. */ const isValidVerseNumber = (verseId)=>{
  129. const verseIdNumber = Number(verseId);
  130. return !Number.isNaN(verseIdNumber);
  131. };
  132. /**
  133. * Validate a verseId which can be in-valid in 3 cases:
  134. *
  135. * 1. if it's a string that is not numeric e.g. "test".
  136. * 2. if it's a numeric string but below 1.
  137. * 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.
  138. *
  139. * @param {ChaptersData} chaptersData
  140. * @param {string} chapterId the chapter id. We will assume it's valid since we already validated it.
  141. * @param {string} verseId the verse id being validated.
  142. * @returns {boolean}
  143. */ const isValidVerseId = (chaptersData, chapterId, verseId)=>{
  144. const verseIdNumber = Number(verseId);
  145. // is not a valid number, below 1 or above the maximum number of verses for the chapter.
  146. if (Number.isNaN(verseIdNumber) || verseIdNumber < 1) {
  147. return false;
  148. }
  149. if (!(0,_chapter__WEBPACK_IMPORTED_MODULE_0__/* .getChapterData */ .dy)(chaptersData, chapterId) || verseIdNumber > (0,_chapter__WEBPACK_IMPORTED_MODULE_0__/* .getChapterData */ .dy)(chaptersData, chapterId).versesCount) {
  150. return false;
  151. }
  152. return true;
  153. };
  154. /**
  155. * Validate a juzId which can be in-valid in 2 cases:
  156. *
  157. * 1. if it's a string that is not numeric e.g. "test".
  158. * 2. if it's a numeric string but lies outside the range 1->30.
  159. *
  160. * @param {string} juzId
  161. * @returns {boolean}
  162. */ const isValidJuzId = (juzId)=>{
  163. const juzIdNumber = Number(juzId);
  164. // if it's not a numeric string or it's numeric but out of the range of chapter 1->30
  165. if (Number.isNaN(juzIdNumber) || juzIdNumber > 30 || juzIdNumber < 1) {
  166. return false;
  167. }
  168. return true;
  169. };
  170. /**
  171. * Validate a rubId which can be in-valid in 2 cases:
  172. *
  173. * 1. if it's a string that is not numeric e.g. "test".
  174. * 2. if it's a numeric string but lies outside the range 1->240.
  175. *
  176. * @param {string} rubId
  177. * @returns {boolean}
  178. */ const isValidRubId = (rubId)=>{
  179. const rubIdNumber = Number(rubId);
  180. // if it's not a numeric string or it's numeric but out of the range of chapter 1->240
  181. if (Number.isNaN(rubIdNumber) || rubIdNumber > 240 || rubIdNumber < 1) {
  182. return false;
  183. }
  184. return true;
  185. };
  186. /**
  187. * Validate a hizbId which can be in-valid in 2 cases:
  188. *
  189. * 1. if it's a string that is not numeric e.g. "test".
  190. * 2. if it's a numeric string but lies outside the range 1->60.
  191. *
  192. * @param {string} hizbId
  193. * @returns {boolean}
  194. */ const isValidHizbId = (hizbId)=>{
  195. const hizbIdNumber = Number(hizbId);
  196. // if it's not a numeric string or it's numeric but out of the range of chapter 1->30
  197. if (Number.isNaN(hizbIdNumber) || hizbIdNumber > 60 || hizbIdNumber < 1) {
  198. return false;
  199. }
  200. return true;
  201. };
  202. /**
  203. * Validate a pageId which can be in-valid in 2 cases:
  204. *
  205. * 1. if it's a string that is not numeric e.g. "test".
  206. * 2. if it's a numeric string but lies outside the range of the selected Mushaf.
  207. *
  208. * @param {string | number} pageId
  209. * @returns {boolean}
  210. */ const isValidPageNumber = (pageId, mushafId)=>{
  211. const pageIdNumber = Number(pageId);
  212. const MUSHAF_COUNT = _page__WEBPACK_IMPORTED_MODULE_1__/* .PAGES_MUSHAF_MAP */ .Uh[mushafId];
  213. // if it's not a numeric string or it's numeric but out of the range of the selected Mushaf
  214. if (Number.isNaN(pageIdNumber) || pageIdNumber > MUSHAF_COUNT || pageIdNumber < 1) {
  215. return false;
  216. }
  217. return true;
  218. };
  219. /**
  220. * Extract the to and from verse by splitting the range by '-'.
  221. *
  222. * @param {string} range
  223. * @returns {string[]}
  224. */ const getToAndFromFromRange = (range)=>range.split("-");
  225. /**
  226. * This is to check if the range passed is valid or not. It won't be valid if:
  227. *
  228. * 1. The format is not a range's format and this is known if after splitting the range string
  229. * by '-', we don't have 2 parts for the range representing the from verse and to verse.
  230. * e.g. 'one'
  231. * 2. If after splitting them, either of the 2 parts are not a valid number e.g. 'one-two'
  232. * or '1-two' or 'one-2'.
  233. * 3. If the from verse number exceeds the to verse number. e.g. '8-7'.
  234. * 4. If either the from verse number of to verse number exceeds the total number of verses
  235. * for the current chapter e.g. for chapter 1: '7-8' or '8-8'.
  236. *
  237. * @param {ChaptersData} chaptersData
  238. * @param {string} chapterId
  239. * @param {string} range
  240. * @returns {boolean}
  241. */ const isValidVerseRange = (chaptersData, chapterId, range)=>{
  242. const rangeSplits = getToAndFromFromRange(range);
  243. // if the splits are not 2, it means it's not in the right format.
  244. if (rangeSplits.length !== 2) {
  245. return false;
  246. }
  247. const [from, to] = rangeSplits;
  248. const fromNumber = Number(from);
  249. const toNumber = Number(to);
  250. // if the range is in the right format but either value is not a number e.g. 'one-two'
  251. if (Number.isNaN(fromNumber) || Number.isNaN(toNumber)) {
  252. return false;
  253. }
  254. // 0 is not a valid verse number
  255. if (fromNumber === 0 || toNumber === 0) {
  256. return false;
  257. }
  258. // if the from verse number is bigger than the to verse number
  259. if (fromNumber > toNumber) {
  260. return false;
  261. }
  262. // if the chapterId is not a valid chapterId e.g. "word"
  263. if (!(0,_chapter__WEBPACK_IMPORTED_MODULE_0__/* .getChapterData */ .dy)(chaptersData, chapterId)) {
  264. return false;
  265. }
  266. const chapterVersesCount = (0,_chapter__WEBPACK_IMPORTED_MODULE_0__/* .getChapterData */ .dy)(chaptersData, chapterId).versesCount;
  267. // if either the from verse number of to verse number exceeds the chapter's total number.
  268. if (fromNumber > chapterVersesCount || toNumber > chapterVersesCount) {
  269. return false;
  270. }
  271. return true;
  272. };
  273. /**
  274. * Check if a string range is valid or not.
  275. * A valid range looks like this: "1:1-1:2" or "1:1-2:3".
  276. *
  277. * @param {ChaptersData} chaptersData
  278. * @param {string} rangesString
  279. * @returns {boolean}
  280. */ const isRangesStringValid = (chaptersData, rangesString)=>{
  281. const parsedVerseRange = (0,_verseKeys__WEBPACK_IMPORTED_MODULE_2__/* .parseVerseRange */ .p)(rangesString);
  282. // 1. if the range is not in the right format
  283. if (!parsedVerseRange) {
  284. return false;
  285. }
  286. const [fromRange, toRange] = parsedVerseRange;
  287. // if both ranges are in the same chapter
  288. if (fromRange.chapter === toRange.chapter) {
  289. const verseRange = `${fromRange.verse}-${toRange.verse}`;
  290. // 2. if range within same surah is not valid
  291. if (!isValidVerseRange(chaptersData, fromRange.chapter, verseRange)) {
  292. return false;
  293. }
  294. } else {
  295. // 2. if start of range verse key is not valid
  296. if (!isValidVerseKey(chaptersData, fromRange.verseKey)) {
  297. return false;
  298. }
  299. // 3. if end of range verse key is not valid
  300. if (!isValidVerseKey(chaptersData, toRange.verseKey)) {
  301. return false;
  302. }
  303. // 4. if the fromRange chapter is bigger than the toRange chapter e.g. 2:1-1:1
  304. if (Number(fromRange.chapter) > Number(toRange.chapter)) {
  305. return false;
  306. }
  307. }
  308. return true;
  309. };
  310. /**
  311. * Check if a verse key is valid. An invalid verse key can be:
  312. *
  313. * 1. it's in a wrong format e.g. "verseKey"
  314. * 2. if the number of parts is bigger than 2 e.g. "1:2:3"
  315. * 3. if it's not a valid chapter id {@see isValidChapterId}
  316. * 4. if it's not a valid verse ID {@see isValidVerseId}
  317. *
  318. * @param {ChaptersData} chaptersData
  319. * @param {string} verseKey
  320. * @returns {boolean}
  321. */ const isValidVerseKey = (chaptersData, verseKey)=>{
  322. const splits = verseKey.split(":");
  323. // if the splits are not 2, it means it's not in the right format.
  324. if (splits.length !== 2) {
  325. return false;
  326. }
  327. const [chapterId, verseId] = splits;
  328. // if either value is not a number e.g. 'one:2' or if the verseNumber is below 0
  329. if (!isValidChapterId(chapterId) || !isValidVerseId(chaptersData, chapterId, verseId)) {
  330. return false;
  331. }
  332. return true;
  333. };
  334. /**
  335. * Check whether a tafsir id is valid or not. An invalid tafsirId can be:
  336. * 1. A non numeric value.
  337. * 2. A numeric value that is less than 0.
  338. *
  339. * @param {string} tafsirId
  340. * @returns {boolean}
  341. */ const isValidTafsirId = (tafsirId)=>{
  342. const tafsirIdNumber = Number(tafsirId);
  343. // if the tafsir Id is not a number of if it's below 1
  344. if (Number.isNaN(tafsirIdNumber) || tafsirIdNumber < 1) {
  345. return false;
  346. }
  347. return true;
  348. };
  349. /***/ })
  350. };
  351. ;
  352. //# sourceMappingURL=41051.js.map