Skip to content

Commit 01ce7d5

Browse files
committed
feat: add updated SurahMeta
1 parent 21303f7 commit 01ce7d5

17 files changed

+171
-44
lines changed

examples/data-check/checkQuranApi.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77

8-
import { findPagebyAyahId, findAyahIdBySurah, findJuz, findRubAlHizb, getAyahMeta, getRubAlHizbMetaByAyahId, HizbQuarterList, Juz, JuzList, ManzilList, meta, PageList, RukuList, SajdaList, Surah, SurahList, SurahInfo, getJuzMeta, getRubAlHizbMeta, getRukuMeta, getPageMeta, getManzilMeta, getSurahInfo } from "../../src"
8+
import { findPagebyAyahId, findAyahIdBySurah, findJuz, findRubAlHizb, getAyahMeta, getRubAlHizbMetaByAyahId, HizbQuarterList, Juz, JuzList, ManzilList, meta, PageList, RukuList, SajdaList, Surah, SurahList, SurahInfo, getJuzMeta, getRubAlHizbMeta, getRukuMeta, getPageMeta, getManzilMeta, getSurahInfo, getSurahMeta } from "../../src"
99
import { AyahNo, AyahId, Manzil, Page, Ruku, RubAlHizbId } from "../../src/types"
1010

1111
import quranApi from "./data/quran-api.json"
@@ -29,19 +29,18 @@ export function checkQuranApi() {
2929
}
3030

3131
for (let surahNo: Surah = 1; surahNo <= meta.numSurahs; surahNo++) {
32-
const [
33-
startAyahId,
32+
const {
33+
firstAyahId,
3434
ayahCount,
3535
surahOrder,
3636
rukuCount,
3737
name,
38-
isMeccan,
39-
page
40-
]: SurahInfo = getSurahInfo(surahNo as Surah)
38+
isMeccan
39+
} = getSurahMeta(surahNo as Surah)
4140
const { chapter, name: oName, englishname, arabicname, revelation, verses } = quranApi.chapters[surahNo - 1]
4241

4342
if (surahNo !== chapter) console.warn("error QuranApi surah: ", surahNo, chapter)
44-
if (startAyahId !== verses[0].line) console.warn("error QuranApi surah: ", startAyahId, verses[0].line)
43+
if (firstAyahId !== verses[0].line) console.warn("error QuranApi surah: ", firstAyahId, verses[0].line)
4544
if (ayahCount !== verses.length) console.warn("error QuranApi surah: ", ayahCount, verses.length)
4645
}
4746

