@quranjs/api 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -0
  3. package/dist/api.cjs.development.js +2627 -0
  4. package/dist/api.cjs.development.js.map +1 -0
  5. package/dist/api.cjs.production.min.js +2 -0
  6. package/dist/api.cjs.production.min.js.map +1 -0
  7. package/dist/api.esm.js +2618 -0
  8. package/dist/api.esm.js.map +1 -0
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.js +8 -0
  11. package/dist/sdk/index.d.ts +183 -0
  12. package/dist/sdk/utils.d.ts +125 -0
  13. package/dist/sdk/v4/_fetcher.d.ts +3 -0
  14. package/dist/sdk/v4/audio.d.ts +52 -0
  15. package/dist/sdk/v4/chapters.d.ts +13 -0
  16. package/dist/sdk/v4/index.d.ts +173 -0
  17. package/dist/sdk/v4/juzs.d.ts +5 -0
  18. package/dist/sdk/v4/resources.d.ts +26 -0
  19. package/dist/sdk/v4/search.d.ts +22 -0
  20. package/dist/sdk/v4/verses.d.ts +64 -0
  21. package/dist/types/ChapterId.d.ts +1 -0
  22. package/dist/types/HizbNumber.d.ts +1 -0
  23. package/dist/types/JuzNumber.d.ts +1 -0
  24. package/dist/types/PageNumber.d.ts +1 -0
  25. package/dist/types/RubNumber.d.ts +1 -0
  26. package/dist/types/VerseKey.d.ts +1 -0
  27. package/dist/types/api/ApiResponses.d.ts +18 -0
  28. package/dist/types/api/AudioData.d.ts +17 -0
  29. package/dist/types/api/AudioResponse.d.ts +8 -0
  30. package/dist/types/api/Chapter.d.ts +14 -0
  31. package/dist/types/api/ChapterInfo.d.ts +8 -0
  32. package/dist/types/api/Footnote.d.ts +6 -0
  33. package/dist/types/api/Juz.d.ts +8 -0
  34. package/dist/types/api/Pagination.d.ts +7 -0
  35. package/dist/types/api/Reciter.d.ts +21 -0
  36. package/dist/types/api/Resources.d.ts +70 -0
  37. package/dist/types/api/Segment.d.ts +4 -0
  38. package/dist/types/api/Tafsir.d.ts +7 -0
  39. package/dist/types/api/TafsirInfo.d.ts +9 -0
  40. package/dist/types/api/TranslatedName.d.ts +4 -0
  41. package/dist/types/api/Translation.d.ts +17 -0
  42. package/dist/types/api/Transliteration.d.ts +4 -0
  43. package/dist/types/api/Verse.d.ts +32 -0
  44. package/dist/types/api/Word.d.ts +28 -0
  45. package/dist/types/api/index.d.ts +18 -0
  46. package/dist/types/index.d.ts +88 -0
  47. package/dist/utils/misc.d.ts +1 -0
  48. package/dist/utils/qs-stringify.d.ts +21 -0
  49. package/package.json +64 -0
  50. package/src/index.ts +2 -0
  51. package/src/sdk/index.ts +9 -0
  52. package/src/sdk/utils.ts +230 -0
  53. package/src/sdk/v4/_fetcher.ts +28 -0
  54. package/src/sdk/v4/audio.ts +266 -0
  55. package/src/sdk/v4/chapters.ts +83 -0
  56. package/src/sdk/v4/index.ts +17 -0
  57. package/src/sdk/v4/juzs.ts +17 -0
  58. package/src/sdk/v4/resources.ts +224 -0
  59. package/src/sdk/v4/search.ts +40 -0
  60. package/src/sdk/v4/verses.ts +213 -0
  61. package/src/types/ChapterId.ts +115 -0
  62. package/src/types/HizbNumber.ts +61 -0
  63. package/src/types/JuzNumber.ts +31 -0
  64. package/src/types/PageNumber.ts +519 -0
  65. package/src/types/RubNumber.ts +241 -0
  66. package/src/types/VerseKey.ts +6237 -0
  67. package/src/types/api/ApiResponses.ts +19 -0
  68. package/src/types/api/AudioData.ts +20 -0
  69. package/src/types/api/AudioResponse.ts +9 -0
  70. package/src/types/api/Chapter.ts +15 -0
  71. package/src/types/api/ChapterInfo.ts +8 -0
  72. package/src/types/api/Footnote.ts +6 -0
  73. package/src/types/api/Juz.ts +8 -0
  74. package/src/types/api/Pagination.ts +7 -0
  75. package/src/types/api/Reciter.ts +21 -0
  76. package/src/types/api/Resources.ts +81 -0
  77. package/src/types/api/Segment.ts +4 -0
  78. package/src/types/api/Tafsir.ts +7 -0
  79. package/src/types/api/TafsirInfo.ts +10 -0
  80. package/src/types/api/TranslatedName.ts +4 -0
  81. package/src/types/api/Translation.ts +21 -0
  82. package/src/types/api/Transliteration.ts +4 -0
  83. package/src/types/api/Verse.ts +35 -0
  84. package/src/types/api/Word.ts +30 -0
  85. package/src/types/api/index.ts +18 -0
  86. package/src/types/index.ts +134 -0
  87. package/src/utils/misc.ts +3 -0
  88. package/src/utils/qs-stringify.ts +81 -0
