UNPKG

@sahabaplus/mushaf-engine

Version:

TypeScript implementation of a Quran Mushaf navigation engine

67 lines (66 loc) 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Verse = void 0; /** * Information about a single verse (ayah) in the Quran * * This class contains metadata about a verse, including its sura and number, * its position on the page, and how many lines it spans. */ class Verse { /** * Create a new Verse with the specified parameters * * @param sura - Sura number (1-114) * @param number - Verse number within the sura * @param position - Position on the page as [relative position 0.0-1.0, line number] * @param lines - Number of lines this verse spans (can be fractional) */ constructor(sura = 0, number = 0, position = [0, 0], lines = 0) { this.sura = sura; this.number = number; this.position = position; this.lines = lines; } /** * Check if the verse is the last of the page * * @returns true if the verse is the last of the page, false otherwise */ isLastOfPage() { return this.position[1] === 15; } /** * Create a string representation of the verse */ toString() { return `Sura ${this.sura}:${this.number} Position: (${this.position[0].toFixed(1)}, ${this.position[1]}) Lines: ${this.lines}`; } /** * Check if this verse equals another verse */ equals(other) { return (this.sura === other.sura && this.number === other.number && this.position[0] === other.position[0] && this.position[1] === other.position[1] && this.lines === other.lines); } /** * Compare this verse to another verse * Returns -1 if this verse comes before the other verse, * 0 if they are equal, and 1 if this verse comes after */ compareTo(other) { // First compare sura if (this.sura !== other.sura) { return this.sura < other.sura ? -1 : 1; } // If sura is the same, compare ayah number if (this.number !== other.number) { return this.number < other.number ? -1 : 1; } return 0; } } exports.Verse = Verse;