@quranjs/api 1.3.0 → 1.4.0

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.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "1.3.0",
8
+ "version": "1.4.0",
9
9
  "license": "MIT",
10
10
  "main": "dist/index.js",
11
11
  "typings": "dist/index.d.ts",
@@ -15,33 +15,33 @@ import { decamelize } from 'humps';
15
15
  import Utils from '../utils';
16
16
  import { fetcher } from './_fetcher';
17
17
 
18
- type GetChapterRecitationsOptions = Partial<{
18
+ type GetChapterRecitationOptions = Partial<{
19
19
  language: Language;
20
20
  }>;
21
21
 
22
- const defaultChapterRecitationsOptions: GetChapterRecitationsOptions = {
22
+ const defaultChapterRecitationsOptions: GetChapterRecitationOptions = {
23
23
  language: Language.ARABIC,
24
24
  };
25
25
 
26
26
  const getChapterRecitationsOptions = (
27
- options: GetChapterRecitationsOptions = {}
27
+ options: GetChapterRecitationOptions = {}
28
28
  ) => {
29
29
  const final: any = { ...defaultChapterRecitationsOptions, ...options };
30
30
 
31
31
  return final;
32
32
  };
33
33
 
34
- type GetVerseRecitationsOptions = Partial<{
34
+ type GetVerseRecitationOptions = Partial<{
35
35
  language: Language;
36
36
  fields: Partial<Record<VerseRecitationField, boolean>>;
37
37
  }>;
38
38
 
39
- const defaultVerseRecitationsOptions: GetVerseRecitationsOptions = {
39
+ const defaultVerseRecitationsOptions: GetVerseRecitationOptions = {
40
40
  language: Language.ARABIC,
41
41
  };
42
42
 
43
43
  const getVerseRecitationsOptions = (
44
- options: GetVerseRecitationsOptions = {}
44
+ options: GetVerseRecitationOptions = {}
45
45
  ) => {
46
46
  const initial = { ...defaultVerseRecitationsOptions, ...options };
47
47
  const final: any = { language: initial.language };
@@ -61,13 +61,13 @@ const getVerseRecitationsOptions = (
61
61
  * Get all chapter recitations for specific reciter
62
62
  * @description https://quran.api-docs.io/v4/audio-recitations/list-of-all-surah-audio-files-for-specific-reciter
63
63
  * @param {string} reciterId
64
- * @param {GetChapterRecitationsOptions} options
64
+ * @param {GetChapterRecitationOptions} options
65
65
  * @example
66
66
  * quran.v4.audio.findAllChapterRecitations('2')
67
67
  */
68
68
  const findAllChapterRecitations = async (
69
69
  reciterId: string,
70
- options?: GetChapterRecitationsOptions
70
+ options?: GetChapterRecitationOptions
71
71
  ) => {
72
72
  const params = getChapterRecitationsOptions(options);
73
73
  const { audioFiles } = await fetcher<{ audioFiles: ChapterRecitation[] }>(
@@ -82,14 +82,14 @@ const findAllChapterRecitations = async (
82
82
  * @description https://quran.api-docs.io/v4/audio-recitations/get-single-surah-audio-for-specific-reciter
83
83
  * @param {ChapterId} chapterId
84
84
  * @param {string} reciterId
85
- * @param {GetChapterRecitationsOptions} options
85
+ * @param {GetChapterRecitationOptions} options
86
86
  * @example
87
87
  * quran.v4.audio.findChapterRecitationById('1', '2') // first chapter recitation for reciter 2
88
88
  */
89
89
  const findChapterRecitationById = async (
90
90
  chapterId: ChapterId,
91
91
  reciterId: string,
92
- options?: GetChapterRecitationsOptions
92
+ options?: GetChapterRecitationOptions
93
93
  ) => {
94
94
  if (!Utils.isValidChapterId(chapterId)) throw new Error('Invalid chapter id');
95
95
 
@@ -107,14 +107,14 @@ const findChapterRecitationById = async (
107
107
  * @description https://quran.api-docs.io/v4/audio-recitations/get-ayah-recitations-for-specific-surah
108
108
  * @param {ChapterId} chapterId
109
109
  * @param {string} recitationId
110
- * @param {GetVerseRecitationsOptions} options
110
+ * @param {GetVerseRecitationOptions} options
111
111
  * @example
112
112
  * quran.v4.audio.findVerseRecitationsByChapter('1', '2')
113
113
  */
114
114
  const findVerseRecitationsByChapter = async (
115
115
  chapterId: ChapterId,
116
116
  recitationId: string,
117
- options?: GetVerseRecitationsOptions
117
+ options?: GetVerseRecitationOptions
118
118
  ) => {
119
119
  if (!Utils.isValidChapterId(chapterId)) throw new Error('Invalid chapter id');
120
120
 
@@ -139,7 +139,7 @@ const findVerseRecitationsByChapter = async (
139
139
  const findVerseRecitationsByJuz = async (
140
140
  juz: JuzNumber,
141
141
  recitationId: string,
142
- options?: GetVerseRecitationsOptions
142
+ options?: GetVerseRecitationOptions
143
143
  ) => {
144
144
  if (!Utils.isValidJuz(juz)) throw new Error('Invalid juz');
145
145
 
@@ -157,14 +157,14 @@ const findVerseRecitationsByJuz = async (
157
157
  * @description https://quran.api-docs.io/v4/audio-recitations/get-ayah-recitations-for-specific-madani-mushaf-page
158
158
  * @param {PageNumber} page
159
159
  * @param {string} recitationId
160
- * @param {GetVerseRecitationsOptions} options
160
+ * @param {GetVerseRecitationOptions} options
161
161
  * @example
162
162
  * quran.v4.audio.findVerseRecitationsByPage('1', '2')
163
163
  */
164
164
  const findVerseRecitationsByPage = async (
165
165
  page: PageNumber,
166
166
  recitationId: string,
167
- options?: GetVerseRecitationsOptions
167
+ options?: GetVerseRecitationOptions
168
168
  ) => {
169
169
  if (!Utils.isValidQuranPage(page)) throw new Error('Invalid page');
170
170
 
@@ -182,14 +182,14 @@ const findVerseRecitationsByPage = async (
182
182
  * @description https://quran.api-docs.io/v4/audio-recitations/get-ayah-recitations-for-specific-rub
183
183
  * @param {RubNumber} rub
184
184
  * @param {string} recitationId
185
- * @param {GetVerseRecitationsOptions} options
185
+ * @param {GetVerseRecitationOptions} options
186
186
  * @example
187
187
  * quran.v4.audio.findVerseRecitationsByRub('1', '2')
188
188
  */
189
189
  const findVerseRecitationsByRub = async (
190
190
  rub: RubNumber,
191
191
  recitationId: string,
192
- options?: GetVerseRecitationsOptions
192
+ options?: GetVerseRecitationOptions
193
193
  ) => {
194
194
  if (!Utils.isValidRub(rub)) throw new Error('Invalid rub');
195
195
 
@@ -207,14 +207,14 @@ const findVerseRecitationsByRub = async (
207
207
  * @description https://quran.api-docs.io/v4/audio-recitations/get-ayah-recitations-for-specific-hizb
208
208
  * @param {HizbNumber} hizb
209
209
  * @param {string} recitationId
210
- * @param {GetVerseRecitationsOptions} options
210
+ * @param {GetVerseRecitationOptions} options
211
211
  * @example
212
212
  * quran.v4.audio.findVerseRecitationsByHizb('1', '2')
213
213
  */
214
214
  const findVerseRecitationsByHizb = async (
215
215
  hizb: HizbNumber,
216
216
  recitationId: string,
217
- options?: GetVerseRecitationsOptions
217
+ options?: GetVerseRecitationOptions
218
218
  ) => {
219
219
  if (!Utils.isValidHizb(hizb)) throw new Error('Invalid hizb');
220
220
 
@@ -228,18 +228,18 @@ const findVerseRecitationsByHizb = async (
228
228
  };
229
229
 
230
230
  /**
231
- * Get all verse audio files for a specific reciter and a specific hizb
231
+ * Get all verse audio files for a specific reciter and a specific verse
232
232
  * @description https://quran.api-docs.io/v4/audio-recitations/get-ayah-recitations-for-specific-ayah
233
233
  * @param {VerseKey} key
234
234
  * @param {string} recitationId
235
- * @param {GetVerseRecitationsOptions} options
235
+ * @param {GetVerseRecitationOptions} options
236
236
  * @example
237
237
  * quran.v4.audio.findVerseRecitationsByKey('1:1', '2')
238
238
  */
239
239
  const findVerseRecitationsByKey = async (
240
240
  key: VerseKey,
241
241
  recitationId: string,
242
- options?: GetVerseRecitationsOptions
242
+ options?: GetVerseRecitationOptions
243
243
  ) => {
244
244
  if (!Utils.isValidVerseKey(key)) throw new Error('Invalid verse key');
245
245
 
@@ -2,15 +2,15 @@ import { Chapter, ChapterId, ChapterInfo, Language } from '../../types';
2
2
  import { fetcher } from './_fetcher';
3
3
  import Utils from '../utils';
4
4
 
5
- type Options = Partial<{
5
+ type GetChapterOptions = Partial<{
6
6
  language: Language;
7
7
  }>;
8
8
 
9
- const defaultOptions: Options = {
9
+ const defaultOptions: GetChapterOptions = {
10
10
  language: Language.ARABIC,
11
11
  };
12
12
 
13
- const getChapterOptions = (options: Options = {}) => {
13
+ const getChapterOptions = (options: GetChapterOptions = {}) => {
14
14
  const final: any = { ...defaultOptions, ...options };
15
15
  return final;
16
16
  };
@@ -18,11 +18,11 @@ const getChapterOptions = (options: Options = {}) => {
18
18
  /**
19
19
  * Get all chapters.
20
20
  * @description https://quran.api-docs.io/v4/chapters/list-chapters
21
- * @param {Options} options
21
+ * @param {GetChapterOptions} options
22
22
  * @example
23
23
  * quran.v4.chapters.findAll()
24
24
  */
25
- const findAll = async (options?: Options) => {
25
+ const findAll = async (options?: GetChapterOptions) => {
26
26
  const params = getChapterOptions(options);
27
27
  const { chapters } = await fetcher<{ chapters: Chapter[] }>(
28
28
  '/chapters',
@@ -36,12 +36,12 @@ const findAll = async (options?: Options) => {
36
36
  * Get chapter by id.
37
37
  * @description https://quran.api-docs.io/v4/chapters/get-chapter
38
38
  * @param {ChapterId} id chapter id, minimum 1, maximum 114
39
- * @param {Options} options
39
+ * @param {GetChapterOptions} options
40
40
  * @example
41
41
  * quran.v4.chapters.findById('1')
42
42
  * quran.v4.chapters.findById('114')
43
43
  */
44
- const findById = async (id: ChapterId, options?: Options) => {
44
+ const findById = async (id: ChapterId, options?: GetChapterOptions) => {
45
45
  if (!Utils.isValidChapterId(id)) throw new Error('Invalid chapter id');
46
46
 
47
47
  const params = getChapterOptions(options);
@@ -57,12 +57,12 @@ const findById = async (id: ChapterId, options?: Options) => {
57
57
  * Get chapter info by id.
58
58
  * @description https://quran.api-docs.io/v4/chapters/chapter_info
59
59
  * @param {ChapterId} id chapter id, minimum 1, maximum 114
60
- * @param {Options} options
60
+ * @param {GetChapterOptions} options
61
61
  * @example
62
62
  * quran.v4.chapters.findInfoById('1')
63
63
  * quran.v4.chapters.findInfoById('114')
64
64
  */
65
- const findInfoById = async (id: ChapterId, options?: Options) => {
65
+ const findInfoById = async (id: ChapterId, options?: GetChapterOptions) => {
66
66
  if (!Utils.isValidChapterId(id)) throw new Error('Invalid chapter id');
67
67
 
68
68
  const params = getChapterOptions(options);
@@ -14,15 +14,15 @@ import {
14
14
  } from '../../types';
15
15
  import { fetcher } from './_fetcher';
16
16
 
17
- type GetResourcesOptions = Partial<{
17
+ type GetResourceOptions = Partial<{
18
18
  language: Language;
19
19
  }>;
20
20
 
21
- const defaultOptions: GetResourcesOptions = {
21
+ const defaultOptions: GetResourceOptions = {
22
22
  language: Language.ARABIC,
23
23
  };
24
24
 
25
- const getResourcesOptions = (options: GetResourcesOptions = {}) => {
25
+ const getResourcesOptions = (options: GetResourceOptions = {}) => {
26
26
  const final: any = { ...defaultOptions, ...options };
27
27
  return final;
28
28
  };
@@ -30,11 +30,11 @@ const getResourcesOptions = (options: GetResourcesOptions = {}) => {
30
30
  /**
31
31
  * Get all recitations.
32
32
  * @description https://quran.api-docs.io/v4/resources/recitations
33
- * @param {GetResourcesOptions} options
33
+ * @param {GetResourceOptions} options
34
34
  * @example
35
35
  * quran.v4.resources.findAllRecitations()
36
36
  */
37
- const findAllRecitations = async (options?: GetResourcesOptions) => {
37
+ const findAllRecitations = async (options?: GetResourceOptions) => {
38
38
  const params = getResourcesOptions(options);
39
39
  const { recitations } = await fetcher<{
40
40
  recitations: RecitationResource[];
@@ -48,11 +48,11 @@ const findAllRecitations = async (options?: GetResourcesOptions) => {
48
48
  * Get all recitation info.
49
49
  * @description https://quran.api-docs.io/v4/resources/recitation-info
50
50
  * @param {string} id recitation id
51
- * @param {GetResourcesOptions} options
51
+ * @param {GetResourceOptions} options
52
52
  * @example
53
53
  * quran.v4.resources.findRecitationInfo('1')
54
54
  */
55
- // const findRecitationInfo = async (id: string, options?: GetResourcesOptions) => {
55
+ // const findRecitationInfo = async (id: string, options?: GetResourceOptions) => {
56
56
  // const params = getResourcesOptions(options);
57
57
  // const { info } = await fetcher<{
58
58
  // info: RecitationInfoResource;
@@ -64,11 +64,11 @@ const findAllRecitations = async (options?: GetResourcesOptions) => {
64
64
  /**
65
65
  * Get all translations.
66
66
  * @description https://quran.api-docs.io/v4/resources/translations
67
- * @param {GetResourcesOptions} options
67
+ * @param {GetResourceOptions} options
68
68
  * @example
69
69
  * quran.v4.resources.findAllTranslations()
70
70
  */
71
- const findAllTranslations = async (options?: GetResourcesOptions) => {
71
+ const findAllTranslations = async (options?: GetResourceOptions) => {
72
72
  const params = getResourcesOptions(options);
73
73
  const { translations } = await fetcher<{
74
74
  translations: TranslationResource[];
@@ -82,11 +82,11 @@ const findAllTranslations = async (options?: GetResourcesOptions) => {
82
82
  * Get translation info.
83
83
  * @description https://quran.api-docs.io/v4/resources/translation-info
84
84
  * @param {string} id translation id
85
- * @param {GetResourcesOptions} options
85
+ * @param {GetResourceOptions} options
86
86
  * @example
87
87
  * quran.v4.resources.findTranslationInfo('169')
88
88
  */
89
- // const findTranslationInfo = async (id: string, options?: GetResourcesOptions) => {
89
+ // const findTranslationInfo = async (id: string, options?: GetResourceOptions) => {
90
90
  // const params = getResourcesOptions(options);
91
91
  // const { info } = await fetcher<{
92
92
  // info: TranslationInfoResource;
@@ -98,11 +98,11 @@ const findAllTranslations = async (options?: GetResourcesOptions) => {
98
98
  /**
99
99
  * Get all tafsirs.
100
100
  * @description https://quran.api-docs.io/v4/resources/tafsirs
101
- * @param {GetResourcesOptions} options
101
+ * @param {GetResourceOptions} options
102
102
  * @example
103
103
  * quran.v4.resources.findAllTafsirs()
104
104
  */
105
- const findAllTafsirs = async (options?: GetResourcesOptions) => {
105
+ const findAllTafsirs = async (options?: GetResourceOptions) => {
106
106
  const params = getResourcesOptions(options);
107
107
  const { tafsirs } = await fetcher<{
108
108
  tafsirs: TafsirResource[];
@@ -116,11 +116,11 @@ const findAllTafsirs = async (options?: GetResourcesOptions) => {
116
116
  * Get tafsir info.
117
117
  * @description https://quran.api-docs.io/v4/resources/tafsirs-info
118
118
  * @param {string} id tafsir id
119
- * @param {GetResourcesOptions} options
119
+ * @param {GetResourceOptions} options
120
120
  * @example
121
121
  * quran.v4.resources.findTranslationInfo('1')
122
122
  */
123
- // const findTafsirInfo = async (id: string, options?: GetResourcesOptions) => {
123
+ // const findTafsirInfo = async (id: string, options?: GetResourceOptions) => {
124
124
  // const params = getResourcesOptions(options);
125
125
  // const { info } = await fetcher<{
126
126
  // info: TafsirInfoResource;
@@ -146,11 +146,11 @@ const findAllRecitationStyles = async () => {
146
146
  /**
147
147
  * Get all languages.
148
148
  * @description https://quran.api-docs.io/v4/resources/languages
149
- * @param {GetResourcesOptions} options
149
+ * @param {GetResourceOptions} options
150
150
  * @example
151
151
  * quran.v4.resources.findAllLanguages()
152
152
  */
153
- const findAllLanguages = async (options?: GetResourcesOptions) => {
153
+ const findAllLanguages = async (options?: GetResourceOptions) => {
154
154
  const params = getResourcesOptions(options);
155
155
  const { languages } = await fetcher<{
156
156
  languages: LanguageResource[];
@@ -162,11 +162,11 @@ const findAllLanguages = async (options?: GetResourcesOptions) => {
162
162
  /**
163
163
  * Get all chapter infos.
164
164
  * @description https://quran.api-docs.io/v4/resources/chapter-info
165
- * @param {GetResourcesOptions} options
165
+ * @param {GetResourceOptions} options
166
166
  * @example
167
167
  * quran.v4.resources.findAllChapterInfos()
168
168
  */
169
- const findAllChapterInfos = async (options?: GetResourcesOptions) => {
169
+ const findAllChapterInfos = async (options?: GetResourceOptions) => {
170
170
  const params = getResourcesOptions(options);
171
171
  const { chapterInfos } = await fetcher<{
172
172
  chapterInfos: ChapterInfoResource[];
@@ -178,11 +178,11 @@ const findAllChapterInfos = async (options?: GetResourcesOptions) => {
178
178
  /**
179
179
  * Get verse media.
180
180
  * @description https://quran.api-docs.io/v4/resources/verse_media
181
- * @param {GetResourcesOptions} options
181
+ * @param {GetResourceOptions} options
182
182
  * @example
183
183
  * quran.v4.resources.findVerseMedia()
184
184
  */
185
- const findVerseMedia = async (options?: GetResourcesOptions) => {
185
+ const findVerseMedia = async (options?: GetResourceOptions) => {
186
186
  const params = getResourcesOptions(options);
187
187
  const { verseMedia } = await fetcher<{
188
188
  verseMedia: VerseMediaResource;
@@ -194,11 +194,11 @@ const findVerseMedia = async (options?: GetResourcesOptions) => {
194
194
  /**
195
195
  * Get all chapter reciters.
196
196
  * @description https://quran.api-docs.io/v4/resources/list-of-chapter-reciters
197
- * @param {GetResourcesOptions} options
197
+ * @param {GetResourceOptions} options
198
198
  * @example
199
199
  * quran.v4.resources.findAllChapterReciters()
200
200
  */
201
- const findAllChapterReciters = async (options?: GetResourcesOptions) => {
201
+ const findAllChapterReciters = async (options?: GetResourceOptions) => {
202
202
  const params = getResourcesOptions(options);
203
203
  const { reciters } = await fetcher<{
204
204
  reciters: ChapterReciterResource[];
@@ -20,13 +20,13 @@ const getSearchOptions = (q: string, options: SearchOptions = {}) => {
20
20
  /**
21
21
  * Search
22
22
  * @description https://quran.api-docs.io/v4/search/KfCmk4KQYbtyK9adj
23
- * @param q search query
24
- * @param options search options
23
+ * @param {string} q search query
24
+ * @param {SearchOptions} options
25
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 })
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
30
  */
31
31
  const search = async (q: string, options?: SearchOptions) => {
32
32
  const params = getSearchOptions(q, options);