@@ -0,0 +1,266 @@
1
+ import {
2
+ ChapterRecitation,
3
+ VerseRecitation,
4
+ ChapterId,
5
+ HizbNumber,
6
+ JuzNumber,
7
+ Language,
8
+ PageNumber,
9
+ Pagination,
10
+ RubNumber,
11
+ VerseKey,
12
+ VerseRecitationField,
13
+ } from '@/types';
14
+ import { decamelize } from 'humps';
15
+ import Utils from '../utils';
16
+ import { fetcher } from './_fetcher';
17
+
18
+ type GetChapterRecitationsOptions = Partial<{
19
+ language: Language;
20
+ }>;
21
+
22
+ const defaultChapterRecitationsOptions: GetChapterRecitationsOptions = {
23
+ language: Language.ARABIC,
24
+ };
25
+
26
+ const getChapterRecitationsOptions = (
27
+ options: GetChapterRecitationsOptions = {}
28
+ ) => {
29
+ const final: any = { ...defaultChapterRecitationsOptions, ...options };
30
+
31
+ return final;
32
+ };
33
+
34
+ type GetVerseRecitationsOptions = Partial<{
35
+ language: Language;
36
+ fields: Partial<Record<VerseRecitationField, boolean>>;
37
+ }>;
38
+
39
+ const defaultVerseRecitationsOptions: GetVerseRecitationsOptions = {
40
+ language: Language.ARABIC,
41
+ };
42
+
43
+ const getVerseRecitationsOptions = (
44
+ options: GetVerseRecitationsOptions = {}
45
+ ) => {
46
+ const initial = { ...defaultVerseRecitationsOptions, ...options };
47
+ const final: any = { language: initial.language };
48
+
49
+ if (initial.fields) {
50
+ const fields: string[] = [];
51
+ for (const [key, value] of Object.entries(initial.fields)) {
52
+ if (value) fields.push(decamelize(key));
53
+ }
54
+ final.fields = fields.join(',');
55
+ }
56
+
57
+ return final;
58
+ };
59
+
60
+ /**
61
+ * Get all chapter recitations for specific reciter
62
+ * @description https://quran.api-docs.io/v4/audio-recitations/list-of-all-surah-audio-files-for-specific-reciter
63
+ * @param {string} reciterId
64
+ * @param {GetChapterRecitationsOptions} options
65
+ * @example
66
+ * quran.v4.audio.findAllChapterRecitations('2')
67
+ */
68
+ const findAllChapterRecitations = async (
69
+ reciterId: string,
70
+ options?: GetChapterRecitationsOptions
71
+ ) => {
72
+ const params = getChapterRecitationsOptions(options);
73
+ const { audioFiles } = await fetcher<{ audioFiles: ChapterRecitation[] }>(
74
+ `/chapter_recitations/${reciterId}`,
75
+ params
76
+ );
77
+ return audioFiles;
78
+ };
79
+
80
+ /**
81
+ * Get chapter recitation for specific reciter and a specific chapter
82
+ * @description https://quran.api-docs.io/v4/audio-recitations/get-single-surah-audio-for-specific-reciter
83
+ * @param {ChapterId} chapterId
84
+ * @param {string} reciterId
85
+ * @param {GetChapterRecitationsOptions} options
86
+ * @example
87
+ * quran.v4.audio.findChapterRecitationById('1', '2') // first chapter recitation for reciter 2
88
+ */
89
+ const findChapterRecitationById = async (
90
+ chapterId: ChapterId,
91
+ reciterId: string,
92
+ options?: GetChapterRecitationsOptions
93
+ ) => {
94
+ if (!Utils.isValidChapterId(chapterId)) throw new Error('Invalid chapter id');
95
+
96
+ const params = getChapterRecitationsOptions(options);
97
+ const { audioFile } = await fetcher<{ audioFile: ChapterRecitation }>(
98
+ `/chapter_recitations/${reciterId}/${chapterId}`,
99
+ params
100
+ );
101
+
102
+ return audioFile;
103
+ };
104
+
105
+ /**
106
+ * Get all verse audio files for a specific reciter and a specific chapter
107
+ * @description https://quran.api-docs.io/v4/audio-recitations/get-ayah-recitations-for-specific-surah
108
+ * @param {ChapterId} chapterId
109
+ * @param {string} recitationId
110
+ * @param {GetVerseRecitationsOptions} options
111
+ * @example
112
+ * quran.v4.audio.findVerseRecitationsByChapter('1', '2')
113
+ */
114
+ const findVerseRecitationsByChapter = async (
115
+ chapterId: ChapterId,
116
+ recitationId: string,
117
+ options?: GetVerseRecitationsOptions
118
+ ) => {
119
+ if (!Utils.isValidChapterId(chapterId)) throw new Error('Invalid chapter id');
120
+
121
+ const params = getVerseRecitationsOptions(options);
122
+ const data = await fetcher<{
123
+ audioFiles: VerseRecitation[];
124
+ pagination: Pagination;
125
+ }>(`/recitations/${recitationId}/by_chapter/${chapterId}`, params);
126
+
127
+ return data;
128
+ };
129
+
130
+ /**
131
+ * Get all verse audio files for a specific reciter and a specific juz
132
+ * @description https://quran.api-docs.io/v4/audio-recitations/get-ayah-recitations-for-specific-juz
133
+ * @param {JuzNumber} juz
134
+ * @param {string} recitationId
135
+ * @param {GetRecitationsOptions} options
136
+ * @example
137
+ * quran.v4.audio.findVerseRecitationsByJuz('1', '2')
138
+ */
139
+ const findVerseRecitationsByJuz = async (
140
+ juz: JuzNumber,
141
+ recitationId: string,
142
+ options?: GetVerseRecitationsOptions
143
+ ) => {
144
+ if (!Utils.isValidJuz(juz)) throw new Error('Invalid juz');
145
+
146
+ const params = getVerseRecitationsOptions(options);
147
+ const data = await fetcher<{
148
+ audioFiles: VerseRecitation[];
149
+ pagination: Pagination;
150
+ }>(`/recitations/${recitationId}/by_juz/${juz}`, params);
151
+
152
+ return data;
153
+ };
154
+
155
+ /**
156
+ * Get all verse audio files for a specific reciter and a specific mushaf page
157
+ * @description https://quran.api-docs.io/v4/audio-recitations/get-ayah-recitations-for-specific-madani-mushaf-page
158
+ * @param {PageNumber} page
159
+ * @param {string} recitationId
160
+ * @param {GetVerseRecitationsOptions} options
161
+ * @example
162
+ * quran.v4.audio.findVerseRecitationsByPage('1', '2')
163
+ */
164
+ const findVerseRecitationsByPage = async (
165
+ page: PageNumber,
166
+ recitationId: string,
167
+ options?: GetVerseRecitationsOptions
168
+ ) => {
169
+ if (!Utils.isValidQuranPage(page)) throw new Error('Invalid page');
170
+
171
+ const params = getVerseRecitationsOptions(options);
172
+ const data = await fetcher<{
173
+ audioFiles: VerseRecitation[];
174
+ pagination: Pagination;
175
+ }>(`/recitations/${recitationId}/by_page/${page}`, params);
176
+
177
+ return data;
178
+ };
179
+
180
+ /**
181
+ * Get all verse audio files for a specific reciter and a specific rub
182
+ * @description https://quran.api-docs.io/v4/audio-recitations/get-ayah-recitations-for-specific-rub
183
+ * @param {RubNumber} rub
184
+ * @param {string} recitationId
185
+ * @param {GetVerseRecitationsOptions} options
186
+ * @example
187
+ * quran.v4.audio.findVerseRecitationsByRub('1', '2')
188
+ */
189
+ const findVerseRecitationsByRub = async (
190
+ rub: RubNumber,
191
+ recitationId: string,
192
+ options?: GetVerseRecitationsOptions
193
+ ) => {
194
+ if (!Utils.isValidRub(rub)) throw new Error('Invalid rub');
195
+
196
+ const params = getVerseRecitationsOptions(options);
197
+ const data = await fetcher<{
198
+ audioFiles: VerseRecitation[];
199
+ pagination: Pagination;
200
+ }>(`/recitations/${recitationId}/by_rub/${rub}`, params);
201
+
202
+ return data;
203
+ };
204
+
205
+ /**
206
+ * Get all verse audio files for a specific reciter and a specific hizb
207
+ * @description https://quran.api-docs.io/v4/audio-recitations/get-ayah-recitations-for-specific-hizb
208
+ * @param {HizbNumber} hizb
209
+ * @param {string} recitationId
210
+ * @param {GetVerseRecitationsOptions} options
211
+ * @example
212
+ * quran.v4.audio.findVerseRecitationsByHizb('1', '2')
213
+ */
214
+ const findVerseRecitationsByHizb = async (
215
+ hizb: HizbNumber,
216
+ recitationId: string,
217
+ options?: GetVerseRecitationsOptions
218
+ ) => {
219
+ if (!Utils.isValidHizb(hizb)) throw new Error('Invalid hizb');
220
+
221
+ const params = getVerseRecitationsOptions(options);
222
+ const data = await fetcher<{
223
+ audioFiles: VerseRecitation[];
224
+ pagination: Pagination;
225
+ }>(`/recitations/${recitationId}/by_hizb/${hizb}`, params);
226
+
227
+ return data;
228
+ };
229
+
230
+ /**
231
+ * Get all verse audio files for a specific reciter and a specific hizb
232
+ * @description https://quran.api-docs.io/v4/audio-recitations/get-ayah-recitations-for-specific-ayah
233
+ * @param {VerseKey} key
234
+ * @param {string} recitationId
235
+ * @param {GetVerseRecitationsOptions} options
236
+ * @example
237
+ * quran.v4.audio.findVerseRecitationsByKey('1:1', '2')
238
+ */
239
+ const findVerseRecitationsByKey = async (
240
+ key: VerseKey,
241
+ recitationId: string,
242
+ options?: GetVerseRecitationsOptions
243
+ ) => {
244
+ if (!Utils.isValidVerseKey(key)) throw new Error('Invalid verse key');
245
+
246
+ const params = getVerseRecitationsOptions(options);
247
+ const data = await fetcher<{
248
+ audioFiles: VerseRecitation[];
249
+ pagination: Pagination;
250
+ }>(`/recitations/${recitationId}/by_ayah/${key}`, params);
251
+
252
+ return data;
253
+ };
254
+
255
+ const audio = {
256
+ findAllChapterRecitations,
257
+ findChapterRecitationById,
258
+ findVerseRecitationsByChapter,
259
+ findVerseRecitationsByJuz,
260
+ findVerseRecitationsByPage,
261
+ findVerseRecitationsByRub,
262
+ findVerseRecitationsByHizb,
263
+ findVerseRecitationsByKey,
264
+ };
265
+
266
+ export default audio;
@@ -0,0 +1,83 @@
1
+ import { Chapter, ChapterId, ChapterInfo, Language } from '@/types';
2
+ import { fetcher } from './_fetcher';
3
+ import Utils from '../utils';
4
+
5
+ type Options = Partial<{
6
+ language: Language;
7
+ }>;
8
+
9
+ const defaultOptions: Options = {
10
+ language: Language.ARABIC,
11
+ };
12
+
13
+ const getChapterOptions = (options: Options = {}) => {
14
+ const final: any = { ...defaultOptions, ...options };
15
+ return final;
16
+ };
17
+
18
+ /**
19
+ * Get all chapters.
20
+ * @description https://quran.api-docs.io/v4/chapters/list-chapters
21
+ * @param {Options} options
22
+ * @example
23
+ * quran.v4.chapters.findAll()
24
+ */
25
+ const findAll = async (options?: Options) => {
26
+ const params = getChapterOptions(options);
27
+ const { chapters } = await fetcher<{ chapters: Chapter[] }>(
28
+ '/chapters',
29
+ params
30
+ );
31
+
32
+ return chapters;
33
+ };
34
+
35
+ /**
36
+ * Get chapter by id.
37
+ * @description https://quran.api-docs.io/v4/chapters/get-chapter
38
+ * @param {ChapterId} id chapter id, minimum 1, maximum 114
39
+ * @param {Options} options
40
+ * @example
41
+ * quran.v4.chapters.findById('1')
42
+ * quran.v4.chapters.findById('114')
43
+ */
44
+ const findById = async (id: ChapterId, options?: Options) => {
45
+ if (!Utils.isValidChapterId(id)) throw new Error('Invalid chapter id');
46
+
47
+ const params = getChapterOptions(options);
48
+ const { chapter } = await fetcher<{ chapter: Chapter }>(
49
+ `/chapters/${id}`,
50
+ params
51
+ );
52
+
53
+ return chapter;
54
+ };
55
+
56
+ /**
57
+ * Get chapter info by id.
58
+ * @description https://quran.api-docs.io/v4/chapters/chapter_info
59
+ * @param {ChapterId} id chapter id, minimum 1, maximum 114
60
+ * @param {Options} options
61
+ * @example
62
+ * quran.v4.chapters.findInfoById('1')
63
+ * quran.v4.chapters.findInfoById('114')
64
+ */
65
+ const findInfoById = async (id: ChapterId, options?: Options) => {
66
+ if (!Utils.isValidChapterId(id)) throw new Error('Invalid chapter id');
67
+
68
+ const params = getChapterOptions(options);
69
+ const { chapterInfo } = await fetcher<{ chapterInfo: ChapterInfo }>(
70
+ `/chapters/${id}/info`,
71
+ params
72
+ );
73
+
74
+ return chapterInfo;
75
+ };
76
+
77
+ const chapters = {
78
+ findAll,
79
+ findById,
80
+ findInfoById,
81
+ };
82
+
83
+ export default chapters;
@@ -0,0 +1,17 @@
1
+ import chapters from './chapters';
2
+ import verses from './verses';
3
+ import juzs from './juzs';
4
+ import audio from './audio';
5
+ import resources from './resources';
6
+ import search from './search';
7
+
8
+ const v4 = {
9
+ chapters,
10
+ verses,
11
+ juzs,
12
+ audio,
13
+ resources,
14
+ search,
15
+ };
16
+
17
+ export default v4;
@@ -0,0 +1,17 @@
1
+ import { Juz } from '@/types';
2
+ import { fetcher } from './_fetcher';
3
+
4
+ /**
5
+ * Get All Juzs
6
+ * @description https://quran.api-docs.io/v4/juz/get-all-juzs
7
+ * @example
8
+ * quran.v4.juzs.findAll()
9
+ */
10
+ const findAll = async () => {
11
+ const { juzs } = await fetcher<{ juzs: Juz[] }>('/juzs');
12
+ return juzs;
13
+ };
14
+
15
+ const juzs = { findAll };
16
+
17
+ export default juzs;
@@ -0,0 +1,224 @@
1
+ import {
2
+ ChapterInfoResource,
3
+ ChapterReciterResource,
4
+ Language,
5
+ LanguageResource,
6
+ // RecitationInfoResource,
7
+ RecitationResource,
8
+ RecitationStylesResource,
9
+ // TafsirInfoResource,
10
+ TafsirResource,
11
+ // TranslationInfoResource,
12
+ TranslationResource,
13
+ VerseMediaResource,
14
+ } from '@/types';
15
+ import { fetcher } from './_fetcher';
16
+
17
+ type GetResourcesOptions = Partial<{
18
+ language: Language;
19
+ }>;
20
+
21
+ const defaultOptions: GetResourcesOptions = {
22
+ language: Language.ARABIC,
23
+ };
24
+
25
+ const getResourcesOptions = (options: GetResourcesOptions = {}) => {
26
+ const final: any = { ...defaultOptions, ...options };
27
+ return final;
28
+ };
29
+
30
+ /**
31
+ * Get all recitations.
32
+ * @description https://quran.api-docs.io/v4/resources/recitations
33
+ * @param {GetResourcesOptions} options
34
+ * @example
35
+ * quran.v4.resources.findAllRecitations()
36
+ */
37
+ const findAllRecitations = async (options?: GetResourcesOptions) => {
38
+ const params = getResourcesOptions(options);
39
+ const { recitations } = await fetcher<{
40
+ recitations: RecitationResource[];
41
+ }>('/resources/recitations', params);
42
+
43
+ return recitations;
44
+ };
45
+
46
+ // TODO: uncomment when API is ready
47
+ /**
48
+ * Get all recitation info.
49
+ * @description https://quran.api-docs.io/v4/resources/recitation-info
50
+ * @param {string} id recitation id
51
+ * @param {GetResourcesOptions} options
52
+ * @example
53
+ * quran.v4.resources.findRecitationInfo('1')
54
+ */
55
+ // const findRecitationInfo = async (id: string, options?: GetResourcesOptions) => {
56
+ // const params = getResourcesOptions(options);
57
+ // const { info } = await fetcher<{
58
+ // info: RecitationInfoResource;
59
+ // }>(`/resources/recitations/${id}/info`, params);
60
+
61
+ // return info;
62
+ // };
63
+
64
+ /**
65
+ * Get all translations.
66
+ * @description https://quran.api-docs.io/v4/resources/translations
67
+ * @param {GetResourcesOptions} options
68
+ * @example
69
+ * quran.v4.resources.findAllTranslations()
70
+ */
71
+ const findAllTranslations = async (options?: GetResourcesOptions) => {
72
+ const params = getResourcesOptions(options);
73
+ const { translations } = await fetcher<{
74
+ translations: TranslationResource[];
75
+ }>('/resources/translations', params);
76
+
77
+ return translations;
78
+ };
79
+
80
+ // TODO: uncomment when API is ready
81
+ /**
82
+ * Get translation info.
83
+ * @description https://quran.api-docs.io/v4/resources/translation-info
84
+ * @param {string} id translation id
85
+ * @param {GetResourcesOptions} options
86
+ * @example
87
+ * quran.v4.resources.findTranslationInfo('169')
88
+ */
89
+ // const findTranslationInfo = async (id: string, options?: GetResourcesOptions) => {
90
+ // const params = getResourcesOptions(options);
91
+ // const { info } = await fetcher<{
92
+ // info: TranslationInfoResource;
93
+ // }>(`/resources/translations/${id}/info`, params);
94
+
95
+ // return info;
96
+ // };
97
+
98
+ /**
99
+ * Get all tafsirs.
100
+ * @description https://quran.api-docs.io/v4/resources/tafsirs
101
+ * @param {GetResourcesOptions} options
102
+ * @example
103
+ * quran.v4.resources.findAllTafsirs()
104
+ */
105
+ const findAllTafsirs = async (options?: GetResourcesOptions) => {
106
+ const params = getResourcesOptions(options);
107
+ const { tafsirs } = await fetcher<{
108
+ tafsirs: TafsirResource[];
109
+ }>('/resources/tafsirs', params);
110
+
111
+ return tafsirs;
112
+ };
113
+
114
+ // TODO: uncomment when API is ready
115
+ /**
116
+ * Get tafsir info.
117
+ * @description https://quran.api-docs.io/v4/resources/tafsirs-info
118
+ * @param {string} id tafsir id
119
+ * @param {GetResourcesOptions} options
120
+ * @example
121
+ * quran.v4.resources.findTranslationInfo('1')
122
+ */
123
+ // const findTafsirInfo = async (id: string, options?: GetResourcesOptions) => {
124
+ // const params = getResourcesOptions(options);
125
+ // const { info } = await fetcher<{
126
+ // info: TafsirInfoResource;
127
+ // }>(`/resources/tafsirs/${id}/info`, params);
128
+
129
+ // return info;
130
+ // };
131
+
132
+ /**
133
+ * Get all recitation styles.
134
+ * @description https://quran.api-docs.io/v4/resources/recitation-styles
135
+ * @example
136
+ * quran.v4.resources.findAllRecitationStyles()
137
+ */
138
+ const findAllRecitationStyles = async () => {
139
+ const { recitationStyles } = await fetcher<{
140
+ recitationStyles: RecitationStylesResource;
141
+ }>('/resources/recitation_styles');
142
+
143
+ return recitationStyles;
144
+ };
145
+
146
+ /**
147
+ * Get all languages.
148
+ * @description https://quran.api-docs.io/v4/resources/languages
149
+ * @param {GetResourcesOptions} options
150
+ * @example
151
+ * quran.v4.resources.findAllLanguages()
152
+ */
153
+ const findAllLanguages = async (options?: GetResourcesOptions) => {
154
+ const params = getResourcesOptions(options);
155
+ const { languages } = await fetcher<{
156
+ languages: LanguageResource[];
157
+ }>('/resources/languages', params);
158
+
159
+ return languages;
160
+ };
161
+
162
+ /**
163
+ * Get all chapter infos.
164
+ * @description https://quran.api-docs.io/v4/resources/chapter-info
165
+ * @param {GetResourcesOptions} options
166
+ * @example
167
+ * quran.v4.resources.findAllChapterInfos()
168
+ */
169
+ const findAllChapterInfos = async (options?: GetResourcesOptions) => {
170
+ const params = getResourcesOptions(options);
171
+ const { chapterInfos } = await fetcher<{
172
+ chapterInfos: ChapterInfoResource[];
173
+ }>('/resources/chapter_infos', params);
174
+
175
+ return chapterInfos;
176
+ };
177
+
178
+ /**
179
+ * Get verse media.
180
+ * @description https://quran.api-docs.io/v4/resources/verse_media
181
+ * @param {GetResourcesOptions} options
182
+ * @example
183
+ * quran.v4.resources.findVerseMedia()
184
+ */
185
+ const findVerseMedia = async (options?: GetResourcesOptions) => {
186
+ const params = getResourcesOptions(options);
187
+ const { verseMedia } = await fetcher<{
188
+ verseMedia: VerseMediaResource;
189
+ }>(`/resources/verse_media`, params);
190
+
191
+ return verseMedia;
192
+ };
193
+
194
+ /**
195
+ * Get all chapter reciters.
196
+ * @description https://quran.api-docs.io/v4/resources/list-of-chapter-reciters
197
+ * @param {GetResourcesOptions} options
198
+ * @example
199
+ * quran.v4.resources.findAllChapterReciters()
200
+ */
201
+ const findAllChapterReciters = async (options?: GetResourcesOptions) => {
202
+ const params = getResourcesOptions(options);
203
+ const { reciters } = await fetcher<{
204
+ reciters: ChapterReciterResource[];
205
+ }>(`/resources/chapter_reciters`, params);
206
+
207
+ return reciters;
208
+ };
209
+
210
+ const resources = {
211
+ findAllRecitations,
212
+ findAllTranslations,
213
+ findAllTafsirs,
214
+ findAllRecitationStyles,
215
+ findAllLanguages,
216
+ findVerseMedia,
217
+ findAllChapterReciters,
218
+ findAllChapterInfos,
219
+ // findRecitationInfo
220
+ // findTranslationInfo
221
+ // findTafsirInfo
222
+ };
223
+
224
+ export default resources;
@@ -0,0 +1,40 @@
1
+ import { Language, SearchResponse } from '@/types';
2
+ import { fetcher } from './_fetcher';
3
+
4
+ type SearchOptions = Partial<{
5
+ language: Language;
6
+ size: number;
7
+ page: number;
8
+ }>;
9
+
10
+ const defaultSearchOptions: SearchOptions = {
11
+ language: Language.ARABIC,
12
+ size: 30,
13
+ };
14
+
15
+ const getSearchOptions = (q: string, options: SearchOptions = {}) => {
16
+ const all = { ...defaultSearchOptions, ...options, q };
17
+ return all;
18
+ };
19
+
20
+ /**
21
+ * Search
22
+ * @description https://quran.api-docs.io/v4/search/KfCmk4KQYbtyK9adj
23
+ * @param q search query
24
+ * @param options search options
25
+ * @example
26
+ * quran.v4.search.search('الله')
27
+ * quran.v4.search.search('الله', { language: Language.ENGLISH })
28
+ * quran.v4.search.search('الله', { language: Language.ENGLISH, size: 10 })
29
+ * quran.v4.search.search('الله', { language: Language.ENGLISH, page: 2 })
30
+ */
31
+ const search = async (q: string, options?: SearchOptions) => {
32
+ const params = getSearchOptions(q, options);
33
+ const { search } = await fetcher<SearchResponse>('/search', params);
34
+
35
+ return search;
36
+ };
37
+
38
+ const searchApi = { search };
39
+
40
+ export default searchApi;