Skip to content

Commit

Permalink
Remove empty-string from transliterated month names type
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Dec 31, 2024
1 parent 4394e40 commit 80adc27
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/hdateBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ export const months = {
ADAR_II,
} as const;

const NISAN_STR = 'Nisan';
const monthNames0 = [
'',
'Nisan',
NISAN_STR,
'Iyyar',
'Sivan',
'Tamuz',
Expand All @@ -65,18 +66,32 @@ const monthNames0 = [
"Sh'vat",
] as const;

/**
/*
* Transliterations of Hebrew month names.
* Regular years are index 0 and leap years are index 1.
* @private
*/
const monthNames = [
[...monthNames0, 'Adar', 'Nisan'],
[...monthNames0, 'Adar I', 'Adar II', 'Nisan'],
[...monthNames0, 'Adar', NISAN_STR],
[...monthNames0, 'Adar I', 'Adar II', NISAN_STR],
] as const;

/** Transliterated Hebrew month names. */
export type MonthName = (typeof monthNames)[number][number];
export type MonthName =
| 'Nisan'
| 'Iyyar'
| 'Sivan'
| 'Tamuz'
| 'Av'
| 'Elul'
| 'Tishrei'
| 'Cheshvan'
| 'Kislev'
| 'Tevet'
| "Sh'vat"
| 'Adar'
| 'Adar I'
| 'Adar II';

const edCache: Map<number, number> = new Map<number, number>();

Expand All @@ -87,7 +102,7 @@ const AVG_HEBYEAR_DAYS = 365.24682220597794;
/**
* @private
*/
function assertNumber(n: any, name: string) {
function assertNumber(n: unknown, name: string) {
if (typeof n !== 'number' || isNaN(n)) {
throw new TypeError(`invalid parameter '${name}' not a number: ${n}`);
}
Expand Down Expand Up @@ -236,7 +251,7 @@ export function getMonthName(month: number, year: number): MonthName {
if (month < 1 || month > 14) {
throw new TypeError(`bad month argument ${month}`);
}
return monthNames[+isLeapYear(year)][month];
return monthNames[+isLeapYear(year)][month] as MonthName;
}

/**
Expand Down

0 comments on commit 80adc27

Please sign in to comment.