Skip to content

Commit d032c2b

Browse files
SLaksmjradwin
authored andcommitted
Make getMonth() return strong string types
I didn't change setMonth(), because that accepts more variants
1 parent 6e20f9e commit d032c2b

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/hdate.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
*/
2121
import {
22+
MonthName,
2223
SimpleHebrewDate,
2324
abs2hebrew,
2425
daysInMonth,
@@ -324,7 +325,7 @@ export class HDate {
324325
* const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
325326
* hd.getMonthName(); // 'Cheshvan'
326327
*/
327-
getMonthName(): string {
328+
getMonthName(): MonthName {
328329
return getMonthName(this.getMonth(), this.getFullYear());
329330
}
330331

@@ -610,7 +611,7 @@ export class HDate {
610611
* import {HDate, months} from '@hebcal/hdate';
611612
* HDate.getMonthName(months.CHESHVAN, 5769); // 'Cheshvan'
612613
*/
613-
static getMonthName(month: number, year: number): string {
614+
static getMonthName(month: number, year: number): MonthName {
614615
return getMonthName(month, year);
615616
}
616617

src/hdateBase.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const months = {
5050
ADAR_II,
5151
} as const;
5252

53-
const monthNames0: string[] = [
53+
const monthNames0 = [
5454
'',
5555
'Nisan',
5656
'Iyyar',
@@ -70,11 +70,14 @@ const monthNames0: string[] = [
7070
* Regular years are index 0 and leap years are index 1.
7171
* @private
7272
*/
73-
const monthNames: string[][] = [
74-
monthNames0.concat(['Adar', 'Nisan']),
75-
monthNames0.concat(['Adar I', 'Adar II', 'Nisan']),
73+
const monthNames = [
74+
[...monthNames0, 'Adar', 'Nisan'],
75+
[...monthNames0, 'Adar I', 'Adar II', 'Nisan'],
7676
] as const;
7777

78+
/** Transliterated Hebrew month names. */
79+
export type MonthName = (typeof monthNames)[number][number];
80+
7881
const edCache: Map<number, number> = new Map<number, number>();
7982

8083
const EPOCH = -1373428;
@@ -227,7 +230,7 @@ export function daysInMonth(month: number, year: number): number {
227230
* @param month Hebrew month (e.g. months.TISHREI)
228231
* @param year Hebrew year
229232
*/
230-
export function getMonthName(month: number, year: number): string {
233+
export function getMonthName(month: number, year: number): MonthName {
231234
assertNumber(month, 'month');
232235
assertNumber(year, 'year');
233236
if (month < 1 || month > 14) {

0 commit comments

Comments
 (0)