Skip to content

Commit

Permalink
Modernize some JavaScript idioms
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Oct 16, 2023
1 parent 9979eb1 commit d11a5d0
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 126 deletions.
366 changes: 267 additions & 99 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,23 @@
"verbose": true
},
"devDependencies": {
"@babel/core": "^7.23.0",
"@babel/preset-env": "^7.22.20",
"@babel/core": "^7.23.2",
"@babel/preset-env": "^7.23.2",
"@babel/register": "^7.22.15",
"@hebcal/solar-calc": "^1.1.2",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^25.0.4",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"ava": "^5.3.1",
"core-js": "^3.33.0",
"eslint": "^8.50.0",
"eslint": "^8.51.0",
"eslint-config-google": "^0.14.0",
"jsdoc": "^4.0.2",
"jsdoc-to-markdown": "^8.0.0",
"nyc": "^15.1.0",
"rollup": "^3.29.4",
"rollup": "^4.1.4",
"ttag-cli": "^1.10.6"
}
}
4 changes: 2 additions & 2 deletions src/HebrewDateEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class HebrewDateEvent extends Event {
* @return {string}
*/
render(locale) {
const locale1 = locale && locale.toLowerCase();
const locale1 = locale?.toLowerCase();
const locale0 = locale1 || Locale.getLocaleName();
const hd = this.getDate();
switch (locale0) {
Expand All @@ -50,7 +50,7 @@ export class HebrewDateEvent extends Event {
* @return {string}
*/
renderBrief(locale) {
const locale1 = locale && locale.toLowerCase();
const locale1 = locale?.toLowerCase();
const locale0 = locale1 || Locale.getLocaleName();
const hd = this.getDate();
if (hd.getMonth() === months.TISHREI && hd.getDate() === 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/candles.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export function makeFastStartEnd(ev, location) {
if (desc === 'Erev Tish\'a B\'Av') {
const sunset = zmanim.sunset();
ev.startEvent = makeTimedEvent(hd, sunset, 'Fast begins', ev, location);
} else if (desc.substring(0, 11) === 'Tish\'a B\'Av') {
} else if (desc.startsWith('Tish\'a B\'Av')) {
ev.endEvent = makeTimedEvent(hd, zmanim.tzeit(TZEIT_3MEDIUM_STARS), 'Fast ends', ev, location);
} else {
const dawn = zmanim.alotHaShachar();
Expand Down
3 changes: 1 addition & 2 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ export class Event {
*/
getCategories() {
const mask = this.getFlags();
for (let i = 0; i < flagToCategory.length; i++) {
const attrs = flagToCategory[i];
for (const attrs of flagToCategory) {
if (mask & attrs[0]) {
return attrs.slice(1);
}
Expand Down
8 changes: 4 additions & 4 deletions src/gematriya.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ export function gematriya(number) {
const thousands = Math.floor(num / 1000);
if (thousands > 0 && thousands !== 5) {
const tdigits = num2digits(thousands);
for (let i = 0; i < tdigits.length; i++) {
str += num2heb[tdigits[i]];
for (const tdig of tdigits) {
str += num2heb[tdig];
}
str += GERESH;
}
Expand Down Expand Up @@ -116,8 +116,8 @@ export function gematriyaStrToNum(str) {
num += gematriyaStrToNum(thousands) * 1000;
str = str.substring(gereshIdx);
}
for (let i = 0; i < str.length; i++) {
const n = heb2num[str[i]];
for (const ch of str) {
const n = heb2num[ch];
if (typeof n === 'number') {
num += n;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export class HDate {
if (ofStr) {
return ' ' + ofStr;
}
if ('ashkenazi' === locale.substring(0, 9)) {
if (locale.startsWith('ashkenazi')) {
return ' of';
}
return '';
Expand Down
2 changes: 1 addition & 1 deletion src/hebcal.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function checkCandleOptions(options) {
return;
}
const location = options.location;
if (typeof location === 'undefined' || !location instanceof Location) {
if (typeof location === 'undefined' || !(location instanceof Location)) {
throw new TypeError('options.candlelighting requires valid options.location');
}
if (typeof options.havdalahMins === 'number' && typeof options.havdalahDeg === 'number') {
Expand Down
2 changes: 1 addition & 1 deletion src/holidays.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ function eventDateDesc(ev) {

test('9av-observed', (t) => {
const events = HebrewCalendar.calendar({year: 2015, numYears: 10});
const av9 = events.filter((ev) => ev.getDesc().substring(0, 11) === 'Tish\'a B\'Av');
const av9 = events.filter((ev) => ev.getDesc().startsWith('Tish\'a B\'Av'));
const actual = av9.map(eventDateBasenameDesc);
const expected = [
{date: '2015-07-26', basename: 'Tish\'a B\'Av', desc: 'Tish\'a B\'Av (observed)'},
Expand Down
6 changes: 3 additions & 3 deletions src/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Locale {
* @return {string}
*/
static lookupTranslation(id, locale) {
const locale0 = locale && locale.toLowerCase();
const locale0 = locale?.toLowerCase();
const loc = (typeof locale == 'string' && locales[locale0]) || activeLocale;
const array = loc[id];
if (array && array.length && array[0].length) {
Expand Down Expand Up @@ -153,7 +153,7 @@ export class Locale {
* @return {string[]}
*/
static getLocaleNames() {
return Object.keys(locales).sort();
return Object.keys(locales).sort((a, b) => a.localeCompare(b));
}

/**
Expand All @@ -162,7 +162,7 @@ export class Locale {
* @return {string}
*/
static ordinal(n, locale) {
const locale1 = locale && locale.toLowerCase();
const locale1 = locale?.toLowerCase();
const locale0 = locale1 || activeName;
if (!locale0) {
return this.getEnOrdinal(n);
Expand Down
6 changes: 3 additions & 3 deletions src/tachanun.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ function tachanunYear(year, il) {
new HDate(14, months.IYYAR, year), // Pesach Sheini
);
return {
none: none.map((hd) => hd.abs()).sort(),
some: some.map((hd) => hd.abs()).sort(),
yesPrev: yesPrev.map((hd) => hd.abs()).sort(),
none: none.map((hd) => hd.abs()).sort((a, b) => a - b),
some: some.map((hd) => hd.abs()).sort((a, b) => a - b),
yesPrev: yesPrev.map((hd) => hd.abs()).sort((a, b) => a - b),
};
}

0 comments on commit d11a5d0

Please sign in to comment.