js/lib/: add Quran.ts, Quran/Surah.ts

This commit is contained in:
0x1eef 2022-10-30 23:46:34 -03:00
parent d7e593c95b
commit 34cd6129e8
2 changed files with 49 additions and 0 deletions

5
src/js/lib/Quran.ts Normal file
View file

@ -0,0 +1,5 @@
import { Surah, Ayah, Ayat } from "./Quran/Surah";
const Quran = {
Surah: Surah
};
export { Quran, Surah, Ayah, Ayat };

44
src/js/lib/Quran/Surah.ts Normal file
View file

@ -0,0 +1,44 @@
type SurahDetails = {
id: string,
place_of_revelation: string,
transliterated_name: string,
translated_name: string,
verse_count: number,
slug: string,
codepoints: Array<number>
}
export type Ayah = {num: number, text: string, readingTime: number};
export type Ayat = Array<Ayah>;
export class Surah {
#details: SurahDetails;
ayat: Ayat;
static fromJSON(details: SurahDetails, ayat: Array<[number, string]>): Surah {
return new Surah(
details,
ayat.map(([num, text]) => {
return {
num, text,
readingTime: text.split(" ").length * 500,
}
})
);
}
constructor(details: SurahDetails, ayat: Ayat) {
this.#details = details;
this.ayat = ayat;
}
getDetails() {
const {
id,
place_of_revelation: placeOfRevelation,
transliterated_name: transliteratedName,
translated_name: translatedName,
verse_count: ayahCount,
codepoints: arabicCodePoints
} = this.#details;
}
}