@hebcal/leyning 8.0.1 → 8.1.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/README.md CHANGED
@@ -108,6 +108,9 @@ of full kriyah aliyot, special Maftir, special Haftarah</p>
108
108
  <dd><p>Looks up leyning for a given holiday. Returns some
109
109
  of full kriyah aliyot, special Maftir, special Haftarah</p>
110
110
  </dd>
111
+ <dt><a href="#makeLeyningNames">makeLeyningNames(parsha)</a> ⇒ <code><a href="#LeyningNames">LeyningNames</a></code></dt>
112
+ <dd><p>Transliterated English and Hebrew names of this parsha</p>
113
+ </dd>
111
114
  <dt><a href="#getWeekdayReading">getWeekdayReading(parsha)</a> ⇒ <code>Object.&lt;string, Aliyah&gt;</code></dt>
112
115
  <dd><p>Looks up Monday/Thursday aliyot for a regular parsha</p>
113
116
  </dd>
@@ -357,6 +360,17 @@ of full kriyah aliyot, special Maftir, special Haftarah
357
360
  | ev | <code>Event</code> | | the Hebcal event associated with this leyning |
358
361
  | [il] | <code>boolean</code> | <code>false</code> | true if Israel holiday scheme |
359
362
 
363
+ <a name="makeLeyningNames"></a>
364
+
365
+ ## makeLeyningNames(parsha) ⇒ [<code>LeyningNames</code>](#LeyningNames)
366
+ Transliterated English and Hebrew names of this parsha
367
+
368
+ **Kind**: global function
369
+
370
+ | Param | Type | Description |
371
+ | --- | --- | --- |
372
+ | parsha | <code>string</code> \| <code>Array.&lt;string&gt;</code> | untranslated name like 'Pinchas' or ['Pinchas'] or ['Matot','Masei'] |
373
+
360
374
  <a name="getWeekdayReading"></a>
361
375
 
362
376
  ## getWeekdayReading(parsha) ⇒ <code>Object.&lt;string, Aliyah&gt;</code>
@@ -501,7 +515,7 @@ Leyning for a parsha hashavua or holiday
501
515
  | --- | --- | --- |
