@hebcal/core 4.5.1 → 5.0.0-rc2

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.
@@ -1,444 +0,0 @@
1
- /*! @hebcal/core v4.5.1 */
2
- var hebcal = (function (exports) {
3
- 'use strict';
4
-
5
- function _typeof(o) {
6
- "@babel/helpers - typeof";
7
-
8
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
9
- return typeof o;
10
- } : function (o) {
11
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
12
- }, _typeof(o);
13
- }
14
-
15
- /*
16
- * More minimal greg routines
17
- */
18
-
19
- /** @private */
20
- var lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
21
- /** @private */
22
- var monthLengths = [lengths, lengths.slice()];
23
- monthLengths[1][2] = 29;
24
-
25
- /**
26
- * @private
27
- * @param {number} x
28
- * @param {number} y
29
- * @return {number}
30
- */
31
- function mod(x, y) {
32
- return x - y * Math.floor(x / y);
33
- }
34
-
35
- /**
36
- * @private
37
- * @param {number} x
38
- * @param {number} y
39
- * @return {number}
40
- */
41
- function quotient(x, y) {
42
- return Math.floor(x / y);
43
- }
44
-
45
- /**
46
- * Returns true if the Gregorian year is a leap year
47
- * @private
48
- * @param {number} year Gregorian year
49
- * @return {boolean}
50
- */
51
- function isLeapYear$1(year) {
52
- return !(year % 4) && (!!(year % 100) || !(year % 400));
53
- }
54
-
55
- /**
56
- * Returns true if the object is a Javascript Date
57
- * @private
58
- * @param {Object} obj
59
- * @return {boolean}
60
- */
61
- function isDate(obj) {
62
- return _typeof(obj) === 'object' && Date.prototype === obj.__proto__;
63
- }
64
-
65
- /*
66
- const ABS_14SEP1752 = 639797;
67
- const ABS_2SEP1752 = 639785;
68
- */
69
-
70
- /**
71
- * Converts Gregorian date to absolute R.D. (Rata Die) days
72
- * @private
73
- * @param {Date} date Gregorian date
74
- * @return {number}
75
- */
76
- function greg2abs(date) {
77
- if (!isDate(date)) {
78
- throw new TypeError("Argument not a Date: ".concat(date));
79
- }
80
- var abs = toFixed(date.getFullYear(), date.getMonth() + 1, date.getDate());
81
- /*
82
- if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
83
- throw new RangeError(`Invalid Date: ${date}`);
84
- }
85
- */
86
- return abs;
87
- }
88
-
89
- /**
90
- * @private
91
- * @param {number} abs - R.D. number of days
92
- * @return {number}
93
- */
94
- function yearFromFixed(abs) {
95
- var l0 = abs - 1;
96
- var n400 = quotient(l0, 146097);
97
- var d1 = mod(l0, 146097);
98
- var n100 = quotient(d1, 36524);
99
- var d2 = mod(d1, 36524);
100
- var n4 = quotient(d2, 1461);
101
- var d3 = mod(d2, 1461);
102
- var n1 = quotient(d3, 365);
103
- var year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
104
- return n100 != 4 && n1 != 4 ? year + 1 : year;
105
- }
106
-
107
- /**
108
- * @private
109
- * @param {number} year
110
- * @param {number} month (1-12)
111
- * @param {number} day (1-31)
112
- * @return {number}
113
- */
114
- function toFixed(year, month, day) {
115
- var py = year - 1;
116
- return 365 * py + quotient(py, 4) - quotient(py, 100) + quotient(py, 400) + quotient(367 * month - 362, 12) + (month <= 2 ? 0 : isLeapYear$1(year) ? -1 : -2) + day;
117
- }
118
-
119
- /**
120
- * Converts from Rata Die (R.D. number) to Gregorian date.
121
- * See the footnote on page 384 of ``Calendrical Calculations, Part II:
122
- * Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M.
123
- * Clamen, Software--Practice and Experience, Volume 23, Number 4
124
- * (April, 1993), pages 383-404 for an explanation.
125
- * @private
126
- * @param {number} abs - R.D. number of days
127
- * @return {Date}
128
- */
129
- function abs2greg(abs) {
130
- if (typeof abs !== 'number') {
131
- throw new TypeError("Argument not a Number: ".concat(abs));
132
- }
133
- abs = Math.trunc(abs);
134
- /*
135
- if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
136
- throw new RangeError(`Invalid Date: ${abs}`);
137
- }
138
- */
139
- var year = yearFromFixed(abs);
140
- var priorDays = abs - toFixed(year, 1, 1);
141
- var correction = abs < toFixed(year, 3, 1) ? 0 : isLeapYear$1(year) ? 1 : 2;
142
- var month = quotient(12 * (priorDays + correction) + 373, 367);
143
- var day = abs - toFixed(year, month, 1) + 1;
144
- var dt = new Date(year, month - 1, day);
145
- if (year < 100 && year >= 0) {
146
- dt.setFullYear(year);
147
- }
148
- return dt;
149
- }
150
-
151
- /*
152
- * More minimal HDate
153
- */
154
-
155
- var NISAN = 1;
156
- var IYYAR = 2;
157
- // const SIVAN = 3;
158
- var TAMUZ = 4;
159
- // const AV = 5;
160
- var ELUL = 6;
161
- var TISHREI = 7;
162
- var CHESHVAN = 8;
163
- var KISLEV = 9;
164
- var TEVET = 10;
165
- // const SHVAT = 11;
166
- var ADAR_I = 12;
167
- var ADAR_II = 13;
168
-
169
- /**
170
- * Hebrew months of the year (NISAN=1, TISHREI=7)
171
- * @readonly
172
- * @enum {number}
173
- */
174
- var months = {
175
- /** Nissan / ניסן */
176
- NISAN: 1,
177
- /** Iyyar / אייר */
178
- IYYAR: 2,
179
- /** Sivan / סיון */
180
- SIVAN: 3,
181
- /** Tamuz (sometimes Tammuz) / תמוז */
182
- TAMUZ: 4,
183
- /** Av / אב */
184
- AV: 5,
185
- /** Elul / אלול */
186
- ELUL: 6,
187
- /** Tishrei / תִּשְׁרֵי */
188
- TISHREI: 7,
189
- /** Cheshvan / חשון */
190
- CHESHVAN: 8,
191
- /** Kislev / כסלו */
192
- KISLEV: 9,
193
- /** Tevet / טבת */
194
- TEVET: 10,
195
- /** Sh'vat / שבט */
196
- SHVAT: 11,
197
- /** Adar or Adar Rishon / אדר */
198
- ADAR_I: 12,
199
- /** Adar Sheini (only on leap years) / אדר ב׳ */
200
- ADAR_II: 13
201
- };
202
- var monthNames0 = ['', 'Nisan', 'Iyyar', 'Sivan', 'Tamuz', 'Av', 'Elul', 'Tishrei', 'Cheshvan', 'Kislev', 'Tevet', 'Sh\'vat'];
203
-
204
- /**
205
- * Transliterations of Hebrew month names.
206
- * Regular years are index 0 and leap years are index 1.
207
- * @private
208
- */
209
- var monthNames = [monthNames0.concat(['Adar', 'Nisan']), monthNames0.concat(['Adar I', 'Adar II', 'Nisan'])];
210
- var edCache = Object.create(null);
211
- var EPOCH = -1373428;
212
- // Avg year length in the cycle (19 solar years with 235 lunar months)
213
- var AVG_HEBYEAR_DAYS = 365.24682220597794;
214
-
215
- /**
216
- * @private
217
- * @param {any} n
218
- * @param {string} name
219
- */
220
- function assertNumber(n, name) {
221
- if (typeof n !== 'number' || isNaN(n)) {
222
- throw new TypeError("invalid parameter '".concat(name, "' not a number: ").concat(n));
223
- }
224
- }
225
-
226
- /**
227
- * Converts Hebrew date to R.D. (Rata Die) fixed days.
228
- * R.D. 1 is the imaginary date Monday, January 1, 1 on the Gregorian
229
- * Calendar.
230
- * @private
231
- * @param {number} year Hebrew year
232
- * @param {number} month Hebrew month
233
- * @param {number} day Hebrew date (1-30)
234
- * @return {number}
235
- */
236
- function hebrew2abs(year, month, day) {
237
- assertNumber(year, 'year');
238
- assertNumber(month, 'month');
239
- assertNumber(day, 'day');
240
- if (year < 1) {
241
- throw new RangeError("hebrew2abs: invalid year ".concat(year));
242
- }
243
- var tempabs = day;
244
- if (month < TISHREI) {
245
- for (var m = TISHREI; m <= monthsInYear(year); m++) {
246
- tempabs += daysInMonth(m, year);
247
- }
248
- for (var _m = NISAN; _m < month; _m++) {
249
- tempabs += daysInMonth(_m, year);
250
- }
251
- } else {
252
- for (var _m2 = TISHREI; _m2 < month; _m2++) {
253
- tempabs += daysInMonth(_m2, year);
254
- }
255
- }
256
- return EPOCH + elapsedDays(year) + tempabs - 1;
257
- }
258
-
259
- /**
260
- * @private
261
- * @param {number} year
262
- * @return {number}
263
- */
264
- function newYear(year) {
265
- return EPOCH + elapsedDays(year);
266
- }
267
-
268
- /**
269
- * Converts absolute R.D. days to Hebrew date
270
- * @private
271
- * @param {number} abs absolute R.D. days
272
- * @return {SimpleHebrewDate}
273
- */
274
- function abs2hebrew(abs) {
275
- assertNumber(abs, 'abs');
276
- abs = Math.trunc(abs);
277
- if (abs <= EPOCH) {
278
- throw new RangeError("abs2hebrew: ".concat(abs, " is before epoch"));
279
- }
280
- // first, quickly approximate year
281
- var year = Math.floor((abs - EPOCH) / AVG_HEBYEAR_DAYS);
282
- while (newYear(year) <= abs) {
283
- ++year;
284
- }
285
- --year;
286
- var month = abs < hebrew2abs(year, 1, 1) ? 7 : 1;
287
- while (abs > hebrew2abs(year, month, daysInMonth(month, year))) {
288
- ++month;
289
- }
290
- var day = 1 + abs - hebrew2abs(year, month, 1);
291
- return {
292
- yy: year,
293
- mm: month,
294
- dd: day
295
- };
296
- }
297
-
298
- /**
299
- * Returns true if Hebrew year is a leap year
300
- * @private
301
- * @param {number} year Hebrew year
302
- * @return {boolean}
303
- */
304
- function isLeapYear(year) {
305
- return (1 + year * 7) % 19 < 7;
306
- }
307
-
308
- /**
309
- * Number of months in this Hebrew year (either 12 or 13 depending on leap year)
310
- * @private
311
- * @param {number} year Hebrew year
312
- * @return {number}
313
- */
314
- function monthsInYear(year) {
315
- return 12 + isLeapYear(year); // boolean is cast to 1 or 0
316
- }
317
-
318
- /**
319
- * Number of days in Hebrew month in a given year (29 or 30)
320
- * @private
321
- * @param {number} month Hebrew month (e.g. months.TISHREI)
322
- * @param {number} year Hebrew year
323
- * @return {number}
324
- */
325
- function daysInMonth(month, year) {
326
- switch (month) {
327
- case IYYAR:
328
- case TAMUZ:
329
- case ELUL:
330
- case TEVET:
331
- case ADAR_II:
332
- return 29;
333
- }
334
- if (month === ADAR_I && !isLeapYear(year) || month === CHESHVAN && !longCheshvan(year) || month === KISLEV && shortKislev(year)) {
335
- return 29;
336
- } else {
337
- return 30;
338
- }
339
- }
340
-
341
- /**
342
- * Returns a transliterated string name of Hebrew month in year,
343
- * for example 'Elul' or 'Cheshvan'.
344
- * @private
345
- * @param {number} month Hebrew month (e.g. months.TISHREI)
346
- * @param {number} year Hebrew year
347
- * @return {string}
348
- */
349
- function getMonthName(month, year) {
350
- assertNumber(month, 'month');
351
- assertNumber(year, 'year');
352
- if (month < 1 || month > 14) {
353
- throw new TypeError("bad month argument ".concat(month));
354
- }
355
- return monthNames[+isLeapYear(year)][month];
356
- }
357
-
358
- /**
359
- * Days from sunday prior to start of Hebrew calendar to mean
360
- * conjunction of Tishrei in Hebrew YEAR
361
- * @private
362
- * @param {number} year Hebrew year
363
- * @return {number}
364
- */
365
- function elapsedDays(year) {
366
- var elapsed = edCache[year] = edCache[year] || elapsedDays0(year);
367
- return elapsed;
368
- }
369
-
370
- /**
371
- * Days from sunday prior to start of Hebrew calendar to mean
372
- * conjunction of Tishrei in Hebrew YEAR
373
- * @private
374
- * @param {number} year Hebrew year
375
- * @return {number}
376
- */
377
- function elapsedDays0(year) {
378
- var prevYear = year - 1;
379
- var mElapsed = 235 * Math.floor(prevYear / 19) +
380
- // Months in complete 19 year lunar (Metonic) cycles so far
381
- 12 * (prevYear % 19) +
382
- // Regular months in this cycle
383
- Math.floor((prevYear % 19 * 7 + 1) / 19); // Leap months this cycle
384
-
385
- var pElapsed = 204 + 793 * (mElapsed % 1080);
386
- var hElapsed = 5 + 12 * mElapsed + 793 * Math.floor(mElapsed / 1080) + Math.floor(pElapsed / 1080);
387
- var parts = pElapsed % 1080 + 1080 * (hElapsed % 24);
388
- var day = 1 + 29 * mElapsed + Math.floor(hElapsed / 24);
389
- var altDay = day + (parts >= 19440 || 2 === day % 7 && parts >= 9924 && !isLeapYear(year) || 1 === day % 7 && parts >= 16789 && isLeapYear(prevYear));
390
- return altDay + (altDay % 7 === 0 || altDay % 7 === 3 || altDay % 7 === 5);
391
- }
392
-
393
- /**
394
- * Number of days in the hebrew YEAR.
395
- * A common Hebrew calendar year can have a length of 353, 354 or 355 days
396
- * A leap Hebrew calendar year can have a length of 383, 384 or 385 days
397
- * @private
398
- * @param {number} year Hebrew year
399
- * @return {number}
400
- */
401
- function daysInYear(year) {
402
- return elapsedDays(year + 1) - elapsedDays(year);
403
- }
404
-
405
- /**
406
- * true if Cheshvan is long in Hebrew year
407
- * @private
408
- * @param {number} year Hebrew year
409
- * @return {boolean}
410
- */
411
- function longCheshvan(year) {
412
- return daysInYear(year) % 10 === 5;
413
- }
414
-
415
- /**
416
- * true if Kislev is short in Hebrew year
417
- * @private
418
- * @param {number} year Hebrew year
419
- * @return {boolean}
420
- */
421
- function shortKislev(year) {
422
- return daysInYear(year) % 10 === 3;
423
- }
424
-
425
- var hdate = {
426
- abs2hebrew: abs2hebrew,
427
- daysInMonth: daysInMonth,
428
- daysInYear: daysInYear,
429
- getMonthName: getMonthName,
430
- hebrew2abs: hebrew2abs,
431
- isLeapYear: isLeapYear,
432
- longCheshvan: longCheshvan,
433
- months: months,
434
- monthsInYear: monthsInYear,
435
- shortKislev: shortKislev
436
- };
437
-
438
- exports.abs2greg = abs2greg;
439
- exports.greg2abs = greg2abs;
440
- exports.hdate = hdate;
441
-
442
- return exports;
443
-
444
- })({});
@@ -1,2 +0,0 @@
1
- /*! @hebcal/core v4.5.1 */
2
- var hebcal=function(r){"use strict";function n(r){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},n(r)}var t=[0,31,28,31,30,31,30,31,31,30,31,30,31];function e(r,n){return r-n*Math.floor(r/n)}function o(r,n){return Math.floor(r/n)}function a(r){return!(r%4||!(r%100)&&r%400)}function u(r,n,t){var e=r-1;return 365*e+o(e,4)-o(e,100)+o(e,400)+o(367*n-362,12)+(n<=2?0:a(r)?-1:-2)+t}[t,t.slice()][1][2]=29;var c=1,f=2,i=4,h=6,s=7,l=8,y=9,b=10,v=12,m=13,p=["","Nisan","Iyyar","Sivan","Tamuz","Av","Elul","Tishrei","Cheshvan","Kislev","Tevet","Sh'vat"],w=[p.concat(["Adar","Nisan"]),p.concat(["Adar I","Adar II","Nisan"])],A=Object.create(null),I=-1373428;function g(r,n){if("number"!=typeof r||isNaN(r))throw new TypeError("invalid parameter '".concat(n,"' not a number: ").concat(r))}function M(r,n,t){if(g(r,"year"),g(n,"month"),g(t,"day"),r<1)throw new RangeError("hebrew2abs: invalid year ".concat(r));var e=t;if(n<s){for(var o=s;o<=d(r);o++)e+=T(o,r);for(var a=c;a<n;a++)e+=T(a,r)}else for(var u=s;u<n;u++)e+=T(u,r);return I+N(r)+e-1}function E(r){return I+N(r)}function S(r){return(1+7*r)%19<7}function d(r){return 12+S(r)}function T(r,n){switch(r){case f:case i:case h:case b:case m:return 29}return r===v&&!S(n)||r===l&&!D(n)||r===y&&R(n)?29:30}function N(r){var n=A[r]=A[r]||function(r){var n=r-1,t=235*Math.floor(n/19)+n%19*12+Math.floor((n%19*7+1)/19),e=204+t%1080*793,o=5+12*t+793*Math.floor(t/1080)+Math.floor(e/1080),a=e%1080+o%24*1080,u=1+29*t+Math.floor(o/24),c=u+(a>=19440||2==u%7&&a>=9924&&!S(r)||1==u%7&&a>=16789&&S(n));return c+(c%7==0||c%7==3||c%7==5)}(r);return n}function Y(r){return N(r+1)-N(r)}function D(r){return Y(r)%10==5}function R(r){return Y(r)%10==3}var V={abs2hebrew:function(r){if(g(r,"abs"),(r=Math.trunc(r))<=I)throw new RangeError("abs2hebrew: ".concat(r," is before epoch"));for(var n=Math.floor((r-I)/365.24682220597794);E(n)<=r;)++n;for(var t=r<M(--n,1,1)?7:1;r>M(n,t,T(t,n));)++t;return{yy:n,mm:t,dd:1+r-M(n,t,1)}},daysInMonth:T,daysInYear:Y,getMonthName:function(r,n){if(g(r,"month"),g(n,"year"),r<1||r>14)throw new TypeError("bad month argument ".concat(r));return w[+S(n)][r]},hebrew2abs:M,isLeapYear:S,longCheshvan:D,months:{NISAN:1,IYYAR:2,SIVAN:3,TAMUZ:4,AV:5,ELUL:6,TISHREI:7,CHESHVAN:8,KISLEV:9,TEVET:10,SHVAT:11,ADAR_I:12,ADAR_II:13},monthsInYear:d,shortKislev:R};return r.abs2greg=function(r){if("number"!=typeof r)throw new TypeError("Argument not a Number: ".concat(r));var n=function(r){var n=r-1,t=o(n,146097),a=e(n,146097),u=o(a,36524),c=e(a,36524),f=o(c,1461),i=o(e(c,1461),365),h=400*t+100*u+4*f+i;return 4!=u&&4!=i?h+1:h}(r=Math.trunc(r)),t=o(12*(r-u(n,1,1)+(r<u(n,3,1)?0:a(n)?1:2))+373,367),c=r-u(n,t,1)+1,f=new Date(n,t-1,c);return n<100&&n>=0&&f.setFullYear(n),f},r.greg2abs=function(r){if("object"!==n(t=r)||Date.prototype!==t.__proto__)throw new TypeError("Argument not a Date: ".concat(r));var t;return u(r.getFullYear(),r.getMonth()+1,r.getDate())},r.hdate=V,r}({});