UNPKG

quran-meta

Version:

Library with meta data and functionality related to Holy Quran

91 lines 5.41 kB
//#region src/ts-utils.d.ts type GrowToSize<T, N extends number, A extends T[]> = A["length"] extends N ? A : GrowToSize<T, N, [...A, T]>; type FixedArray<T, N extends number> = GrowToSize<T, N, []>; type ArrayOfSameLength<T extends unknown[], U> = { [K in keyof T]: U }; type LessThan<TNumber extends number, TArray extends unknown[] = []> = TNumber extends TArray["length"] ? TArray[number] : LessThan<TNumber, [...TArray, TArray["length"]]>; //#endregion //#region src/types.d.ts /** * The maximum number of ayahs (verses) that can exist in any surah (chapter) of the Quran. * This maximum occurs in Surah Al-Baqarah (2), which has 286 ayahs. */ declare const maxAyahsInSurah = 286; /** * Total number of surahs (chapters) in the Quran. * This is constant across all riwayas. */ declare const numSurahs = 114; /** * Creates a type representing a range of numbers from TStart to TEnd (inclusive). * * @typeParam TStart - The starting number of the range * @typeParam TEnd - The ending number of the range * * * @remarks * This type uses the Exclude utility type along with a LessThan helper type * to generate a union of all numbers within the specified range. */ type NumericRange<TStart extends number, TEnd extends number> = Exclude<TEnd | LessThan<TEnd>, LessThan<TStart>>; /** * Represents a valid Surah number in the Quran. * A type that ensures the number is within the valid range of Surahs (1 to 114). */ type Surah = NumericRange<1, typeof numSurahs>; /** * Represents the number of an ayah (verse) within a surah. * Valid values are between 1 and the maximum number of ayahs in any surah. * */ type AyahNo = NumericRange<1, typeof maxAyahsInSurah>; /** * Represents a numeric identifier for an Ayah (verse) in the Quran. * The value should be between 0 and the total number of Ayahs. */ type AyahId = number; /** * A type representing a valid Ruku (section) number in the Quran. * Uses 1-based indexing where 1 is the first ruku (typically 556 rukus in Hafs). */ type Ruku = NumericRange<1, 556>; type SurahInfo = [startAyahId: AyahId, ayahCount: AyahNo, surahOrder: Surah, rukuCount: Ruku, name: string, isMeccan: boolean]; type SurahListType = FixedArray<SurahInfo, 116>; type SurahName = [name: string, translitName: string]; //#endregion //#region src/i18n/types.d.ts type SurahNames = ArrayOfSameLength<SurahListType, SurahName | []>; declare const languages: readonly ["en", "az", "ru", "tr"]; type Lang = typeof languages[number]; type SurahNamesI18n = { [K in Lang]: SurahNames }; //#endregion //#region src/i18n/surah.en.d.ts declare const surahNamesEn: SurahNames; //#endregion //#region src/i18n/surah.az.d.ts declare const surahNamesAz: SurahNames; //#endregion //#region src/i18n/surah.ru.d.ts declare const surahNamesRu: SurahNames; //#endregion //#region src/i18n/surah.tr.d.ts declare const surahNamesTr: SurahNames; //#endregion //#region src/i18n/getSurahNames.d.ts /** * Retrieves the list of Surah names in the specified language. * * @param lang - The language code for which to retrieve the Surah names * @returns An array of Surah names in the specified language * * @example * ```typescript * const arabicNames = getSurahNames('ar'); * const englishNames = getSurahNames('en'); * ``` */ declare function getSurahNames(lang: Lang): [[] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName, [] | SurahName]; //#endregion //#region src/i18n/index.d.ts declare const surahNames: SurahNamesI18n; //#endregion export { type Lang, type SurahNames, type SurahNamesI18n, getSurahNames, surahNames, surahNamesAz, surahNamesEn, surahNamesRu, surahNamesTr };