Skip to content

Commit

Permalink
Add some additional TypeScript readonly keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Nov 3, 2024
1 parent 7739f6d commit 95f5e89
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/YomKippurKatanEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {flags} from './event';
import {HolidayEvent} from './HolidayEvent';
import './locale'; // Adds Hebrew and Ashkenazic translations

export const ykk = 'Yom Kippur Katan';
const ykk = 'Yom Kippur Katan';

/** YKK is minor day of atonement on the day preceeding each Rosh Chodesh */
export class YomKippurKatanEvent extends HolidayEvent {
Expand Down
2 changes: 1 addition & 1 deletion src/hebcal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ export class HebrewCalendar {
isSaturday
);
if (isFriday && candlesEv && sedra) {
const parsha = sedra!.lookup(abs);
const parsha = sedra.lookup(abs);
const pe = new ParshaEvent(hd.next(), parsha.parsha, il, parsha.num);
candlesEv.memo = pe.render(options.locale);
}
Expand Down
18 changes: 9 additions & 9 deletions src/sedra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class Sedra {
private readonly year: number;
private readonly il: boolean;
private readonly firstSaturday: number;
private readonly theSedraArray: NumberOrString[];
private readonly theSedraArray: readonly NumberOrString[];
/**
* Caculates the Parashah HaShavua for an entire Hebrew year
* @param hyear - Hebrew year (e.g. 5749)
Expand Down Expand Up @@ -262,7 +262,7 @@ export class Sedra {
* Returns the underlying annual sedra schedule.
* Used by `@hebcal/triennial`
*/
getSedraArray(): NumberOrString[] {
getSedraArray(): readonly NumberOrString[] {
return this.theSedraArray;
}

Expand Down Expand Up @@ -324,7 +324,7 @@ export class Sedra {
* @readonly
* @type {string[]}
*/
export const parshiot: string[] = [
export const parshiot: readonly string[] = [
'Bereshit',
'Noach',
'Lech-Lecha',
Expand Down Expand Up @@ -378,7 +378,7 @@ export const parshiot: string[] = [
'Nitzavim',
'Vayeilech',
"Ha'azinu",
];
] as const;

// 0-based parsha IDs
const parsha2id = new Map<string, number>();
Expand Down Expand Up @@ -435,15 +435,15 @@ const SHAVUOT = 'Shavuot'; // 33
* @param start beginning number, inclusive
* @param stop ending number, inclusive
*/
function range(start: number, stop: number): number[] {
function range(start: number, stop: number): readonly number[] {
return Array.from({length: stop - start + 1}, (v, k) => k + start);
}

type NumberOrString = number | string;

const yearStartVayeilech: NumberOrString[] = [51, 52, CHMSUKOT];
const yearStartHaazinu: NumberOrString[] = [52, YK, CHMSUKOT];
const yearStartRH: NumberOrString[] = [RH, 52, SUKKOT, SHMINI];
const yearStartVayeilech: readonly NumberOrString[] = [51, 52, CHMSUKOT];
const yearStartHaazinu: readonly NumberOrString[] = [52, YK, CHMSUKOT];
const yearStartRH: readonly NumberOrString[] = [RH, 52, SUKKOT, SHMINI];
const r020 = range(0, 20);
const r027 = range(0, 27);
const r3340 = range(33, 40);
Expand All @@ -456,7 +456,7 @@ const r4350 = range(43, 50);
* @private
* @readonly
*/
const types: {[s: string]: NumberOrString[]} = {
const types: {[s: string]: readonly NumberOrString[]} = {
/* Hebrew year that starts on Monday, is `incomplete' (Heshvan and
* Kislev each have 29 days), and has Passover start on Tuesday. */
// e.g. 5753
Expand Down
16 changes: 11 additions & 5 deletions src/tachanun.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {HDate, months} from '@hebcal/hdate';
import {dateYomHaZikaron} from './modern';

function range(start: number, end: number): number[] {
function range(start: number, end: number): readonly number[] {
const arr = [];
for (let i = start; i <= end; i++) {
arr.push(i);
Expand Down Expand Up @@ -67,7 +67,13 @@ function tachanun0(
return ret;
}

function tachanunYear(year: number, il: boolean): any {
type TachanunYear = {
none: number[];
some: number[];
yesPrev: number[];
};

function tachanunYear(year: number, il: boolean): TachanunYear {
const leap = HDate.isLeapYear(year);
const monthsInYear = HDate.monthsInYear(year);
let av9dt = new HDate(9, months.AV, year);
Expand All @@ -78,7 +84,7 @@ function tachanunYear(year: number, il: boolean): any {
if (shushPurim.getDay() === 6) {
shushPurim = shushPurim.next();
}
const none: HDate[] = [
const none: readonly HDate[] = [
new HDate(2, months.TISHREI, year), // Rosh Hashana II
].concat(
// Rosh Chodesh - 1st of every month. Also includes RH day 1 (1 Tishrei)
Expand Down Expand Up @@ -108,7 +114,7 @@ function tachanunYear(year: number, il: boolean): any {
shushPurim,
leap ? new HDate(14, months.ADAR_I, year) : [] // Purim Katan
);
const some: HDate[] = [
const some: readonly HDate[] = [
new HDate(14, months.IYYAR, year), // Pesach Sheini
].concat(
// Until 14 Sivan
Expand All @@ -120,7 +126,7 @@ function tachanunYear(year: number, il: boolean): any {
// Yom Yerushalayim
year >= 5727 ? new HDate(28, months.IYYAR, year) : []
);
const yesPrev: HDate[] = [
const yesPrev: readonly HDate[] = [
new HDate(29, months.ELUL, year - 1), // Erev Rosh Hashanah
new HDate(9, months.TISHREI, year), // Erev Yom Kippur
new HDate(14, months.IYYAR, year), // Pesach Sheini
Expand Down

0 comments on commit 95f5e89

Please sign in to comment.