UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

21 lines (19 loc) 839 B
const require_validation = require('./validation.cjs'); const require_utils = require('./utils.cjs'); //#region src/findSurahAyahByAyahId.ts /** * Finds the Surah (chapter) and Ayah (verse) numbers that the given Ayah ID belongs to. * * @param ayahId - The Ayah ID to find the Surah and Ayah numbers for. * @param lists - The Lists object containing SurahList. * @returns An array containing the Surah number and the Ayah number within that Surah. */ function findSurahAyahByAyahId(ayahId, data) { require_validation.checkValidAyahId(ayahId, data.meta); const SurahList = data.SurahList; const ss = require_utils.binarySearch(SurahList, ayahId, (aya, b) => aya - b[0]); const suraNum = ss < 0 ? -ss - 2 : ss; return [suraNum, ayahId - SurahList[suraNum][0] + 1]; } //#endregion exports.findSurahAyahByAyahId = findSurahAyahByAyahId;