502
516
  | name | [<code>LeyningNames</code>](#LeyningNames) | |
503
517
  | [parsha] | <code>Array.&lt;string&gt;</code> | An array of either 1 (regular) or 2 (doubled parsha). `undefined` for holiday readings |
504
- | [parshaNum] | <code>number</code> | 1 for Bereshit, 2 for Noach, etc. `undefined` for holiday readings |
518
+ | [parshaNum] | <code>number</code> \| <code>Array.&lt;number&gt;</code> | 1 for Bereshit, 2 for Noach, etc. `undefined` for holiday readings |
505
519
  | summary | <code>string</code> | Such as `Genesis 1:1 - 6:8` |
506
520
  | haft | [<code>Aliyah</code>](#Aliyah) \| [<code>Array.&lt;Aliyah&gt;</code>](#Aliyah) | Haftarah object(s) |
507
521
  | haftara | <code>string</code> | Haftarah, such as `Isaiah 42:5 – 43:11` |
package/dist/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/leyning v8.0.1 */
1
+ /*! @hebcal/leyning v8.1.0 */
2
2
  var hebcal__leyning = (function (exports, core) {
3
3
  'use strict';
4
4
 
@@ -262,11 +262,11 @@ function lookupFestival(holiday) {
262
262
  }
263
263
  const result = src.fullkriyah ? clone(src) : src;
264
264
  if (result.fullkriyah) {
265
- Object.values(result.fullkriyah).forEach(aliyah => {
265
+ for (const aliyah of Object.values(result.fullkriyah)) {
266
266
  if (typeof aliyah.k === 'number') {
267
267
  aliyah.k = BOOK[aliyah.k];
268
268
  }
269
- });
269
+ }
270
270
  }
271
271
  if (src.note) {
272
272
  result.note = src.note;
@@ -483,14 +483,16 @@ function specialReadings2(parsha, hd, il, aliyot) {
483
483
  if (special.fullkriyah) {
484
484
  const aliyotMap = clone(aliyot);
485
485
  mergeAliyotWithSpecial(aliyotMap, special.fullkriyah);
486
- Object.keys(special.fullkriyah).map(k => reason[k] = key);
486
+ for (const num of Object.keys(special.fullkriyah)) {
487
+ reason[num] = key;
488
+ }
487
489
  aliyot = aliyotMap;
488
490
  }
489
491
  }
490
492
  const parshaName = parshaToString(parsha);
491
493
  const events0 = core.HebrewCalendar.getHolidaysOnDate(hd, il) || [];
492
494
  const events = events0.filter(ev => !(ev.getFlags() & core.flags.ROSH_CHODESH));
493
- events.forEach(ev => {
495
+ for (const ev of events) {
494
496
  if (ev.getDesc() === 'Shabbat Shuva') {
495
497
  handleSpecial(`Shabbat Shuva (with ${parshaName})`);
496
498
  } else {
@@ -499,7 +501,7 @@ function specialReadings2(parsha, hd, il, aliyot) {
499
501
  handleSpecial(key);
500
502
  }
501
503
  }
502
- });
504
+ }
503
505
  if (!haft) {
504
506
  const day = hd.getDate();
505
507
  if (parshaName === 'Pinchas' && day > 17) {
@@ -658,7 +660,7 @@ const Bereshit={num:1,hebrew:"בְּרֵאשִׁית",book:1,haft:{k:"Isaiah",b:
658
660
  * @property {LeyningNames} name
659
661
  * @property {string[]} [parsha] - An array of either 1 (regular) or 2 (doubled parsha).
660
662
  * `undefined` for holiday readings
661
- * @property {number} [parshaNum] - 1 for Bereshit, 2 for Noach, etc. `undefined` for holiday readings
663
+ * @property {number|number[]} [parshaNum] - 1 for Bereshit, 2 for Noach, etc. `undefined` for holiday readings
662
664
  * @property {string} summary - Such as `Genesis 1:1 - 6:8`
663
665
  * @property {Aliyah|Aliyah[]} haft - Haftarah object(s)
664
666
  * @property {string} haftara - Haftarah, such as `Isaiah 42:5 – 43:11`
@@ -692,6 +694,19 @@ function getHaftaraKey(parsha) {
692
694
  }
693
695
  }
694
696
 
697
+ /**
698
+ * Transliterated English and Hebrew names of this parsha
699
+ * @param {string|string[]} parsha untranslated name like 'Pinchas' or ['Pinchas'] or ['Matot','Masei']
700
+ * @return {LeyningNames}
701
+ */
702
+ function makeLeyningNames(parsha) {
703
+ const name = parshaToString(parsha);
704
+ return {
705
+ en: name,
706
+ he: parsha.map(s => core.Locale.lookupTranslation(s, 'he')).join('־')
707
+ };
708
+ }
709
+
695
710
  /**
696
711
  * Looks up regular leyning for a weekly parsha with no special readings
697
712
  * @private
@@ -702,26 +717,22 @@ function getLeyningForParshaShabbatOnly(parsha) {
702
717
  const raw = lookupParsha(parsha);
703
718
  const fullkriyah = {};
704
719
  const book = BOOK[raw.book];
705
- Object.keys(raw.fullkriyah).forEach(num => {
706
- const src = raw.fullkriyah[num];
707
- const reading = {
720
+ for (const [num, src] of Object.entries(raw.fullkriyah)) {
721
+ const aliyah = {
708
722
  k: book,
709
723
  b: src[0],
710
724
  e: src[1]
711
725
  };
712
- fullkriyah[num] = reading;
713
- });
714
- Object.values(fullkriyah).map(aliyah => calculateNumVerses(aliyah));
726
+ calculateNumVerses(aliyah);
727
+ fullkriyah[num] = aliyah;
728
+ }
715
729
  const name = parshaToString(parsha);
716
730
  const parshaNameArray = raw.combined ? [raw.p1, raw.p2] : [name];
717
731
  const parts = makeLeyningParts(fullkriyah);
718
732
  const summary = makeSummaryFromParts(parts);
719
733
  /** @type {Leyning} */
720
734
  const result = {
721
- name: {
722
- en: name,
723
- he: parshaNameArray.map(s => core.Locale.lookupTranslation(s, 'he')).join('־')
724
- },
735
+ name: makeLeyningNames(parshaNameArray),
725
736
  parsha: parshaNameArray,
726
737
  parshaNum: raw.num,
727
738
  summary,
@@ -824,18 +835,20 @@ function getLeyningForParshaHaShavua(ev) {
824
835
  const reasons = Object.keys(reason);
825
836
  if (reasons.length !== 0) {
826
837
  result.reason = reason;
827
- reasons.forEach(num => {
838
+ for (const num of reasons) {
828
839
  if (num === 'haftara' || num === 'sephardic') {
829
840
  const haftObj = result[num === 'haftara' ? 'haft' : 'seph'];
830
841
  const hafts = Array.isArray(haftObj) ? haftObj : [haftObj];
831
- hafts.forEach(haft => haft.reason = reason[num]);
842
+ for (const haft of hafts) {
843
+ haft.reason = reason[num];
844
+ }
832
845
  } else {
833
846
  const aliyah = result.fullkriyah[num];
834
847
  if (typeof aliyah === 'object') {
835
848
  aliyah.reason = reason[num];
836
849
  }
837
850
  }
838
- });
851
+ }
839
852
  }
840
853
  return result;
841
854
  }
@@ -927,48 +940,44 @@ function findParshaHaShavua(saturday, il) {
927
940
  function getLeyningOnDate(hdate, il) {
928
941
  let wantarray = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
929
942
  const dow = hdate.getDay();
930
- const hyear = hdate.getFullYear();
931
- const sedra = core.HebrewCalendar.getSedra(hyear, il);
932
- const parsha = sedra.lookup(hdate);
933
- if (dow === 6 && !parsha.chag) {
934
- const parshaEvent = new core.ParshaEvent(hdate, parsha.parsha, il);
935
- const reading = getLeyningForParshaHaShavua(parshaEvent, il);
936
- return wantarray ? [reading] : reading;
943
+ if (dow === 6) {
944
+ const hyear = hdate.getFullYear();
945
+ const sedra = core.HebrewCalendar.getSedra(hyear, il);
946
+ const parsha = sedra.lookup(hdate);
947
+ if (!parsha.chag) {
948
+ const parshaEvent = new core.ParshaEvent(hdate, parsha.parsha, il);
949
+ const reading = getLeyningForParshaHaShavua(parshaEvent, il);
950
+ return wantarray ? [reading] : reading;
951
+ }
937
952
  }
938
953
  const events = core.HebrewCalendar.getHolidaysOnDate(hdate, il) || [];
939
954
  const arr = [];
940
- for (let i = 0; i < events.length; i++) {
941
- const ev = events[i];
955
+ let hasFullKriyah = false;
956
+ for (const ev of events) {
942
957
  const reading = getLeyningForHoliday(ev, il);
943
958
  if (reading) {
944
- if (wantarray) {
945
- arr.push(reading);
946
- const mincha = getMincha(ev, il);
947
- if (mincha) {
948
- arr.push(mincha);
949
- }
950
- } else {
951
- return reading;
959
+ arr.push(reading);
960
+ if (reading.fullkriyah) {
961
+ hasFullKriyah = true;
962
+ }
963
+ const mincha = getMincha(ev, il);
964
+ if (mincha) {
965
+ arr.push(mincha);
952
966
  }
953
967
  }
954
968
  }
955
- if (wantarray && arr.length !== 0) {
956
- return arr;
957
- }
958
- if (dow === 1 || dow === 4) {
969
+ if (!hasFullKriyah && (dow === 1 || dow === 4)) {
959
970
  const saturday = hdate.onOrAfter(6);
960
- const parsha2 = findParshaHaShavua(saturday);
961
- const reading = getLeyningForParsha(parsha2.parsha);
962
- const result = {
963
- name: reading.name,
964
- parsha: reading.parsha,
965
- parshaNum: reading.parshaNum,
966
- weekday: reading.weekday
971
+ const parsha = findParshaHaShavua(saturday);
972
+ const reading = {
973
+ name: makeLeyningNames(parsha.parsha),
974
+ parsha: parsha.parsha,
975
+ parshaNum: parsha.num,
976
+ weekday: getWeekdayReading(parsha.parsha)
967
977
  };
968
- return wantarray ? [result] : result;
978
+ arr.unshift(reading);
969
979
  }
970
- // no reading today: it's not Shabbat, Mon/Thu, or a Torah-reading holiday
971
- return wantarray ? [] : undefined;
980
+ return wantarray ? arr : arr[0];
972
981
  }
973
982
  const minchaSuffix = ' (Mincha)';
974
983
 
@@ -1040,11 +1049,11 @@ function writeFullKriyahCsv(stream, hyear, il) {
1040
1049
  const events = events0.filter(ev => ev.getDesc() !== 'Rosh Chodesh Tevet');
1041
1050
  const parshaDates = getParshaDates(events);
1042
1051
  stream.write('"Date","Parashah","Aliyah","Reading","Verses"\r\n');
1043
- events.forEach(ev => {
1052
+ for (const ev of events) {
1044
1053
  if (ev.getFlags() === core.flags.PARSHA_HASHAVUA || !parshaDates[ev.getDate().toString()]) {
1045
1054
  writeFullKriyahEvent(stream, ev, il);
1046
1055
  }
1047
- });
1056
+ }
1048
1057
  }
1049
1058
 
1050
1059
  /**
@@ -1113,13 +1122,13 @@ function writeCsvLines(stream, ev, reading, il, isParsha) {
1113
1122
  const parsha = isParsha ? ev.basename() : getLeyningKeyForEvent(ev, il) || ev.render();
1114
1123
  const date = fmtDate(ev.getDate().greg());
1115
1124
  const lines = getFullKriyahLines(reading);
1116
- lines.forEach(s => {
1125
+ for (const s of lines) {
1117
1126
  const code = s[0].charCodeAt(0);
1118
1127
  if (code < 48 || code > 57) {
1119
1128
  s[0] = `"${s[0]}"`;
1120
1129
  }
1121
1130
  stream.write(`${date},"${parsha}",${s[0]},"${s[1]}",${s[2]}\r\n`);
1122
- });
1131
+ }
1123
1132
  stream.write('\r\n');
1124
1133
  }
1125
1134
 
@@ -1131,8 +1140,7 @@ function writeCsvLines(stream, ev, reading, il, isParsha) {
1131
1140
  function getFullKriyahLines(reading) {
1132
1141
  const lines = [];
1133
1142
  if (reading.fullkriyah) {
1134
- Object.keys(reading.fullkriyah).forEach(num => {
1135
- const a = reading.fullkriyah[num];
1143
+ for (const [num, a] of Object.entries(reading.fullkriyah)) {
1136
1144
  if (typeof a !== 'undefined') {
1137
1145
  var _reading$reason;
1138
1146
  const k = num == 'M' ? 'maf' : num;
@@ -1142,7 +1150,7 @@ function getFullKriyahLines(reading) {
1142
1150
  }
1143
1151
  lines.push([k, aliyah, a.v || '']);
1144
1152
  }
1145
- });
1153
+ }
1146
1154
  }
1147
1155
  let specialHaftara = false;
1148
1156
  if (reading.haftara) {
@@ -1163,13 +1171,12 @@ function getFullKriyahLines(reading) {
1163
1171
  lines.push(['Alternate Haftara', haftara, reading.triHaftaraNumV || '']);
1164
1172
  }
1165
1173
  if (reading.megillah) {
1166
- Object.keys(reading.megillah).forEach(num => {
1167
- const a = reading.megillah[num];
1174
+ for (const [num, a] of Object.entries(reading.megillah)) {
1168
1175
  if (typeof a !== 'undefined') {
1169
1176
  const aliyah = formatAliyahWithBook(a);
1170
1177
  lines.push([`Megillah Ch. ${num}`, aliyah, a.v || '']);
1171
1178
  }
1172
- });
1179
+ }
1173
1180
  }
1174
1181
  return lines;
1175
1182
  }
@@ -1191,6 +1198,7 @@ exports.getWeekdayReading = getWeekdayReading;
1191
1198
  exports.hasFestival = hasFestival;
1192
1199
  exports.lookupFestival = lookupFestival;
1193
1200
  exports.lookupParsha = lookupParsha;
1201
+ exports.makeLeyningNames = makeLeyningNames;
1194
1202
  exports.makeLeyningParts = makeLeyningParts;
1195
1203
  exports.makeLeyningSummary = makeLeyningSummary;
1196
1204
  exports.makeSummaryFromParts = makeSummaryFromParts;