@hebcal/rest-api 5.1.4 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/rest-api v5.1.4 */
1
+ /*! @hebcal/rest-api v5.2.0 */
2
2
  'use strict';
3
3
 
4
4
  var core = require('@hebcal/core');
@@ -708,7 +708,8 @@ var holidayDescription0 = {
708
708
  * makeAnchor('Rosh Chodesh Adar II') // 'rosh-chodesh-adar-ii'
709
709
  */
710
710
  function makeAnchor(s) {
711
- return s.toLowerCase()
711
+ return s
712
+ .toLowerCase()
712
713
  .replace(/'/g, '')
713
714
  .replace(/[^\w]/g, '-')
714
715
  .replace(/-+/g, '-')
@@ -734,7 +735,7 @@ const doubled = new Set();
734
735
  for (const name of doubledParshiyot) {
735
736
  const anchor = makeAnchor(name);
736
737
  doubled.add(anchor);
737
- const [p1, p2] = anchor.split('-');
738
+ const [p1] = anchor.split('-');
738
739
  const id = parsha2id.get(p1);
739
740
  parsha2id.set(anchor, id);
740
741
  }
@@ -777,14 +778,25 @@ function shortenSedrotUrl(u) {
777
778
  }
778
779
  }
779
780
 
780
- const LOC_FIELDS = ['elevation', 'admin1', 'asciiname', 'geo', 'zip', 'state', 'stateName', 'geonameid'];
781
+ const LOC_FIELDS = [
782
+ 'elevation',
783
+ 'admin1',
784
+ 'asciiname',
785
+ 'geo',
786
+ 'zip',
787
+ 'state',
788
+ 'stateName',
789
+ 'geonameid',
790
+ ];
781
791
  const holidayDescription = holidayDescription0;
782
792
  const countryNames = countryNames0;
783
793
  /**
784
794
  * Converts a @hebcal/core `Location` to a plain JS object.
785
795
  */
786
796
  function locationToPlainObj(location) {
787
- if (typeof location === 'object' && location !== null && typeof location.getLatitude === 'function') {
797
+ if (typeof location === 'object' &&
798
+ location !== null &&
799
+ typeof location.getLatitude === 'function') {
788
800
  const cc = location.getCountryCode();
789
801
  const o = {
790
802
  title: location.getName(),
@@ -818,7 +830,8 @@ function getDownloadFilename(options) {
818
830
  fileName += '_' + options.month;
819
831
  }
820
832
  }
821
- else if (typeof options.start === 'object' && typeof options.end === 'object') {
833
+ else if (typeof options.start === 'object' &&
834
+ typeof options.end === 'object') {
822
835
  const start = new core.HDate(options.start);
823
836
  const end = new core.HDate(options.end);
824
837
  const y1 = start.greg().getFullYear();
@@ -859,7 +872,9 @@ function getEventCategories(ev) {
859
872
  * Renders the event title in default locale, but strips off time
860
873
  */
861
874
  function renderTitleWithoutTime(ev) {
862
- return typeof ev.eventTime === 'undefined' ? ev.render() : ev.renderBrief();
875
+ return typeof ev.eventTime === 'undefined'
876
+ ? ev.render()
877
+ : ev.renderBrief();
863
878
  }
864
879
  function shortLocationName(options) {
865
880
  const loc = options.location;
@@ -892,19 +907,20 @@ function getCalendarTitle(events, options) {
892
907
  else {
893
908
  title += ' Diaspora';
894
909
  }
895
- if (options.subscribe == '1') {
910
+ const sub = options.subscribe;
911
+ if (sub === '1' || sub === 1 || sub === true) {
896
912
  return title;
897
913
  }
898
- if (options.year && (options.isHebrewYear || events.length == 0)) {
914
+ if (options.year && (options.isHebrewYear || events.length === 0)) {
899
915
  title += ' ' + options.year;
900
916
  }
901
917
  else if (events.length) {
902
918
  const start = events[0].getDate().greg();
903
919
  const end = events[events.length - 1].getDate().greg();
904
- if (start.getFullYear() != end.getFullYear()) {
920
+ if (start.getFullYear() !== end.getFullYear()) {
905
921
  title += ' ' + start.getFullYear() + '-' + end.getFullYear();
906
922
  }
907
- else if (start.getMonth() == end.getMonth()) {
923
+ else if (start.getMonth() === end.getMonth()) {
908
924
  const monthFormat = new Intl.DateTimeFormat('en-US', { month: 'long' });
909
925
  const startMonth = monthFormat.format(start);
910
926
  title += ' ' + startMonth + ' ' + start.getFullYear();
@@ -919,34 +935,42 @@ function getCalendarTitle(events, options) {
919
935
  * Returns an English language description of the holiday
920
936
  */
921
937
  function getHolidayDescription(ev, firstSentence = false) {
922
- const str0 = ev.getFlags() & core.flags.SHABBAT_MEVARCHIM ?
923
- holidayDescription['Shabbat Mevarchim Chodesh'] :
924
- holidayDescription[ev.getDesc()] || holidayDescription[ev.basename()] || '';
938
+ const str0 = ev.getFlags() & core.flags.SHABBAT_MEVARCHIM
939
+ ? holidayDescription['Shabbat Mevarchim Chodesh']
940
+ : holidayDescription[ev.getDesc()] ||
941
+ holidayDescription[ev.basename()] ||
942
+ '';
925
943
  const str = str0.normalize();
926
944
  if (firstSentence && str) {
927
945
  const dot = str.indexOf('.');
928
- if (dot != -1) {
946
+ if (dot !== -1) {
929
947
  return str.substring(0, dot);
930
948
  }
931
949
  }
932
950
  return str;
933
951
  }
934
- const HOLIDAY_IGNORE_MASK = core.flags.DAF_YOMI | core.flags.OMER_COUNT |
935
- core.flags.SHABBAT_MEVARCHIM | core.flags.MOLAD | core.flags.USER_EVENT |
936
- core.flags.NACH_YOMI | core.flags.DAILY_LEARNING |
937
- core.flags.HEBREW_DATE | core.flags.YERUSHALMI_YOMI;
952
+ const HOLIDAY_IGNORE_MASK = core.flags.DAF_YOMI |
953
+ core.flags.OMER_COUNT |
954
+ core.flags.SHABBAT_MEVARCHIM |
955
+ core.flags.MOLAD |
956
+ core.flags.USER_EVENT |
957
+ core.flags.NACH_YOMI |
958
+ core.flags.DAILY_LEARNING |
959
+ core.flags.HEBREW_DATE |
960
+ core.flags.YERUSHALMI_YOMI;
938
961
  /**
939
962
  * Makes mulit-line text that summarizes Torah & Haftarah
940
963
  */
941
964
  function makeTorahMemoText(ev, il) {
942
965
  var _a;
943
966
  const mask = ev.getFlags();
944
- if ((mask & HOLIDAY_IGNORE_MASK) || (typeof ev.eventTime !== 'undefined')) {
967
+ if (mask & HOLIDAY_IGNORE_MASK ||
968
+ typeof ev.eventTime !== 'undefined') {
945
969
  return '';
946
970
  }
947
- const reading = (mask & core.flags.PARSHA_HASHAVUA) ?
948
- leyning.getLeyningForParshaHaShavua(ev, il) :
949
- leyning.getLeyningForHoliday(ev, il);
971
+ const reading = mask & core.flags.PARSHA_HASHAVUA
972
+ ? leyning.getLeyningForParshaHaShavua(ev, il)
973
+ : leyning.getLeyningForHoliday(ev, il);
950
974
  let memo = '';
951
975
  if (reading && (reading.summary || reading.haftara)) {
952
976
  if (reading.summary) {
@@ -1006,10 +1030,12 @@ function appendIsraelAndTracking(url, il, utmSource, utmMedium, utmCampaign) {
1006
1030
  else if (isSedrot) {
1007
1031
  shortenSedrotUrl(u);
1008
1032
  }
1009
- else { // isOmer
1033
+ else {
1034
+ // isOmer
1010
1035
  u.pathname = '/o/' + path.substring(6);
1011
1036
  }
1012
- if (!utmCampaign || !(utmCampaign.startsWith('ical-') || utmCampaign.startsWith('pdf-'))) {
1037
+ if (!utmCampaign ||
1038
+ !(utmCampaign.startsWith('ical-') || utmCampaign.startsWith('pdf-'))) {
1013
1039
  if (utmSource) {
1014
1040
  u.searchParams.set('us', utmSource);
1015
1041
  }
@@ -1042,12 +1068,14 @@ function shouldRenderBrief(ev) {
1042
1068
  const mask = ev.getFlags();
1043
1069
  if (mask & core.flags.HEBREW_DATE) {
1044
1070
  const hd = ev.getDate();
1045
- return (hd.getDate() === 1) ? false : true;
1071
+ return hd.getDate() === 1 ? false : true;
1046
1072
  }
1047
- else if (mask & (core.flags.DAILY_LEARNING | core.flags.DAF_YOMI | core.flags.YERUSHALMI_YOMI)) {
1073
+ else if (mask &
1074
+ (core.flags.DAILY_LEARNING | core.flags.DAF_YOMI | core.flags.YERUSHALMI_YOMI)) {
1048
1075
  return true;
1049
1076
  }
1050
- else if (mask & core.flags.MINOR_FAST && ev.getDesc().substring(0, 16) === 'Yom Kippur Katan') {
1077
+ else if (mask & core.flags.MINOR_FAST &&
1078
+ ev.getDesc().substring(0, 16) === 'Yom Kippur Katan') {
1051
1079
  return true;
1052
1080
  }
1053
1081
  else if (mask & core.flags.SHABBAT_MEVARCHIM) {
@@ -1083,15 +1111,20 @@ function eventToCsv(ev, options) {
1083
1111
  const mday = d.getDate();
1084
1112
  const mon = d.getMonth() + 1;
1085
1113
  const year = String(d.getFullYear()).padStart(4, '0');
1086
- const date = options.euro ? `"${mday}/${mon}/${year}"` : `"${mon}/${mday}/${year}"`;
1114
+ const date = options.euro
1115
+ ? `"${mday}/${mon}/${year}"`
1116
+ : `"${mon}/${mday}/${year}"`;
1087
1117
  let startTime = '';
1088
1118
  let endTime = '';
1089
1119
  let endDate = '';
1090
1120
  let allDay = '"true"';
1091
- const timed = Boolean(ev.eventTime);
1092
- let subj = shouldRenderBrief(ev) ? ev.renderBrief(options.locale) : ev.render(options.locale);
1121
+ const timedEv = ev;
1122
+ const timed = Boolean(timedEv.eventTime);
1123
+ let subj = shouldRenderBrief(ev)
1124
+ ? ev.renderBrief(options.locale)
1125
+ : ev.render(options.locale);
1093
1126
  if (timed) {
1094
- const timeStr = core.HebrewCalendar.reformatTimeStr(ev.eventTimeStr, ' PM', options);
1127
+ const timeStr = core.HebrewCalendar.reformatTimeStr(timedEv.eventTimeStr, ' PM', options);
1095
1128
  endTime = startTime = `"${timeStr}"`;
1096
1129
  endDate = date;
1097
1130
  allDay = '"false"';
@@ -1110,7 +1143,7 @@ function eventToCsv(ev, options) {
1110
1143
  loc = category;
1111
1144
  }
1112
1145
  }
1113
- subj = subj.replace(/,/g, '').replace(/"/g, '\'\'');
1146
+ subj = subj.replace(/,/g, '').replace(/"/g, "''");
1114
1147
  if (options.appendHebrewToSubject) {
1115
1148
  const hebrew = ev.renderBrief('he');
1116
1149
  if (hebrew) {
@@ -1118,15 +1151,19 @@ function eventToCsv(ev, options) {
1118
1151
  }
1119
1152
  }
1120
1153
  let memo0 = ev.memo || getHolidayDescription(ev, true);
1121
- if (!memo0 && typeof ev.linkedEvent !== 'undefined') {
1122
- memo0 = ev.linkedEvent.render(options.locale);
1123
- }
1124
- const memo = memo0.replace(/,/g, ';').replace(/"/g, '\'\'').replace(/\n/g, ' / ');
1125
- const showTimeAs = (timed || (mask & core.flags.CHAG)) ? 4 : 3;
1154
+ if (!memo0 && typeof timedEv.linkedEvent !== 'undefined') {
1155
+ memo0 = timedEv.linkedEvent.render(options.locale);
1156
+ }
1157
+ const memo = memo0
1158
+ .replace(/,/g, ';')
1159
+ .replace(/"/g, "''")
1160
+ .replace(/\n/g, ' / ');
1161
+ const showTimeAs = timed || mask & core.flags.CHAG ? 4 : 3;
1126
1162
  return `"${subj}",${date},${startTime},${endDate},${endTime},${allDay},"${memo}","${showTimeAs}","${loc}"`;
1127
1163
  }
1128
1164
  function eventsToCsv(events, options) {
1129
- return [csvHeader].concat(events.map((ev) => eventToCsv(ev, options))).join('\r\n') + '\r\n';
1165
+ return ([csvHeader].concat(events.map(ev => eventToCsv(ev, options))).join('\r\n') +
1166
+ '\r\n');
1130
1167
  }
1131
1168
 
1132
1169
  function eventIsoDate(ev) {
@@ -1139,6 +1176,7 @@ function eventsToClassicApi(events, options, leyning = true) {
1139
1176
  const result = {
1140
1177
  title: getCalendarTitle(events, options),
1141
1178
  date: new Date().toISOString(),
1179
+ version: core.version,
1142
1180
  };
1143
1181
  result.location = locationToPlainObj(options.location);
1144
1182
  if (events.length) {
@@ -1147,28 +1185,31 @@ function eventsToClassicApi(events, options, leyning = true) {
1147
1185
  end: eventIsoDate(events[events.length - 1]),
1148
1186
  };
1149
1187
  }
1150
- result.items = events.map((ev) => eventToClassicApiObject(ev, options, leyning));
1188
+ result.items = events.map(ev => eventToClassicApiObject(ev, options, leyning));
1151
1189
  return result;
1152
1190
  }
1153
1191
  /**
1154
1192
  * Converts a Hebcal event to a classic Hebcal.com JSON API object
1155
1193
  */
1156
1194
  function eventToClassicApiObject(ev, options, leyning$1 = true) {
1157
- const eventTime = ev.eventTime;
1195
+ const timedEv = ev;
1196
+ const eventTime = timedEv.eventTime;
1158
1197
  const timed = Boolean(eventTime);
1159
1198
  const hd = ev.getDate();
1160
1199
  const dt = hd.greg();
1161
1200
  const tzid = typeof options.location === 'object' ? options.location.getTzid() : 'UTC';
1162
- const date = timed ?
1163
- core.Zmanim.formatISOWithTimeZone(tzid, eventTime) :
1164
- isoDateString(dt);
1201
+ const date = timed
1202
+ ? core.Zmanim.formatISOWithTimeZone(tzid, eventTime)
1203
+ : isoDateString(dt);
1165
1204
  const categories = getEventCategories(ev);
1166
1205
  const mask = ev.getFlags();
1167
- let title = shouldRenderBrief(ev) ? ev.renderBrief(options.locale) : ev.render(options.locale);
1206
+ let title = shouldRenderBrief(ev)
1207
+ ? ev.renderBrief(options.locale)
1208
+ : ev.render(options.locale);
1168
1209
  const desc = ev.getDesc();
1169
1210
  const candles = desc === 'Havdalah' || desc === 'Candle lighting';
1170
1211
  if (candles) {
1171
- const time = core.HebrewCalendar.reformatTimeStr(ev.eventTimeStr, 'pm', options);
1212
+ const time = core.HebrewCalendar.reformatTimeStr(timedEv.eventTimeStr, 'pm', options);
1172
1213
  title += ': ' + time;
1173
1214
  }
1174
1215
  const result = {
@@ -1182,10 +1223,10 @@ function eventToClassicApiObject(ev, options, leyning$1 = true) {
1182
1223
  if (categories.length > 1) {
1183
1224
  result.subcat = categories[1];
1184
1225
  }
1185
- if (categories[0] === 'holiday' && (mask & core.flags.CHAG)) {
1226
+ if (categories[0] === 'holiday' && mask & core.flags.CHAG) {
1186
1227
  result.yomtov = true;
1187
1228
  }
1188
- if (title != desc) {
1229
+ if (title !== desc) {
1189
1230
  result.title_orig = desc;
1190
1231
  }
1191
1232
  const hebrew = ev.renderBrief('he');
@@ -1195,10 +1236,10 @@ function eventToClassicApiObject(ev, options, leyning$1 = true) {
1195
1236
  if (!candles) {
1196
1237
  if (leyning$1) {
1197
1238
  const il = options.il;
1198
- const isParsha = (mask === core.flags.PARSHA_HASHAVUA);
1199
- const reading = isParsha ?
1200
- leyning.getLeyningForParshaHaShavua(ev, il) :
1201
- leyning.getLeyningForHoliday(ev, il);
1239
+ const isParsha = mask === core.flags.PARSHA_HASHAVUA;
1240
+ const reading = isParsha
1241
+ ? leyning.getLeyningForParshaHaShavua(ev, il)
1242
+ : leyning.getLeyningForHoliday(ev, il);
1202
1243
  if (reading) {
1203
1244
  result.leyning = formatLeyningResult(reading);
1204
1245
  const hyear = hd.getFullYear();
@@ -1246,7 +1287,7 @@ function eventToClassicApiObject(ev, options, leyning$1 = true) {
1246
1287
  };
1247
1288
  delete result.hebrew;
1248
1289
  }
1249
- if ((options.heDateParts && !timed) || (mask & core.flags.HEBREW_DATE)) {
1290
+ if ((options.heDateParts && !timed) || mask & core.flags.HEBREW_DATE) {
1250
1291
  const yy = hd.getFullYear();
1251
1292
  const mm = hd.getMonthName();
1252
1293
  const dd = hd.getDate();
@@ -1260,8 +1301,8 @@ function eventToClassicApiObject(ev, options, leyning$1 = true) {
1260
1301
  if (typeof memo === 'string' && memo.length !== 0) {
1261
1302
  result.memo = memo.normalize();
1262
1303
  }
1263
- else if (typeof ev.linkedEvent !== 'undefined') {
1264
- result.memo = ev.linkedEvent.render(options.locale);
1304
+ else if (typeof timedEv.linkedEvent !== 'undefined') {
1305
+ result.memo = timedEv.linkedEvent.render(options.locale);
1265
1306
  }
1266
1307
  if (options.includeEvent) {
1267
1308
  result.ev = ev;
@@ -1271,7 +1312,7 @@ function eventToClassicApiObject(ev, options, leyning$1 = true) {
1271
1312
  function formatAliyot(result, aliyot) {
1272
1313
  for (const [num, aliyah] of Object.entries(aliyot)) {
1273
1314
  if (typeof aliyah !== 'undefined') {
1274
- const k = num == 'M' ? 'maftir' : num;
1315
+ const k = num === 'M' ? 'maftir' : num;
1275
1316
  result[k] = leyning.formatAliyahWithBook(aliyah);
1276
1317
  }
1277
1318
  }
@@ -1280,7 +1321,7 @@ function formatAliyot(result, aliyot) {
1280
1321
  function formatReasons(result, reason) {
1281
1322
  for (const num of ['7', '8', 'M']) {
1282
1323
  if (reason[num]) {
1283
- const k = num == 'M' ? 'maftir' : num;
1324
+ const k = num === 'M' ? 'maftir' : num;
1284
1325
  result[k] += ' | ' + reason[num];
1285
1326
  }
1286
1327
  }
@@ -1333,12 +1374,12 @@ function getLinkAndGuid(ev, il, tzid, mainUrl, utmSource, utmMedium) {
1333
1374
  return [link, guid];
1334
1375
  }
1335
1376
  const localeToLg = {
1336
- 's': 'en',
1337
- 'a': 'en',
1377
+ s: 'en',
1378
+ a: 'en',
1338
1379
  'he-x-NoNikud': 'he',
1339
- 'h': 'he',
1340
- 'ah': 'en',
1341
- 'sh': 'en',
1380
+ h: 'he',
1381
+ ah: 'en',
1382
+ sh: 'en',
1342
1383
  };
1343
1384
  function eventsToRss2(events, options) {
1344
1385
  options.dayFormat = new Intl.DateTimeFormat('en-US', {
@@ -1351,9 +1392,9 @@ function eventsToRss2(events, options) {
1351
1392
  if (!options.mainUrl || !options.selfUrl) {
1352
1393
  throw new TypeError('mainUrl cannot be empty or blank');
1353
1394
  }
1354
- const buildDate = options.buildDate = options.buildDate || new Date();
1395
+ const buildDate = (options.buildDate = options.buildDate || new Date());
1355
1396
  const thisYear = buildDate.getFullYear();
1356
- const lastBuildDate = options.lastBuildDate = buildDate.toUTCString();
1397
+ const lastBuildDate = (options.lastBuildDate = buildDate.toUTCString());
1357
1398
  const title = options.title || getCalendarTitle(events, options);
1358
1399
  const description = options.description || title;
1359
1400
  const utmSource = options.utmSource || 'shabbat1c';
@@ -1408,7 +1449,7 @@ function eventToRssItem2(ev, options) {
1408
1449
  let memo;
1409
1450
  if (candles) {
1410
1451
  const colon = subj.indexOf(': ');
1411
- if (colon != -1) {
1452
+ if (colon !== -1) {
1412
1453
  const options = { location, il, locale: core.Locale.getLocaleName() };
1413
1454
  const time = core.HebrewCalendar.reformatTimeStr(ev.eventTimeStr, 'pm', options);
1414
1455
  subj = subj.substring(0, colon) + ': ' + time;
@@ -1418,11 +1459,11 @@ function eventToRssItem2(ev, options) {
1418
1459
  memo = makeMemo(ev, il);
1419
1460
  }
1420
1461
  const dayFormat = options.dayFormat;
1421
- const description0 = memo || dayFormat.format(evDate);
1422
- const description = description0.indexOf('<') === -1 ? description0 : `<![CDATA[${description0}]]>`;
1423
- const geoTags = (cat0 == 'candles') ?
1424
- `<geo:lat>${location.getLatitude()}</geo:lat>\n<geo:long>${location.getLongitude()}</geo:long>\n` :
1425
- '';
1462
+ const tmp = memo || dayFormat.format(evDate);
1463
+ const description = tmp.indexOf('<') === -1 ? tmp : `<![CDATA[${tmp}]]>`;
1464
+ const geoTags = cat0 === 'candles'
1465
+ ? `<geo:lat>${location.getLatitude()}</geo:lat>\n<geo:long>${location.getLongitude()}</geo:long>\n`
1466
+ : '';
1426
1467
  return `<item>
1427
1468
  <title>${subj}</title>
1428
1469
  <link>${link}</link>
@@ -1440,15 +1481,16 @@ ${geoTags}</item>
1440
1481
  function eventToFullCalendar(ev, tzid, il) {
1441
1482
  const classes = getEventCategories(ev);
1442
1483
  const mask = ev.getFlags();
1443
- if (classes[0] == 'holiday' && mask & core.flags.CHAG) {
1484
+ if (classes[0] === 'holiday' && mask & core.flags.CHAG) {
1444
1485
  classes.push('yomtov');
1445
1486
  }
1446
- const eventTime = ev.eventTime;
1487
+ const timedEv = ev;
1488
+ const eventTime = timedEv.eventTime;
1447
1489
  const timed = Boolean(eventTime);
1448
1490
  const title = shouldRenderBrief(ev) ? ev.renderBrief() : ev.render();
1449
- const start = timed ?
1450
- core.Zmanim.formatISOWithTimeZone(tzid, eventTime) :
1451
- isoDateString(ev.getDate().greg());
1491
+ const start = timed
1492
+ ? core.Zmanim.formatISOWithTimeZone(tzid, eventTime)
1493
+ : isoDateString(ev.getDate().greg());
1452
1494
  const result = {
1453
1495
  title,
1454
1496
  start,
@@ -1470,8 +1512,8 @@ function eventToFullCalendar(ev, tzid, il) {
1470
1512
  if (memo) {
1471
1513
  result.description = memo;
1472
1514
  }
1473
- else if (typeof ev.linkedEvent !== 'undefined') {
1474
- result.description = ev.linkedEvent.render();
1515
+ else if (typeof timedEv.linkedEvent !== 'undefined') {
1516
+ result.description = timedEv.linkedEvent.render();
1475
1517
  }
1476
1518
  }
1477
1519
  return result;