UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

21 lines (19 loc) 780 B
import { checkValidAyahId } from "./validation.mjs"; import { binarySearch } from "./utils.mjs"; //#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) { checkValidAyahId(ayahId, data.meta); const SurahList = data.SurahList; const ss = binarySearch(SurahList, ayahId, (aya, b) => aya - b[0]); const suraNum = ss < 0 ? -ss - 2 : ss; return [suraNum, ayahId - SurahList[suraNum][0] + 1]; } //#endregion export { findSurahAyahByAyahId };