mirror of
https://github.com/acamarata/date-fns-hijri.git
synced 2026-06-30 18:54:25 +00:00
chore: adopt shared config packages (tsconfig, eslint, prettier)
This commit is contained in:
parent
d19c624bce
commit
a86df7dc09
6 changed files with 88 additions and 33 deletions
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"singleQuote": true,
|
|
||||||
"trailingComma": "all",
|
|
||||||
"printWidth": 100,
|
|
||||||
"tabWidth": 2
|
|
||||||
}
|
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
import eslint from '@eslint/js';
|
import tsParser from '@typescript-eslint/parser';
|
||||||
import tseslint from 'typescript-eslint';
|
import tsPlugin from '@typescript-eslint/eslint-plugin';
|
||||||
import eslintConfigPrettier from 'eslint-config-prettier';
|
import eslintConfigPrettier from 'eslint-config-prettier';
|
||||||
|
import { typescript } from '@acamarata/eslint-config';
|
||||||
|
|
||||||
export default tseslint.config(
|
export default [
|
||||||
eslint.configs.recommended,
|
{
|
||||||
...tseslint.configs.recommended,
|
plugins: { '@typescript-eslint': tsPlugin },
|
||||||
|
languageOptions: { parser: tsParser },
|
||||||
|
},
|
||||||
|
...typescript,
|
||||||
eslintConfigPrettier,
|
eslintConfigPrettier,
|
||||||
{
|
{
|
||||||
ignores: ['dist/', 'node_modules/', 'test.mjs', 'test-cjs.cjs'],
|
ignores: ['dist/', 'node_modules/', 'test.mjs', 'test-cjs.cjs'],
|
||||||
},
|
},
|
||||||
);
|
];
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,9 @@
|
||||||
"hijri-core": "^1.0.0"
|
"hijri-core": "^1.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@acamarata/eslint-config": "^0.1.0",
|
||||||
|
"@acamarata/prettier-config": "^0.1.0",
|
||||||
|
"@acamarata/tsconfig": "^0.1.0",
|
||||||
"@eslint/js": "^10.0.1",
|
"@eslint/js": "^10.0.1",
|
||||||
"@types/node": "^25.3.5",
|
"@types/node": "^25.3.5",
|
||||||
"eslint": "^10.0.3",
|
"eslint": "^10.0.3",
|
||||||
|
|
@ -79,5 +82,6 @@
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/acamarata/date-fns-hijri/issues"
|
"url": "https://github.com/acamarata/date-fns-hijri/issues"
|
||||||
},
|
},
|
||||||
"type": "module"
|
"type": "module",
|
||||||
|
"prettier": "@acamarata/prettier-config"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,15 @@ importers:
|
||||||
|
|
||||||
.:
|
.:
|
||||||
devDependencies:
|
devDependencies:
|
||||||
|
'@acamarata/eslint-config':
|
||||||
|
specifier: ^0.1.0
|
||||||
|
version: 0.1.0(@typescript-eslint/eslint-plugin@8.56.1(@typescript-eslint/parser@8.56.1(eslint@10.0.3)(typescript@5.9.3))(eslint@10.0.3)(typescript@5.9.3))(@typescript-eslint/parser@8.56.1(eslint@10.0.3)(typescript@5.9.3))(eslint-config-prettier@10.1.8(eslint@10.0.3))(eslint@10.0.3)
|
||||||
|
'@acamarata/prettier-config':
|
||||||
|
specifier: ^0.1.0
|
||||||
|
version: 0.1.0(prettier@3.8.1)
|
||||||
|
'@acamarata/tsconfig':
|
||||||
|
specifier: ^0.1.0
|
||||||
|
version: 0.1.0
|
||||||
'@eslint/js':
|
'@eslint/js':
|
||||||
specifier: ^10.0.1
|
specifier: ^10.0.1
|
||||||
version: 10.0.1(eslint@10.0.3)
|
version: 10.0.1(eslint@10.0.3)
|
||||||
|
|
@ -38,6 +47,32 @@ importers:
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
|
|
||||||
|
'@acamarata/eslint-config@0.1.0':
|
||||||
|
resolution: {integrity: sha512-St2TObpHKXBLBy1GPrXWlHzXCujJ7jaor6BuWRdLMTOjM56LPBDJx+898R7yFyI8Wi52VWNZdSTPxzHuyRAq+A==}
|
||||||
|
engines: {node: '>=20'}
|
||||||
|
peerDependencies:
|
||||||
|
'@typescript-eslint/eslint-plugin': '>=8.0.0'
|
||||||
|
'@typescript-eslint/parser': '>=8.0.0'
|
||||||
|
eslint: '>=9.0.0'
|
||||||
|
eslint-config-prettier: '>=9.0.0'
|
||||||
|
eslint-plugin-react: '>=7.0.0'
|
||||||
|
eslint-plugin-react-hooks: '>=5.0.0'
|
||||||
|
peerDependenciesMeta:
|
||||||
|
eslint-plugin-react:
|
||||||
|
optional: true
|
||||||
|
eslint-plugin-react-hooks:
|
||||||
|
optional: true
|
||||||
|
|
||||||
|
'@acamarata/prettier-config@0.1.0':
|
||||||
|
resolution: {integrity: sha512-ImMnz/653ettR4gJVd1f7Pz61DQSeDmUtguLrnCl8RdYncqfghT+QGEO5Znml0KvgX3vk4c4roPAWYdXaZgcPA==}
|
||||||
|
engines: {node: '>=20'}
|
||||||
|
peerDependencies:
|
||||||
|
prettier: '>=3.0.0'
|
||||||
|
|
||||||
|
'@acamarata/tsconfig@0.1.0':
|
||||||
|
resolution: {integrity: sha512-bgzyBak43mE+0HhduZX3cvaPjKcggtGGZZMjr35qtYWolsIWgZ9nx7OOswbVYoU35qoUv6rZ0mTK6GbZ8QTYjw==}
|
||||||
|
engines: {node: '>=20'}
|
||||||
|
|
||||||
'@esbuild/aix-ppc64@0.27.3':
|
'@esbuild/aix-ppc64@0.27.3':
|
||||||
resolution: {integrity: sha512-9fJMTNFTWZMh5qwrBItuziu834eOCUcEqymSH7pY+zoMVEZg3gcPuBNxH1EvfVYe9h0x/Ptw8KBzv7qxb7l8dg==}
|
resolution: {integrity: sha512-9fJMTNFTWZMh5qwrBItuziu834eOCUcEqymSH7pY+zoMVEZg3gcPuBNxH1EvfVYe9h0x/Ptw8KBzv7qxb7l8dg==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
|
|
@ -912,6 +947,19 @@ packages:
|
||||||
|
|
||||||
snapshots:
|
snapshots:
|
||||||
|
|
||||||
|
'@acamarata/eslint-config@0.1.0(@typescript-eslint/eslint-plugin@8.56.1(@typescript-eslint/parser@8.56.1(eslint@10.0.3)(typescript@5.9.3))(eslint@10.0.3)(typescript@5.9.3))(@typescript-eslint/parser@8.56.1(eslint@10.0.3)(typescript@5.9.3))(eslint-config-prettier@10.1.8(eslint@10.0.3))(eslint@10.0.3)':
|
||||||
|
dependencies:
|
||||||
|
'@typescript-eslint/eslint-plugin': 8.56.1(@typescript-eslint/parser@8.56.1(eslint@10.0.3)(typescript@5.9.3))(eslint@10.0.3)(typescript@5.9.3)
|
||||||
|
'@typescript-eslint/parser': 8.56.1(eslint@10.0.3)(typescript@5.9.3)
|
||||||
|
eslint: 10.0.3
|
||||||
|
eslint-config-prettier: 10.1.8(eslint@10.0.3)
|
||||||
|
|
||||||
|
'@acamarata/prettier-config@0.1.0(prettier@3.8.1)':
|
||||||
|
dependencies:
|
||||||
|
prettier: 3.8.1
|
||||||
|
|
||||||
|
'@acamarata/tsconfig@0.1.0': {}
|
||||||
|
|
||||||
'@esbuild/aix-ppc64@0.27.3':
|
'@esbuild/aix-ppc64@0.27.3':
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
|
|
||||||
33
src/index.ts
33
src/index.ts
|
|
@ -128,9 +128,13 @@ export function getHijriMonthName(
|
||||||
throw new RangeError(`Hijri month must be 1–12, got ${hm}.`);
|
throw new RangeError(`Hijri month must be 1–12, got ${hm}.`);
|
||||||
}
|
}
|
||||||
const idx = hm - 1;
|
const idx = hm - 1;
|
||||||
if (length === 'medium') return hmMedium[idx];
|
// Non-null: hm validated 1-12 above; idx is always 0-11, within all hm* array bounds.
|
||||||
if (length === 'short') return hmShort[idx];
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
return hmLong[idx];
|
if (length === 'medium') return hmMedium[idx]!;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
if (length === 'short') return hmShort[idx]!;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
return hmLong[idx]!;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -143,7 +147,9 @@ export function getHijriMonthName(
|
||||||
*/
|
*/
|
||||||
export function getHijriWeekdayName(date: Date, length: 'long' | 'short' = 'long'): string {
|
export function getHijriWeekdayName(date: Date, length: 'long' | 'short' = 'long'): string {
|
||||||
const day = date.getDay(); // 0–6
|
const day = date.getDay(); // 0–6
|
||||||
return length === 'short' ? hwShort[day] : hwLong[day];
|
// Non-null: day is always 0-6 from getDay(), within hw* array bounds.
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
return length === 'short' ? hwShort[day]! : hwLong[day]!;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
@ -186,16 +192,19 @@ export function formatHijriDate(
|
||||||
|
|
||||||
const day = date.getDay(); // 0–6
|
const day = date.getDay(); // 0–6
|
||||||
|
|
||||||
return formatStr.replace(TOKEN_RE, (token) => {
|
return formatStr.replace(TOKEN_RE, (token): string => {
|
||||||
switch (token) {
|
switch (token) {
|
||||||
case 'iYYYY':
|
case 'iYYYY':
|
||||||
return String(h.hy);
|
return String(h.hy);
|
||||||
case 'iYY':
|
case 'iYY':
|
||||||
return String(h.hy).slice(-2).padStart(2, '0');
|
return String(h.hy).slice(-2).padStart(2, '0');
|
||||||
case 'iMMMM':
|
case 'iMMMM':
|
||||||
return hmLong[h.hm - 1];
|
// Non-null: hm is a valid Hijri month 1-12; index hm-1 is within hmLong bounds.
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
return hmLong[h.hm - 1]!;
|
||||||
case 'iMMM':
|
case 'iMMM':
|
||||||
return hmMedium[h.hm - 1];
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
return hmMedium[h.hm - 1]!;
|
||||||
case 'iMM':
|
case 'iMM':
|
||||||
return String(h.hm).padStart(2, '0');
|
return String(h.hm).padStart(2, '0');
|
||||||
case 'iM':
|
case 'iM':
|
||||||
|
|
@ -205,11 +214,15 @@ export function formatHijriDate(
|
||||||
case 'iD':
|
case 'iD':
|
||||||
return String(h.hd);
|
return String(h.hd);
|
||||||
case 'iEEEE':
|
case 'iEEEE':
|
||||||
return hwLong[day];
|
// Non-null: day is always 0-6 from getDay(), within hwLong bounds.
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
return hwLong[day]!;
|
||||||
case 'iEEE':
|
case 'iEEE':
|
||||||
return hwShort[day];
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
return hwShort[day]!;
|
||||||
case 'iE':
|
case 'iE':
|
||||||
return String(hwNumeric[day]);
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
|
return String(hwNumeric[day]!);
|
||||||
case 'ioooo':
|
case 'ioooo':
|
||||||
return 'AH';
|
return 'AH';
|
||||||
case 'iooo':
|
case 'iooo':
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,9 @@
|
||||||
{
|
{
|
||||||
|
"extends": "@acamarata/tsconfig/tsconfig.library.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2020",
|
|
||||||
"module": "ESNext",
|
|
||||||
"moduleResolution": "bundler",
|
|
||||||
"strict": true,
|
|
||||||
"forceConsistentCasingInFileNames": true,
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"declaration": true,
|
|
||||||
"declarationMap": true,
|
|
||||||
"noImplicitReturns": true,
|
"noImplicitReturns": true,
|
||||||
"noFallthroughCasesInSwitch": true,
|
"noFallthroughCasesInSwitch": true,
|
||||||
"sourceMap": true,
|
"esModuleInterop": true,
|
||||||
"outDir": "dist",
|
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
"types": ["node"]
|
"types": ["node"]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue