Skip to content

Commit

Permalink
feat: docs string provided for the api methods
Browse files Browse the repository at this point in the history
  • Loading branch information
PrantaDas committed Aug 24, 2024
1 parent 3ed55da commit 24492f2
Show file tree
Hide file tree
Showing 9 changed files with 376 additions and 5 deletions.
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "al-quran-api",
"name": "al-quran-js",
"version": "1.0.0",
"description": "An API wrapper for Quran on top of quran.com",
"main": "./dist/index.js",
Expand All @@ -20,7 +20,17 @@
"test": "jest",
"start": "ts-node src/index.ts"
},
"keywords": [],
"keywords": [
"al-quran",
"api",
"quran",
"quran.com",
"al-quran-api",
"verse",
"ayah",
"juz",
"quran-js"
],
"files": [
"dist",
"README.md",
Expand All @@ -47,4 +57,4 @@
"agentkeepalive": "^4.5.0",
"axios": "^1.7.2"
}
}
}
94 changes: 93 additions & 1 deletion src/apis/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ const api = Api();

export const audio: AudioApi = {

/**
* Retrieves audio recordings of a specific chapter by a particular reciter.
*
* @param id - The ID of the reciter.
* @param chapter_number - The number of the chapter.
* @returns A promise that resolves to the audio recordings or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/chapter-reciter-audio-file}
*/
getChaptersAudioOfAReciter(id: number, chapter_number: number): Promise<IAudio | Error | AxiosError> {
if (!id || !chapter_number)
return Promise.reject(new Error('Reciter\'s ID and Chapter number is required'));
Expand All @@ -26,6 +34,13 @@ export const audio: AudioApi = {
});
},

/**
* Retrieves all audio recordings for a specific reciter.
*
* @param id - The ID of the reciter.
* @returns A promise that resolves to the list of audio recordings or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/chapter-reciter-audio-files}
*/
getAllChaptersAudioOfAReciter(id: number): Promise<IListOfAllAudioOfAReciter | Error | AxiosError> {
if (!id)
return Promise.reject(new Error('Reciter\'s ID is required'));
Expand All @@ -37,7 +52,13 @@ export const audio: AudioApi = {
});
},


/**
* Retrieves a list of recitations available in the specified language.
*
* @param language - The language code. Defaults to 'en'.
* @returns A promise that resolves to the list of recitations or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/recitations}
*/
getRecitations(language: string = 'en'): Promise<IRecitation | Error | AxiosError> {
const isLanguageSupported = ALLOWED_LANGUAGES.has(language);
if (!isLanguageSupported) return Promise.reject(new Error("Provided language is not supported"));
Expand All @@ -48,6 +69,15 @@ export const audio: AudioApi = {
});
},


/**
* Retrieves all audio files for a specific recitation, optionally filtered by query parameters.
*
* @param recitation_id - The ID of the recitation.
* @param query - Optional query parameters to filter the audio files.
* @returns A promise that resolves to the list of audio files or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/recitation-autio-files}
*/
getAllAudioFilesofARecitation(recitation_id: number, query?: AudioQueryParams): Promise<ISingleRecitation | Error | AxiosError> {
if (!recitation_id) return Promise.reject(new Error('recitation_id is required'));
let uri = `/quran/recitations/${recitation_id}`;
Expand All @@ -61,6 +91,14 @@ export const audio: AudioApi = {
},



/**
* Retrieves a list of chapter reciters available in the specified language.
*
* @param language - The language code. Defaults to 'en'.
* @returns A promise that resolves to the list of chapter reciters or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/chapter-reciters}
*/
getListOfChapterReciters(language: string = 'en'): Promise<IReciters | Error | AxiosError> {
const isLanguageSupported = ALLOWED_LANGUAGES.has(language);
if (!isLanguageSupported) return Promise.reject(new Error("Provided language is not supported"));
Expand All @@ -71,6 +109,15 @@ export const audio: AudioApi = {
});
},


/**
* Retrieves audio recitations for a specific chapter by a particular reciter.
*
* @param recitation_id - The ID of the reciter.
* @param chapter_number - The number of the chapter.
* @returns A promise that resolves to the audio recitations or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/list-surah-recitation}
*/
getAyahRecitationsForSpecificSurah(recitation_id: number, chapter_number: number): Promise<IAyahRecitationSpecificSurah | Error | AxiosError> {
if (!recitation_id || !chapter_number)
return Promise.reject(new Error('recitation_id and Chapter number is required'));
Expand All @@ -81,6 +128,15 @@ export const audio: AudioApi = {
});
},


/**
* Retrieves audio recitations for a specific Juz by a particular reciter.
*
* @param recitation_id - The ID of the reciter.
* @param juz_number - The number of the Juz.
* @returns A promise that resolves to the audio recitations or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/list-juz-recitaiton}
*/
getAyahRecitationsForSpecificJuz(recitation_id: number, juz_number: number): Promise<IAyahRecitationSpecificJuz | Error | AxiosError> {
if (!recitation_id || !juz_number)
return Promise.reject(new Error('recitation_id and juz_number is required'));
Expand All @@ -91,6 +147,15 @@ export const audio: AudioApi = {
});
},