src/ayahStringSplitter.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import { checkValidAyahId, checkValidSurahAyah } from "./validation"
77
* @param str - The string to parse, expected format: "surah:ayah" or "surah:ayahStart-ayahEnd"
88
* @param isStrict - If true, enforces strict format checking. Defaults to true. If false, allows for additional characters in the string
99
* @returns A tuple containing surah number and either a single ayah number or a range [start, end]
10-
* @throws {Error} If the string format is invalid
11-
* @throws {Error} If surah number is invalid
12-
* @throws {Error} If ayah number(s) are invalid
13-
* @throws {Error} If ayah range is invalid (start > end)
10+
* @throws {@link Error} If the string format is invalid
11+
* @throws {@link Error} If surah number is invalid
12+
* @throws {@link Error} If ayah number(s) are invalid
13+
* @throws {@link sError} If ayah range is invalid (start > end)
1414
* @example
15+
* ```ts
1516
* ayahStringSplitter("2:255") // returns [2, 255]
1617
* ayahStringSplitter("1:1-7") // returns [1, [1, 7]]
18+
* ```
1719
*/
1820
export function ayahStringSplitter(str: string, isStrict = true): SurahAyahSegment {
1921
const result = isStrict ? string2NumberSplitterStrict(str) : string2NumberSplitter(str)
@@ -82,7 +84,7 @@ export function string2NumberSplitter(str: string): { ayah?: number, ayahTo?: nu
8284
* - surahOrAyah: The surah number
8385
* - ayah: The first or only ayah number
8486
* - ayahTo: The ending ayah number (if range specified)
85-
* @throws {Error} When the input string format is invalid or contains non-numeric values
87+
* @throws {@link Error} When the input string format is invalid or contains non-numeric values
8688
*
8789
* @example
8890
* string2NumberSplitterStrict("2:255") // returns { surahOrAyah: 2, ayah: 255, ayahTo: NaN }

src/findManzilByAyahId.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { checkValidAyahId } from "./validation"
99
*
1010
* @param ayahId - The ID of the Ayah to find the Manzil for
1111
* @returns The Manzil number (1-7) containing the specified Ayah
12-
* @throws {Error} If the provided Ayah ID is invalid
12+
* @throws {@link Error} If the provided Ayah ID is invalid
1313
*
1414
* @example
1515
* ```typescript

src/findRukuByAyahId.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { checkValidAyahId } from "./validation"
88
*
99
* @param ayahId - The unique identifier of an Ayah in format: surah:ayah (e.g., "2:255")
1010
* @returns The Ruku number corresponding to the given Ayah ID
11-
* @throws {Error} If the provided Ayah ID is invalid
11+
* @throws {@link Error} If the provided Ayah ID is invalid
1212
*
1313
* @example
14-
* ```typescript
14+
* ```ts
1515
* const ruku = findRukuByAyahId("2:255");
1616
* // Returns the Ruku number containing Ayah 255 of Surah 2
1717
* ```

src/getPageMeta.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { checkValidPage } from "./validation"
77
* Retrieves metadata for a specific page of the Quran.
88
*
99
* @param pageNum - The page number to retrieve metadata for (1-604)
10-
* @returns An object containing the page number, first ayah, and last ayah on the page
11-
* @throws RangeError If the page number is not between 1 and 604
10+
* @returns {@link PageMeta} An object containing the page number, first ayah, and last ayah on the page
11+
* @throws {@link RangeError} If the page number is not between 1 and 604
1212
*/
1313
export function getPageMeta(pageNum: Page): PageMeta {
1414
checkValidPage(pageNum)

src/getRukuMeta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { checkValidRuku } from "./validation"
66
/**
77
* Retrieves metadata for a specific Ruku (section) of the Quran.
88
* @param rukuNum - The number of the Ruku to retrieve metadata for
9-
* @returns {RukuMeta} An object containing metadata about the Ruku including:
9+
* @returns {@link RukuMeta} An object containing metadata about the Ruku including:
1010
* - rukuNum: The Ruku number
1111
* - firstAyahId: The global Ayah ID of the first verse in this Ruku
1212
* - lastAyahId: The global Ayah ID of the last verse in this Ruku

src/getSurahMeta.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { getSurahInfo } from "./getSurahInfo"
2+
import { Surah, SurahMeta } from "./types"
3+
4+
/**
5+
* Gets the metadata for the specified Surah.
6+
*
7+
* @param surah - The Surah to get the metadata for.
8+
* @returns The metadata for the specified Surah.
9+
*/
10+
export function getSurahMeta(surahNum: Surah): SurahMeta {
11+
const [
12+
firstAyahId,
13+
ayahCount,
14+
surahOrder,
15+
rukuCount,
16+
name,
17+
isMeccan
18+
] = getSurahInfo(surahNum)
19+
20+
const lastAyahId = firstAyahId + ayahCount - 1
21+
return {
22+
surahNum,
23+
ayahCount,
24+
surahOrder,
25+
rukuCount,
26+
name,
27+
isMeccan,
28+
firstAyahId,
29+
lastAyahId,
30+
first: [surahNum, 1],
31+
last: [surahNum, ayahCount]
32+
}
33+
}

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export { getRubAlHizb } from "./getRubAlHizb"
3434
export { getRubAlHizbMeta } from "./getRubAlHizbMeta"
3535
export { getRubAlHizbMetaByAyahId } from "./getRubAlHizbMetaByAyahId"
3636
export { getRubAlHizbByAyahId } from "./getRubAlHizbByAyahId"
37-
export { getSurahInfo as getSurahInfo } from "./getSurahInfo"
37+
export { getSurahMeta } from "./getSurahMeta"
3838
export { isAyahJuzFirst } from "./isAyahJuzFirst"
3939
export { isAyahPageFirst } from "./isAyahPageFirst"
4040
export { isSurahAyahJuzFirst } from "./isSurahAyahJuzFirst"

src/surahStringParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Surah } from "./types"
55
* Parses a string representation of a Surah number and converts it to a valid Surah type
66
* @param str - The string containing the Surah number to parse
77
* @returns The parsed Surah number as a Surah type
8-
* @throws {Error} If the string cannot be parsed as a number or if the number is not a valid Surah number
8+
* @throws {@link Error} If the string cannot be parsed as a number or if the number is not a valid Surah number
99
*/
1010
export function surahStringParser(str: string, isStrict = false): Surah {
1111
const surahX = isStrict ? Number(str.trim()) : Number.parseInt(str.trim(), 10)

src/typeGuards.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ export function isValidRuku(x: unknown): x is Ruku {
112112
* @returns True if the value is an integer between 1 and the total number of Manzils
113113
*
114114
* @example
115+
* ```ts
115116
* if (isValidManzil(3)) {
116117
* // value is a valid Manzil number
117118
* }
119+
* ```
118120
*/
119121
export function isValidManzil(x: unknown): x is Manzil {
120122
return Number.isInteger(x) && 1 <= (x as number) && x as number <= meta.numManzils

0 commit comments

Comments
 (0)