|
| 1 | +--- |
| 2 | +id: usage |
| 3 | +title: "📚 SDK Usage" |
| 4 | +sidebar_label: Usage Examples |
| 5 | +--- |
| 6 | + |
| 7 | +This page highlights the main wrappers exported by the SDK. All examples assume you have already called `configure`. |
| 8 | + |
| 9 | +## Chapters |
| 10 | + |
| 11 | +```javascript |
| 12 | +// List all chapters |
| 13 | +const chapters = await quran.qf.chapters.findAll(); |
| 14 | + |
| 15 | +// Get a single chapter by ID |
| 16 | +const chapter = await quran.qf.chapters.findById('1'); |
| 17 | + |
| 18 | +// Retrieve chapter information |
| 19 | +const info = await quran.qf.chapters.findInfoById('1'); |
| 20 | +``` |
| 21 | + |
| 22 | +## Verses |
| 23 | + |
| 24 | +```javascript |
| 25 | +// Get verses of a chapter |
| 26 | +const verses = await quran.qf.verses.findByChapter('1'); |
| 27 | + |
| 28 | +// Fetch a verse by key |
| 29 | +const verse = await quran.qf.verses.findByKey('1:1'); |
| 30 | + |
| 31 | +// Retrieve a random verse |
| 32 | +const random = await quran.qf.verses.findRandom(); |
| 33 | +``` |
| 34 | + |
| 35 | +Additional helpers include `findByPage`, `findByJuz`, `findByHizb` and `findByRub`. |
| 36 | + |
| 37 | +## Juzs |
| 38 | + |
| 39 | +```javascript |
| 40 | +const juzs = await quran.qf.juzs.findAll(); |
| 41 | +``` |
| 42 | + |
| 43 | +## Audio |
| 44 | + |
| 45 | +```javascript |
| 46 | +// All chapter recitations for a reciter |
| 47 | +const files = await quran.qf.audio.findAllChapterRecitations('2'); |
| 48 | + |
| 49 | +// Verse recitations by chapter |
| 50 | +const recitations = await quran.qf.audio.findVerseRecitationsByChapter('1', '2'); |
| 51 | +``` |
| 52 | + |
| 53 | +Other helpers cover pages, hizbs, rubs and specific verses. |
| 54 | + |
| 55 | +## Resources |
| 56 | + |
| 57 | +```javascript |
| 58 | +// Available translations |
| 59 | +const translations = await quran.qf.resources.findAllTranslations(); |
| 60 | + |
| 61 | +// Reciter information |
| 62 | +const reciterInfo = await quran.qf.resources.findRecitationInfo('1'); |
| 63 | +``` |
| 64 | + |
| 65 | +This wrapper also exposes methods for languages, tafsirs, recitation styles, chapter reciters and more. |
| 66 | + |
| 67 | +## Search |
| 68 | + |
| 69 | +```javascript |
| 70 | +const results = await quran.qf.search.search('mercy'); |
| 71 | +``` |
| 72 | + |
| 73 | +## Utilities |
| 74 | + |
| 75 | +```javascript |
| 76 | +import { quran } from '@quranjs/api'; |
| 77 | + |
| 78 | +quran.utils.isValidVerseKey('2:255'); // true |
| 79 | +quran.utils.isValidChapterId('115'); // false |
| 80 | +``` |
| 81 | + |
| 82 | +See the [Endpoint Reference](endpoints.md) for a list of API routes these wrappers use. |
0 commit comments