/**
* Retrieves audio recitations for a specific Madani Mushaf page by a particular reciter.
*
* @param recitation_id - The ID of the reciter.
* @param page_number - The number of the Madani Mushaf page.
* @returns A promise that resolves to the audio recitations or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/list-page-recitaiton}
*/
getAyahRecitationForSpecificMadaniMushafPage(recitation_id: number, page_number: number): Promise<IAyahRecitationSpecificMadaniMushafPage | Error | AxiosError> {
if (!recitation_id || !page_number)
return Promise.reject(new Error('recitation_id and Page number is required'));
Expand All @@ -101,6 +166,15 @@ export const audio: AudioApi = {
});
},


/**
* Retrieves audio recitations for a specific Rub El Hizb by a particular reciter.
*
* @param recitation_id - The ID of the reciter.
* @param rub_el_hizb_number - The number of the Rub El Hizb.
* @returns A promise that resolves to the audio recitations or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/list-rub-el-hizb-recitaiton}
*/
getAyahRecitationForSpecificRubelHizb(recitation_id: number, rub_el_hizb_number: number): Promise<IAyahRecitationSpecificRubelHizb | Error | AxiosError> {
if (!recitation_id || !rub_el_hizb_number)
return Promise.reject(new Error('recitation_id and rub_el_hizb_number is required'));
Expand All @@ -111,6 +185,15 @@ export const audio: AudioApi = {
});
},


/**
* Retrieves audio recitations for a specific Hizb by a particular reciter.
*
* @param recitation_id - The ID of the reciter.
* @param hizb_number - The number of the Hizb.
* @returns A promise that resolves to the audio recitations or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/list-hizb-recitaiton}
*/
getAyahRecitationForSpecificHizb(recitation_id: number, hizb_number: number): Promise<IAyahRecitationSpecificHizb | Error | AxiosError> {
if (!recitation_id || !hizb_number)
return Promise.reject(new Error('recitation_id and hizb_number is required'));
Expand All @@ -121,6 +204,15 @@ export const audio: AudioApi = {
});
},


/**
* Retrieves audio recitations for a specific Ayah by a particular reciter.
*
* @param recitation_id - The ID of the reciter.
* @param ayah_key - The key of the Ayah.
* @returns A promise that resolves to the audio recitations or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/list-ayah-recitaiton}
*/
getAyahRecitationForSpecificAyah(recitation_id: number, ayah_key: string): Promise<IAyahRecitationSpecificAyah | Error | AxiosError> {
if (!recitation_id || !ayah_key)
return Promise.reject(new Error('recitation_id and ayah_key is required'));
Expand Down
26 changes: 26 additions & 0 deletions src/apis/chapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const api = Api();


export const chapter: ChapterApi = {

/**
* Retrieves a list of all chapters in the Quran.
*
* @param language - The language code for the chapter names. Defaults to 'en'.
* @returns A promise that resolves to the list of chapters or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/list-chapters}
*/
listChapters(language = 'en'): Promise<ListChapters | Error | AxiosError> {
const isLanguageSupported = language && ALLOWED_LANGUAGES.has(language);
if (!isLanguageSupported) return Promise.reject(new Error("Provided language is not supported"));
Expand All @@ -16,6 +24,15 @@ export const chapter: ChapterApi = {
.catch(handleError(reject));
});
},

/**
* Retrieves information about a specific chapter.
*
* @param id - The ID of the chapter to retrieve.
* @param language - The language code for the chapter information. Defaults to 'en'.
* @returns A promise that resolves to the chapter details or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/get-chapter}
*/
getChapter(id: number, language = 'en'): Promise<Chapter | Error | AxiosError> {
if (language && !ALLOWED_LANGUAGES.has(language)) return Promise.reject(new Error("Provided language is not supported"));
return new Promise((resolve, reject) => {
Expand All @@ -24,6 +41,15 @@ export const chapter: ChapterApi = {
.catch(handleError(reject));
});
},

/**
* Retrieves detailed information about a specific chapter.
*
* @param chapter_id - The ID of the chapter to retrieve information for.
* @param language - The language code for the chapter information. Defaults to 'en'.
* @returns A promise that resolves to the chapter information or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/info}
*/
getChapterInfo(chapter_id: number, language = 'en'): Promise<ChapterInfo | Error | AxiosError> {
if (language && !ALLOWED_LANGUAGES.has(language)) return Promise.reject(new Error("Provided language is not supported"));
return new Promise((resolve, reject) => {
Expand Down
8 changes: 8 additions & 0 deletions src/apis/juz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import { handleError, handleResponse } from "../utils";
const api = Api();

export const juz: JuzApi = {

/**
* Retrieves a list of all Juzs (sections) of the Quran.
*
* @returns A promise that resolves to the list of Juzs or rejects with an error.
* @see {@link https://api-docs.quran.com/docs/quran.com_versioned/juzs}
*/

getAllJuzs(): Promise<JuzResponse | Error | AxiosError> {
return new Promise((resolve, reject) => {
api.get('/juzs')
Expand Down
Loading

0 comments on commit 24492f2

Please sign in to comment.