Add eslint|prettier to the Quran package

This commit is contained in:
0x1eef 2024-10-17 22:37:09 -03:00
parent bb8df9270c
commit 926e551ad9
4 changed files with 37 additions and 20 deletions

3
package-lock.json generated
View file

@ -6392,6 +6392,9 @@
"devDependencies": {
"@types/node": "^22.0",
"babel-loader": "^9.2.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"prettier": "^3.3.3",
"typescript": "^5.5"
}
}

View file

@ -0,0 +1,12 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import prettier from 'eslint-plugin-prettier/recommended';
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
prettier,
{
rules: {'@typescript-eslint/no-require-imports': 0},
}
)

View file

@ -8,7 +8,8 @@
],
"scripts": {
"build": "npx webpack --config etc/webpack.config.js",
"prepare": "npm run build"
"prepare": "npm run build",
"format": "npx eslint --config etc/eslint.config.mjs --fix src/index.ts"
},
"repository": {
"type": "git",
@ -19,6 +20,9 @@
"devDependencies": {
"@types/node": "^22.0",
"babel-loader": "^9.2.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"prettier": "^3.3.3",
"typescript": "^5.5"
}
}

View file

@ -4,15 +4,15 @@
type TAyat = Ayah[];
type TLocale = {
readonly name: string,
readonly displayName: string,
readonly direction: "rtl" | "ltr"
readonly name: string;
readonly displayName: string;
readonly direction: "rtl" | "ltr";
};
type TQuran = {
readonly locale: TLocale;
readonly surahs: Surah[];
}
};
type TSurah = {
readonly id: number;
@ -26,7 +26,7 @@ type TSurah = {
type TAyah = {
readonly id: number;
readonly body: string;
}
};
/**
* Classes
@ -40,20 +40,22 @@ class Quran {
*/
static get locales(): Record<string, TLocale> {
return {
"en": {"name": "en", "displayName": "English", "direction": "ltr"},
"ar": {"name": "ar", "displayName": "العربية", "direction": "rtl"},
"fa": {"name": "fa", "displayName": "فارسی", "direction": "rtl"}
}
en: { name: "en", displayName: "English", direction: "ltr" },
ar: { name: "ar", displayName: "العربية", direction: "rtl" },
fa: { name: "fa", displayName: "فارسی", direction: "rtl" },
};
}
/**
* @returns {Record<string, Surah[]>} The available surahs
*/
static get surahs(): Record<string, Surah[]> {
const result: Record<string, Surah[]> = {}
const result: Record<string, Surah[]> = {};
const surahs: Record<string, TSurah[]> = require("@json/surahs");
for (const locale in surahs) {
result[locale] = surahs[locale].map((surah: TSurah) => new Surah({...surah, locale}));
result[locale] = surahs[locale].map(
(surah: TSurah) => new Surah({ ...surah, locale }),
);
}
return result;
}
@ -73,7 +75,7 @@ class Surah {
readonly locale: string;
readonly translatedBy: string | null;
constructor(self: TSurah & {locale: string}) {
constructor(self: TSurah & { locale: string }) {
this.id = self.id;
this.name = self.name;
this.urlName = self.urlName;
@ -85,8 +87,8 @@ class Surah {
}
get ayat(): Ayah[] {
const ayat = require(`@json/${this.locale}/${this.id}.json`)
return ayat.map(([id, body]) => new Ayah({id,body}));
const ayat = require(`@json/${this.locale}/${this.id}.json`);
return ayat.map(([id, body]) => new Ayah({ id, body }));
}
}
@ -105,8 +107,4 @@ class Ayah {
/**
* Exports
*/
export {
Quran, Surah, Ayah,
TQuran, TSurah, TAyah,
TAyat, TLocale
};
export { Quran, Surah, Ayah, TQuran, TSurah, TAyah, TAyat, TLocale };