@sahabaplus/mushaf-engine
Version:
TypeScript implementation of a Quran Mushaf navigation engine
48 lines (47 loc) • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mushaf = void 0;
/**
* Representation of a complete Quran Mushaf (printed copy)
*
* This class contains all pages and verses of the Quran with their metadata,
* including information about line positions and page numbers.
*/
class Mushaf {
/**
* Create a new Mushaf with the specified parameters
*
* @param linesPerPage - Number of lines on each page in this Mushaf edition
* @param maxPage - Total number of pages in this Mushaf edition
* @param pages - Array containing all pages
*/
constructor(linesPerPage = 15, maxPage = 0, pages = []) {
this.linesPerPage = linesPerPage;
this.maxPage = maxPage;
this.pages = pages;
}
/**
* Get a page by its number (1-indexed)
*
* @param pageNumber - The page number to retrieve (1-indexed)
* @returns The requested page if it exists, undefined otherwise
*/
getPage(pageNumber) {
if (pageNumber === 0 || pageNumber > this.maxPage) {
return undefined;
}
return this.pages[pageNumber - 1];
}
/**
* Create a string representation of the Mushaf
*/
toString() {
let result = "=== Mushaf Summary ===\n";
result += `Total Pages: ${this.maxPage}\n`;
result += `Lines per Page: ${this.linesPerPage}\n`;
const totalVerses = this.pages.reduce((sum, page) => sum + page.verses().length, 0);
result += `Total Verses: ${totalVerses}\n`;
return result;
}
}
exports.Mushaf = Mushaf;