Add eslint|prettier to the Quran package
This commit is contained in:
parent
bb8df9270c
commit
926e551ad9
4 changed files with 37 additions and 20 deletions
3
package-lock.json
generated
3
package-lock.json
generated
|
@ -6392,6 +6392,9 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.0",
|
"@types/node": "^22.0",
|
||||||
"babel-loader": "^9.2.1",
|
"babel-loader": "^9.2.1",
|
||||||
|
"eslint-config-prettier": "^9.1.0",
|
||||||
|
"eslint-plugin-prettier": "^5.2.1",
|
||||||
|
"prettier": "^3.3.3",
|
||||||
"typescript": "^5.5"
|
"typescript": "^5.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
packages/typescript/Quran/etc/eslint.config.mjs
Normal file
12
packages/typescript/Quran/etc/eslint.config.mjs
Normal 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},
|
||||||
|
}
|
||||||
|
)
|
|
@ -8,7 +8,8 @@
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npx webpack --config etc/webpack.config.js",
|
"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": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -19,6 +20,9 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^22.0",
|
"@types/node": "^22.0",
|
||||||
"babel-loader": "^9.2.1",
|
"babel-loader": "^9.2.1",
|
||||||
|
"eslint-config-prettier": "^9.1.0",
|
||||||
|
"eslint-plugin-prettier": "^5.2.1",
|
||||||
|
"prettier": "^3.3.3",
|
||||||
"typescript": "^5.5"
|
"typescript": "^5.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,15 +4,15 @@
|
||||||
type TAyat = Ayah[];
|
type TAyat = Ayah[];
|
||||||
|
|
||||||
type TLocale = {
|
type TLocale = {
|
||||||
readonly name: string,
|
readonly name: string;
|
||||||
readonly displayName: string,
|
readonly displayName: string;
|
||||||
readonly direction: "rtl" | "ltr"
|
readonly direction: "rtl" | "ltr";
|
||||||
};
|
};
|
||||||
|
|
||||||
type TQuran = {
|
type TQuran = {
|
||||||
readonly locale: TLocale;
|
readonly locale: TLocale;
|
||||||
readonly surahs: Surah[];
|
readonly surahs: Surah[];
|
||||||
}
|
};
|
||||||
|
|
||||||
type TSurah = {
|
type TSurah = {
|
||||||
readonly id: number;
|
readonly id: number;
|
||||||
|
@ -26,7 +26,7 @@ type TSurah = {
|
||||||
type TAyah = {
|
type TAyah = {
|
||||||
readonly id: number;
|
readonly id: number;
|
||||||
readonly body: string;
|
readonly body: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classes
|
* Classes
|
||||||
|
@ -40,20 +40,22 @@ class Quran {
|
||||||
*/
|
*/
|
||||||
static get locales(): Record<string, TLocale> {
|
static get locales(): Record<string, TLocale> {
|
||||||
return {
|
return {
|
||||||
"en": {"name": "en", "displayName": "English", "direction": "ltr"},
|
en: { name: "en", displayName: "English", direction: "ltr" },
|
||||||
"ar": {"name": "ar", "displayName": "العربية", "direction": "rtl"},
|
ar: { name: "ar", displayName: "العربية", direction: "rtl" },
|
||||||
"fa": {"name": "fa", "displayName": "فارسی", "direction": "rtl"}
|
fa: { name: "fa", displayName: "فارسی", direction: "rtl" },
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Record<string, Surah[]>} The available surahs
|
* @returns {Record<string, Surah[]>} The available surahs
|
||||||
*/
|
*/
|
||||||
static get surahs(): Record<string, Surah[]> {
|
static get surahs(): Record<string, Surah[]> {
|
||||||
const result: Record<string, Surah[]> = {}
|
const result: Record<string, Surah[]> = {};
|
||||||
const surahs: Record<string, TSurah[]> = require("@json/surahs");
|
const surahs: Record<string, TSurah[]> = require("@json/surahs");
|
||||||
for (const locale in 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +75,7 @@ class Surah {
|
||||||
readonly locale: string;
|
readonly locale: string;
|
||||||
readonly translatedBy: string | null;
|
readonly translatedBy: string | null;
|
||||||
|
|
||||||
constructor(self: TSurah & {locale: string}) {
|
constructor(self: TSurah & { locale: string }) {
|
||||||
this.id = self.id;
|
this.id = self.id;
|
||||||
this.name = self.name;
|
this.name = self.name;
|
||||||
this.urlName = self.urlName;
|
this.urlName = self.urlName;
|
||||||
|
@ -85,8 +87,8 @@ class Surah {
|
||||||
}
|
}
|
||||||
|
|
||||||
get ayat(): Ayah[] {
|
get ayat(): Ayah[] {
|
||||||
const ayat = require(`@json/${this.locale}/${this.id}.json`)
|
const ayat = require(`@json/${this.locale}/${this.id}.json`);
|
||||||
return ayat.map(([id, body]) => new Ayah({id,body}));
|
return ayat.map(([id, body]) => new Ayah({ id, body }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,8 +107,4 @@ class Ayah {
|
||||||
/**
|
/**
|
||||||
* Exports
|
* Exports
|
||||||
*/
|
*/
|
||||||
export {
|
export { Quran, Surah, Ayah, TQuran, TSurah, TAyah, TAyat, TLocale };
|
||||||
Quran, Surah, Ayah,
|
|
||||||
TQuran, TSurah, TAyah,
|
|
||||||
TAyat, TLocale
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in a new issue