Skip to main content
The library provides three async loader functions for lazy-loading datasets. These loaders use dynamic imports for code splitting, keeping your initial bundle size minimal.

Overview

All data loaders are asynchronous and should be called once at app startup:

Load Quran data

loadQuranData()

Loads the complete Quran dataset containing 6,236 verses with text in both standard and Uthmani scripts. Returns: Promise<QuranText[]> Use case: Load once at app startup (browser or Node), then reuse in searches.
The QuranText type includes fields like sura_id, aya_id, gid, page_id, juz_id, sura_name, uthmani, standard, and more.

Load morphology data

loadMorphology()

Loads morphological analysis data (lemmas and roots) for all verses. This large dataset is loaded asynchronously to avoid increasing the initial bundle size. Returns: Promise<Map<number, MorphologyAya>> Use case: Enable lemma/root search and scoring.
The morphology data is stored as a Map for O(1) access by verse GID.

Load word map

loadWordMap()

Loads the word map dictionary that maps normalized Arabic tokens to their canonical lemma and root forms. Returns: Promise<WordMap> Use case: Map normalized query tokens to their canonical lemma/root for linguistic matching.

Error handling

All loader functions include built-in error handling. If a required data file is missing, they throw descriptive errors:
Ensure all data files exist in src/data/ before running the loaders:
  • src/data/quran.json
  • src/data/morphology.json
  • src/data/word-map.json

Data sources

The bundled lemma (morphology) data and word map were downloaded from Quranic Arabic Corpus v4.0: https://corpus.quran.com

Implementation details

From src/utils/loader.ts:9-31:
The loader:
  1. Uses dynamic imports for automatic code splitting
  2. Handles both default and named exports for bundler compatibility
  3. Transforms the array into a Map for optimal lookup performance
  4. Validates data structure before adding to the map