Skip to content

Commit

Permalink
Rename prettierrc.js to be .cjs
Browse files Browse the repository at this point in the history
This fixes an error caused by `type: "module"`, and makes Prettier work again.

And run Prettier on all files
  • Loading branch information
SLaks authored and mjradwin committed Oct 14, 2024
1 parent 0f0f42a commit a8db058
Show file tree
Hide file tree
Showing 16 changed files with 305 additions and 161 deletions.
3 changes: 3 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('gts/.prettierrc.json'),
};
3 changes: 0 additions & 3 deletions .prettierrc.js

This file was deleted.

6 changes: 4 additions & 2 deletions src/calculateHaftarahNumVerses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { calculateNumVerses } from './common';
import {calculateNumVerses} from './common';

export function calculateHaftarahNumVerses(haftara: string): number | undefined {
export function calculateHaftarahNumVerses(
haftara: string
): number | undefined {
const sections = haftara.split(/[;,]/);
let total = 0;
let prevBook = '';
Expand Down
16 changes: 11 additions & 5 deletions src/clone.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Aliyah } from './types';
import { calculateNumVerses } from './common';
import { JsonFestivalAliyah } from './internalTypes';
import {Aliyah} from './types';
import {calculateNumVerses} from './common';
import {JsonFestivalAliyah} from './internalTypes';

/**
* Makes a deep copy of the src object using JSON stringify and parse
Expand All @@ -9,7 +9,11 @@ export function clone(src: any): any {
return JSON.parse(JSON.stringify(src));
}

export type Haftarah = Aliyah | Aliyah[] | JsonFestivalAliyah | JsonFestivalAliyah[];
export type Haftarah =
| Aliyah
| Aliyah[]
| JsonFestivalAliyah
| JsonFestivalAliyah[];

export function cloneHaftara(haft: Haftarah): Aliyah | Aliyah[] {
if (!haft) {
Expand All @@ -28,5 +32,7 @@ export function cloneHaftara(haft: Haftarah): Aliyah | Aliyah[] {
* Returns the total number of verses in an array of Aliyah (or haftarah) objects
*/
export function sumVerses(aliyot: Haftarah): number {
return Array.isArray(aliyot) ? aliyot.reduce((prev, cur) => prev + cur.v!, 0) : aliyot.v!;
return Array.isArray(aliyot)
? aliyot.reduce((prev, cur) => prev + cur.v!, 0)
: aliyot.v!;
}
20 changes: 15 additions & 5 deletions src/common.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import numverses from './numverses.json';
import { Aliyah } from './types';
import {Aliyah} from './types';

/**
* Names of the books of the Torah. BOOK[1] === 'Genesis'
* @readonly
*/
export const BOOK = ['', 'Genesis', 'Exodus', 'Leviticus', 'Numbers', 'Deuteronomy'];
export const BOOK = [
'',
'Genesis',
'Exodus',
'Leviticus',
'Numbers',
'Deuteronomy',
];

/**
* Formats parsha as a string
Expand All @@ -14,7 +21,11 @@ export const BOOK = ['', 'Genesis', 'Exodus', 'Leviticus', 'Numbers', 'Deuterono
export function parshaToString(parsha: string | string[]): string {
if (typeof parsha === 'string') {
return parsha;
} else if (!Array.isArray(parsha) || parsha.length === 0 || parsha.length > 2) {
} else if (
!Array.isArray(parsha) ||
parsha.length === 0 ||
parsha.length > 2
) {
throw new TypeError(`Bad parsha argument: ${parsha}`);
}
let s = parsha[0];
Expand All @@ -25,7 +36,7 @@ export function parshaToString(parsha: string | string[]): string {
}

type NumVerses = {
[key: string]: number[],
[key: string]: number[];
};

/**
Expand Down Expand Up @@ -82,4 +93,3 @@ export function formatAliyahShort(aliyah: Aliyah, showBook: boolean): string {
const end = cv1[0] === cv2[0] ? cv2[1] : end0;
return `${prefix}${begin}-${end}`;
}

101 changes: 77 additions & 24 deletions src/csv.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { Event, HebrewCalendar, HolidayEvent, flags } from '@hebcal/core';
import { WriteStream } from 'node:fs';
import { formatAliyahWithBook } from './common';
import { getLeyningForHoliday, getLeyningForHolidayKey } from './getLeyningForHoliday';
import { getLeyningKeyForEvent } from './getLeyningKeyForEvent';
import { getLeyningForParshaHaShavua } from './leyning';
import { Leyning } from './types';
import {Event, HebrewCalendar, HolidayEvent, flags} from '@hebcal/core';
import {WriteStream} from 'node:fs';
import {formatAliyahWithBook} from './common';
import {
getLeyningForHoliday,
getLeyningForHolidayKey,
} from './getLeyningForHoliday';
import {getLeyningKeyForEvent} from './getLeyningKeyForEvent';
import {getLeyningForParshaHaShavua} from './leyning';
import {Leyning} from './types';

const fmt = new Intl.DateTimeFormat('en-US', {
year: 'numeric', month: 'short', day: '2-digit',
year: 'numeric',
month: 'short',
day: '2-digit',
});

function fmtDate(dt: Date): string {
Expand All @@ -20,7 +25,9 @@ export interface StringToBoolMap {
}

export function getParshaDates(events: Event[]): StringToBoolMap {
const parshaEvents = events.filter((ev) => ev.getFlags() === flags.PARSHA_HASHAVUA);
const parshaEvents = events.filter(
ev => ev.getFlags() === flags.PARSHA_HASHAVUA
);
const emptyMap: StringToBoolMap = {};
const parshaDates = parshaEvents.reduce((set, ev) => {
set[ev.getDate().toString()] = true;
Expand All @@ -29,18 +36,27 @@ export function getParshaDates(events: Event[]): StringToBoolMap {
return parshaDates;
}

export function writeFullKriyahCsv(stream: WriteStream, hyear: number, il: boolean) {
export function writeFullKriyahCsv(
stream: WriteStream,
hyear: number,
il: boolean
) {
const events0 = HebrewCalendar.calendar({
year: hyear,
isHebrewYear: true,
sedrot: true,
il: il,
});
const events = events0.filter((ev: Event) => ev.getDesc() !== 'Rosh Chodesh Tevet');
const events = events0.filter(
(ev: Event) => ev.getDesc() !== 'Rosh Chodesh Tevet'
);
const parshaDates = getParshaDates(events);
stream.write('"Date","Parashah","Aliyah","Reading","Verses"\r\n');
for (const ev of events) {
if (ev.getFlags() === flags.PARSHA_HASHAVUA || !parshaDates[ev.getDate().toString()]) {
if (
ev.getFlags() === flags.PARSHA_HASHAVUA ||
!parshaDates[ev.getDate().toString()]
) {
writeFullKriyahEvent(stream, ev, il);
}
}
Expand All @@ -57,33 +73,58 @@ function ignore(ev: Event): boolean {
return ev.getDate().getDay() === 6;
}

export function writeFullKriyahEvent(stream: WriteStream, ev: Event, il: boolean) {
export function writeFullKriyahEvent(
stream: WriteStream,
ev: Event,
il: boolean
) {
if (ignore(ev)) {
return;
}
const mask = ev.getFlags();
const isParsha = mask === flags.PARSHA_HASHAVUA;
const reading = isParsha ? getLeyningForParshaHaShavua(ev, il) : getLeyningForHoliday(ev, il);
const reading = isParsha
? getLeyningForParshaHaShavua(ev, il)
: getLeyningForHoliday(ev, il);
if (reading) {
writeCsvLines(stream, ev, reading, il, isParsha);
if (!isParsha) {
writeHolidayMincha(stream, ev as HolidayEvent, il);
const desc = ev.getDesc();
if ((il && desc === 'Sukkot VII (Hoshana Raba)') ||
(!il && desc === 'Shmini Atzeret')) {
const ev2 = new HolidayEvent(ev.getDate(), 'Erev Simchat Torah', flags.EREV);
if (
(il && desc === 'Sukkot VII (Hoshana Raba)') ||
(!il && desc === 'Shmini Atzeret')
) {
const ev2 = new HolidayEvent(
ev.getDate(),
'Erev Simchat Torah',
flags.EREV
);
writeFullKriyahEvent(stream, ev2, il);
}
}
}
}

export function writeHolidayMincha(stream: WriteStream, ev: HolidayEvent, il: boolean) {
export function writeHolidayMincha(
stream: WriteStream,
ev: HolidayEvent,
il: boolean
) {
const desc = ev.getDesc();
const minchaDesc1 = desc + ' (Mincha)';
const readingMincha1 = getLeyningForHolidayKey(minchaDesc1, ev.cholHaMoedDay, il);
const readingMincha = readingMincha1 ||
getLeyningForHolidayKey(getLeyningKeyForEvent(ev, il) + ' (Mincha)', ev.cholHaMoedDay, il);
const readingMincha1 = getLeyningForHolidayKey(
minchaDesc1,
ev.cholHaMoedDay,
il
);
const readingMincha =
readingMincha1 ||
getLeyningForHolidayKey(
getLeyningKeyForEvent(ev, il) + ' (Mincha)',
ev.cholHaMoedDay,
il
);
if (readingMincha) {
const minchaEv = new Event(ev.getDate(), minchaDesc1, flags.USER_EVENT);
writeCsvLines(stream, minchaEv, readingMincha, il, false);
Expand All @@ -93,8 +134,16 @@ export function writeHolidayMincha(stream: WriteStream, ev: HolidayEvent, il: bo
/**
* Formats reading for CSV
*/
export function writeCsvLines(stream: WriteStream, ev: Event, reading: Leyning, il: boolean, isParsha: boolean) {
const parsha = isParsha ? ev.basename() : getLeyningKeyForEvent(ev, il) || ev.render();
export function writeCsvLines(
stream: WriteStream,
ev: Event,
reading: Leyning,
il: boolean,
isParsha: boolean
) {
const parsha = isParsha
? ev.basename()
: getLeyningKeyForEvent(ev, il) || ev.render();
const date = fmtDate(ev.getDate().greg());
const lines = getFullKriyahLines(reading);
for (const s of lines) {
Expand Down Expand Up @@ -134,7 +183,11 @@ function getFullKriyahLines(reading: Leyning): any[] {
if (reading.reason?.sephardic) {
sephardic += ' | ' + reading.reason.sephardic;
}
lines.push(['Haftara for Sephardim', sephardic, reading.sephardicNumV || '']);
lines.push([
'Haftara for Sephardim',
sephardic,
reading.sephardicNumV || '',
]);
}
if (reading.triHaftara) {
const haftara = reading.triHaftara.replace(/,/g, ';');
Expand Down
10 changes: 6 additions & 4 deletions src/festival.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BOOK } from './common';
import { clone } from './clone';
import {BOOK} from './common';
import {clone} from './clone';
import festivals0 from './holiday-readings.json';
import { JsonFestivalLeyning } from './internalTypes';
import {JsonFestivalLeyning} from './internalTypes';

type Festivals = {
[key: string]: JsonFestivalLeyning;
Expand All @@ -19,7 +19,9 @@ export function hasFestival(holiday: string): boolean {
/**
* Returns the raw metadata for festival reading for `holiday`
*/
export function lookupFestival(holiday: string): JsonFestivalLeyning | undefined {
export function lookupFestival(
holiday: string
): JsonFestivalLeyning | undefined {
let src = festivals[holiday];
if (typeof src === 'undefined') {
return undefined;
Expand Down
48 changes: 30 additions & 18 deletions src/getLeyningForHoliday.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { Event, Locale, flags } from '@hebcal/core';
import { calculateNumVerses } from './common';
import { clone, cloneHaftara, sumVerses } from './clone';
import { lookupFestival } from './festival';
import { HOLIDAY_IGNORE_MASK, getLeyningKeyForEvent } from './getLeyningKeyForEvent';
import numverses from './numverses.json';
import { makeLeyningParts, makeSummaryFromParts } from './summary';
import {Event, Locale, flags} from '@hebcal/core';
import {calculateNumVerses} from './common';
import {clone, cloneHaftara, sumVerses} from './clone';
import {lookupFestival} from './festival';
import {
Aliyah,
AliyotMap,
Leyning,
} from './types';
HOLIDAY_IGNORE_MASK,
getLeyningKeyForEvent,
} from './getLeyningKeyForEvent';
import numverses from './numverses.json';
import {makeLeyningParts, makeSummaryFromParts} from './summary';
import {Aliyah, AliyotMap, Leyning} from './types';

type NumVerses = {
[key: string]: number[],
[key: string]: number[];
};

/**
Expand All @@ -21,7 +20,11 @@ type NumVerses = {
* of full kriyah aliyot, special Maftir, special Haftarah
* @param key name from `holiday-readings.json` to find
*/
export function getLeyningForHolidayKey(key?: string, cholHaMoedDay?: number, il?: boolean): Leyning | undefined {
export function getLeyningForHolidayKey(
key?: string,
cholHaMoedDay?: number,
il?: boolean
): Leyning | undefined {
if (typeof key !== 'string') {
return undefined;
}
Expand All @@ -30,7 +33,11 @@ export function getLeyningForHolidayKey(key?: string, cholHaMoedDay?: number, il
return undefined;
}
const israelOnly = (src as any).il;
if (typeof israelOnly === 'boolean' && typeof il === 'boolean' && il !== israelOnly) {
if (
typeof israelOnly === 'boolean' &&
typeof il === 'boolean' &&
il !== israelOnly
) {
return undefined;
}
const leyning: any = {
Expand All @@ -54,15 +61,17 @@ export function getLeyningForHolidayKey(key?: string, cholHaMoedDay?: number, il
leyning.summaryParts = parts;
}
}
Object.values(leyning.fullkriyah).map((aliyah) => calculateNumVerses(aliyah as Aliyah));
Object.values(leyning.fullkriyah).map(aliyah =>
calculateNumVerses(aliyah as Aliyah)
);
}
if (src.haft) {
const haft = leyning.haft = cloneHaftara(src.haft);
const haft = (leyning.haft = cloneHaftara(src.haft));
leyning.haftara = makeSummaryFromParts(haft);
leyning.haftaraNumV = sumVerses(haft);
}
if (src.seph) {
const seph = leyning.seph = cloneHaftara(src.seph);
const seph = (leyning.seph = cloneHaftara(src.seph));
leyning.sephardic = makeSummaryFromParts(seph);
leyning.sephardicNumV = sumVerses(seph);
}
Expand All @@ -89,7 +98,10 @@ export function getLeyningForHolidayKey(key?: string, cholHaMoedDay?: number, il
* @param [il] true if Israel holiday scheme
* @returns map of aliyot
*/
export function getLeyningForHoliday(ev: Event, il: boolean = false): Leyning | undefined {
export function getLeyningForHoliday(
ev: Event,
il = false
): Leyning | undefined {
if (typeof ev !== 'object' || typeof ev.getFlags !== 'function') {
throw new TypeError(`Bad event argument: ${JSON.stringify(ev)}`);
} else if (typeof (ev as any).eventTime !== 'undefined') {
Expand Down
Loading

0 comments on commit a8db058

Please sign in to comment.