Skip to content

Commit 1ed1bcc

Browse files
committed
Fix several Typescript lint warnings
1 parent 0c532bf commit 1ed1bcc

File tree

4 files changed

+159
-117
lines changed

4 files changed

+159
-117
lines changed

src/anniversary.ts

+58-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import {hebrew2abs, abs2hebrew, isLeapYear, months, monthsInYear,
2-
shortKislev, longCheshvan, SimpleHebrewDate} from './hdate';
1+
import {
2+
hebrew2abs,
3+
abs2hebrew,
4+
isLeapYear,
5+
months,
6+
monthsInYear,
7+
shortKislev,
8+
longCheshvan,
9+
SimpleHebrewDate,
10+
} from './hdate';
311
import {greg} from './greg';
412

513
const NISAN = months.NISAN;
@@ -11,21 +19,26 @@ const ADAR_I = months.ADAR_I;
1119
const ADAR_II = months.ADAR_II;
1220

1321
/**
14-
* Returns true if the object is a Javascript Date
22+
* Returns true if the object is a SimpleHebrewDate
1523
* @private
1624
* @param {Object} obj
1725
*/
1826
function isSimpleHebrewDate(obj: any): boolean {
19-
return typeof obj === 'object' && obj !== null &&
27+
return (
28+
typeof obj === 'object' &&
29+
obj !== null &&
2030
typeof obj.yy === 'number' &&
2131
typeof obj.mm === 'number' &&
22-
typeof obj.dd === 'number';
32+
typeof obj.dd === 'number'
33+
);
2334
}
2435

2536
/**
2637
* @private
2738
*/
28-
function toSimpleHebrewDate(obj: Date | SimpleHebrewDate | number): SimpleHebrewDate {
39+
function toSimpleHebrewDate(
40+
obj: Date | SimpleHebrewDate | number
41+
): SimpleHebrewDate {
2942
if (isSimpleHebrewDate(obj)) {
3043
return obj as SimpleHebrewDate;
3144
} else if (typeof obj === 'number') {
@@ -71,33 +84,47 @@ function toSimpleHebrewDate(obj: Date | SimpleHebrewDate | number): SimpleHebrew
7184
* @param {Date | SimpleHebrewDate | number} date Gregorian or Hebrew date of death
7285
* @return {Date} anniversary occurring in `hyear`
7386
*/
74-
export function getYahrzeit(hyear: number, date: Date | SimpleHebrewDate | number): Date | undefined {
87+
export function getYahrzeit(
88+
hyear: number,
89+
date: Date | SimpleHebrewDate | number
90+
): Date | undefined {
7591
const hd = getYahrzeitHD(hyear, date);
7692
if (typeof hd === 'undefined') {
7793
return hd;
7894
}
7995
return greg.abs2greg(hebrew2abs(hd.yy, hd.mm, hd.dd));
8096
}
8197

82-
export function getYahrzeitHD(hyear: number, date: Date | SimpleHebrewDate | number): SimpleHebrewDate | undefined {
98+
export function getYahrzeitHD(
99+
hyear: number,
100+
date: Date | SimpleHebrewDate | number
101+
): SimpleHebrewDate | undefined {
83102
let hDeath = toSimpleHebrewDate(date);
84103
if (hyear <= hDeath.yy) {
85104
// Hebrew year ${hyear} occurs on or before original date in ${hDeath.yy}
86105
return undefined;
87106
}
88107

89-
if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hDeath.yy + 1)) {
108+
if (
109+
hDeath.mm === CHESHVAN &&
110+
hDeath.dd === 30 &&
111+
!longCheshvan(hDeath.yy + 1)
112+
) {
90113
// If it's Heshvan 30 it depends on the first anniversary;
91114
// if that was not Heshvan 30, use the day before Kislev 1.
92115
hDeath = abs2hebrew(hebrew2abs(hyear, KISLEV, 1) - 1);
93-
} else if (hDeath.mm == KISLEV && hDeath.dd == 30 && shortKislev(hDeath.yy + 1)) {
116+
} else if (
117+
hDeath.mm === KISLEV &&
118+
hDeath.dd === 30 &&
119+
shortKislev(hDeath.yy + 1)
120+
) {
94121
// If it's Kislev 30 it depends on the first anniversary;
95122
// if that was not Kislev 30, use the day before Teveth 1.
96123
hDeath = abs2hebrew(hebrew2abs(hyear, TEVET, 1) - 1);
97-
} else if (hDeath.mm == ADAR_II) {
124+
} else if (hDeath.mm === ADAR_II) {
98125
// If it's Adar II, use the same day in last month of year (Adar or Adar II).
99126
hDeath.mm = monthsInYear(hyear);
100-
} else if (hDeath.mm == ADAR_I && hDeath.dd == 30 && !isLeapYear(hyear)) {
127+
} else if (hDeath.mm === ADAR_I && hDeath.dd === 30 && !isLeapYear(hyear)) {
101128
// If it's the 30th in Adar I and year is not a leap year
102129
// (so Adar has only 29 days), use the last day in Shevat.
103130
hDeath.dd = 30;
@@ -106,10 +133,10 @@ export function getYahrzeitHD(hyear: number, date: Date | SimpleHebrewDate | num
106133
// In all other cases, use the normal anniversary of the date of death.
107134

108135
// advance day to rosh chodesh if needed
109-
if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hyear)) {
136+
if (hDeath.mm === CHESHVAN && hDeath.dd === 30 && !longCheshvan(hyear)) {
110137
hDeath.mm = KISLEV;
111138
hDeath.dd = 1;
112-
} else if (hDeath.mm == KISLEV && hDeath.dd == 30 && shortKislev(hyear)) {
139+
} else if (hDeath.mm === KISLEV && hDeath.dd === 30 && shortKislev(hyear)) {
113140
hDeath.mm = TEVET;
114141
hDeath.dd = 1;
115142
}
@@ -143,15 +170,21 @@ export function getYahrzeitHD(hyear: number, date: Date | SimpleHebrewDate | num
143170
* @param {Date | SimpleHebrewDate | number} date Gregorian or Hebrew date of event
144171
* @return {Date} anniversary occurring in `hyear`
145172
*/
146-
export function getBirthdayOrAnniversary(hyear: number, date: Date | SimpleHebrewDate): Date | undefined {
173+
export function getBirthdayOrAnniversary(
174+
hyear: number,
175+
date: Date | SimpleHebrewDate
176+
): Date | undefined {
147177
const hd = getBirthdayHD(hyear, date);
148178
if (typeof hd === 'undefined') {
149179
return hd;
150180
}
151181
return greg.abs2greg(hebrew2abs(hd.yy, hd.mm, hd.dd));
152182
}
153183

154-
export function getBirthdayHD(hyear: number, date: Date | SimpleHebrewDate): SimpleHebrewDate | undefined {
184+
export function getBirthdayHD(
185+
hyear: number,
186+
date: Date | SimpleHebrewDate
187+
): SimpleHebrewDate | undefined {
155188
const orig = toSimpleHebrewDate(date);
156189
const origYear = orig.yy;
157190
if (hyear === origYear) {
@@ -164,15 +197,20 @@ export function getBirthdayHD(hyear: number, date: Date | SimpleHebrewDate): Sim
164197
let month = orig.mm;
165198
let day = orig.dd;
166199

167-
if ((month == ADAR_I && !isOrigLeap) || (month == ADAR_II && isOrigLeap)) {
200+
if ((month === ADAR_I && !isOrigLeap) || (month === ADAR_II && isOrigLeap)) {
168201
month = monthsInYear(hyear);
169-
} else if (month == CHESHVAN && day == 30 && !longCheshvan(hyear)) {
202+
} else if (month === CHESHVAN && day === 30 && !longCheshvan(hyear)) {
170203
month = KISLEV;
171204
day = 1;
172-
} else if (month == KISLEV && day == 30 && shortKislev(hyear)) {
205+
} else if (month === KISLEV && day === 30 && shortKislev(hyear)) {
173206
month = TEVET;
174207
day = 1;
175-
} else if (month == ADAR_I && day == 30 && isOrigLeap && !isLeapYear(hyear)) {
208+
} else if (
209+
month === ADAR_I &&
210+
day === 30 &&
211+
isOrigLeap &&
212+
!isLeapYear(hyear)
213+
) {
176214
month = NISAN;
177215
day = 1;
178216
}

src/gematriya.ts

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
const GERESH: string = '׳';
2-
const GERSHAYIM: string = '״';
1+
const GERESH = '׳';
2+
const GERSHAYIM = '״';
33

44
const alefbet = {
5-
'א': 1,
6-
'ב': 2,
7-
'ג': 3,
8-
'ד': 4,
9-
'ה': 5,
10-
'ו': 6,
11-
'ז': 7,
12-
'ח': 8,
13-
'ט': 9,
14-
'י': 10,
15-
'כ': 20,
16-
'ל': 30,
17-
'מ': 40,
18-
'נ': 50,
19-
'ס': 60,
20-
'ע': 70,
21-
'פ': 80,
22-
'צ': 90,
23-
'ק': 100,
24-
'ר': 200,
25-
'ש': 300,
26-
'ת': 400,
5+
א: 1,
6+
ב: 2,
7+
ג: 3,
8+
ד: 4,
9+
ה: 5,
10+
ו: 6,
11+
ז: 7,
12+
ח: 8,
13+
ט: 9,
14+
י: 10,
15+
כ: 20,
16+
ל: 30,
17+
מ: 40,
18+
נ: 50,
19+
ס: 60,
20+
ע: 70,
21+
פ: 80,
22+
צ: 90,
23+
ק: 100,
24+
ר: 200,
25+
ש: 300,
26+
ת: 400,
2727
};
2828
const heb2num = new Map<string, number>();
2929
const num2heb = new Map<number, string>();
@@ -83,7 +83,7 @@ export function gematriya(num: number | string): string {
8383
str += GERESH;
8484
}
8585
const digits = num2digits(num1 % 1000);
86-
if (digits.length == 1) {
86+
if (digits.length === 1) {
8787
return str + num2heb.get(digits[0]) + GERESH;
8888
}
8989
for (let i = 0; i < digits.length; i++) {
@@ -106,7 +106,7 @@ export function gematriya(num: number | string): string {
106106
* @return {number}
107107
*/
108108
export function gematriyaStrToNum(str: string): number {
109-
let num: number = 0;
109+
let num = 0;
110110
const gereshIdx: number = str.indexOf(GERESH);
111111
if (gereshIdx !== -1 && gereshIdx !== str.length - 1) {
112112
const thousands = str.substring(0, gereshIdx);

src/greg.ts

+36-31
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
/* eslint-disable @typescript-eslint/no-namespace, no-inner-declarations */
12
/** @private */
23
const lengths: number[] = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
34
/** @private */
4-
const monthLengths: number[][] = [
5-
lengths,
6-
lengths.slice(),
7-
];
5+
const monthLengths: number[][] = [lengths, lengths.slice()];
86
monthLengths[1][2] = 29;
97

108
/**
@@ -21,6 +19,22 @@ function quotient(x: number, y: number): number {
2119
return Math.floor(x / y);
2220
}
2321

22+
/**
23+
* @private
24+
* @param abs - R.D. number of days
25+
*/
26+
function yearFromFixed(abs: number): number {
27+
const l0: number = abs - 1;
28+
const n400: number = quotient(l0, 146097);
29+
const d1: number = mod(l0, 146097);
30+
const n100: number = quotient(d1, 36524);
31+
const d2: number = mod(d1, 36524);
32+
const n4: number = quotient(d2, 1461);
33+
const d3: number = mod(d2, 1461);
34+
const n1: number = quotient(d3, 365);
35+
const year: number = 400 * n400 + 100 * n100 + 4 * n4 + n1;
36+
return n100 !== 4 && n1 !== 4 ? year + 1 : year;
37+
}
2438
/*
2539
const ABS_14SEP1752 = 639797;
2640
const ABS_2SEP1752 = 639785;
@@ -49,32 +63,16 @@ export namespace greg {
4963
// 1 based months
5064
return monthLengths[+isLeapYear(year)][month];
5165
}
52-
66+
5367
/**
5468
* Returns true if the object is a Javascript Date
5569
* @param {Object} obj
5670
* @return {boolean}
5771
*/
5872
export function isDate(obj: any): boolean {
73+
// eslint-disable-next-line no-prototype-builtins
5974
return typeof obj === 'object' && Date.prototype.isPrototypeOf(obj);
6075
}
61-
62-
/**
63-
* @private
64-
* @param abs - R.D. number of days
65-
*/
66-
function yearFromFixed(abs: number): number {
67-
const l0: number = abs - 1;
68-
const n400: number = quotient(l0, 146097);
69-
const d1: number = mod(l0, 146097);
70-
const n100: number = quotient(d1, 36524);
71-
const d2: number = mod(d1, 36524);
72-
const n4: number = quotient(d2, 1461);
73-
const d3: number = mod(d2, 1461);
74-
const n1: number = quotient(d3, 365);
75-
const year: number = 400 * n400 + 100 * n100 + 4 * n4 + n1;
76-
return n100 != 4 && n1 != 4 ? year + 1 : year;
77-
}
7876

7977
/**
8078
* @private
@@ -84,13 +82,15 @@ export namespace greg {
8482
*/
8583
function toFixed(year: number, month: number, day: number): number {
8684
const py: number = year - 1;
87-
return 365 * py +
85+
return (
86+
365 * py +
8887
quotient(py, 4) -
8988
quotient(py, 100) +
9089
quotient(py, 400) +
91-
quotient((367 * month - 362), 12) +
92-
(month <= 2 ? 0 : (isLeapYear(year) ? -1 : -2)) +
93-
day;
90+
quotient(367 * month - 362, 12) +
91+
(month <= 2 ? 0 : isLeapYear(year) ? -1 : -2) +
92+
day
93+
);
9494
}
9595

9696
/**
@@ -102,15 +102,19 @@ export namespace greg {
102102
if (!isDate(date)) {
103103
throw new TypeError(`Argument not a Date: ${date}`);
104104
}
105-
const abs = toFixed(date.getFullYear(), date.getMonth() + 1, date.getDate());
105+
const abs = toFixed(
106+
date.getFullYear(),
107+
date.getMonth() + 1,
108+
date.getDate()
109+
);
106110
/*
107111
if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
108112
throw new RangeError(`Invalid Date: ${date}`);
109113
}
110114
*/
111115
return abs;
112116
}
113-
117+
114118
/**
115119
* Converts from Rata Die (R.D. number) to Gregorian date.
116120
* See the footnote on page 384 of ``Calendrical Calculations, Part II:
@@ -132,13 +136,14 @@ export namespace greg {
132136
*/
133137
const year: number = yearFromFixed(abs);
134138
const priorDays: number = abs - toFixed(year, 1, 1);
135-
const correction: number = abs < toFixed(year, 3, 1) ? 0 : (isLeapYear(year) ? 1 : 2);
136-
const month: number = quotient((12 * (priorDays + correction) + 373), 367);
139+
const correction: number =
140+
abs < toFixed(year, 3, 1) ? 0 : isLeapYear(year) ? 1 : 2;
141+
const month: number = quotient(12 * (priorDays + correction) + 373, 367);
137142
const day: number = abs - toFixed(year, month, 1) + 1;
138143
const dt: Date = new Date(year, month - 1, day);
139144
if (year < 100 && year >= 0) {
140145
dt.setFullYear(year);
141146
}
142147
return dt;
143148
}
144-
};
149+
}

0 commit comments

Comments
 (0)